@raydium-io/raydium-sdk-v2 0.0.48-alpha → 0.0.49-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/farm/farm.js +1 -1
- package/lib/raydium/farm/farm.js.map +1 -1
- package/lib/raydium/farm/farm.mjs +1 -1
- package/lib/raydium/farm/farm.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/farm/farm.ts +14 -3
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var Nn=Object.defineProperty,En=Object.defineProperties;var Mn=Object.getOwnPropertyDescriptors;var ot=Object.getOwnPropertySymbols;var kr=Object.prototype.hasOwnProperty,Ar=Object.prototype.propertyIsEnumerable;var Tr=(e,t,r)=>t in e?Nn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,G=(e,t)=>{for(var r in t||(t={}))kr.call(t,r)&&Tr(e,r,t[r]);if(ot)for(var r of ot(t))Ar.call(t,r)&&Tr(e,r,t[r]);return e},ee=(e,t)=>En(e,Mn(t));var it=(e,t)=>{var r={};for(var n in e)kr.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&ot)for(var n of ot(e))t.indexOf(n)<0&&Ar.call(e,n)&&(r[n]=e[n]);return r};import{createAssociatedTokenAccountInstruction as Qi}from"@solana/spl-token";import{PublicKey as j,SystemProgram as $i}from"@solana/web3.js";import{get as Ir,set as vn}from"lodash";import Lr from"dayjs";import _n from"dayjs/plugin/utc";Lr.extend(_n);var Kt=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 Lr().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 r=t.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(r)}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}},Sr={},Dn={};function Q(e){let t=Ir(Sr,e);if(!t){let r=Ir(Dn,e);t=new Kt({name:e,logLevel:r}),vn(Sr,e,t)}return t}import{PublicKey as Jo}from"@solana/web3.js";import Qo from"bn.js";import zo from"big.js";import yt from"bn.js";import ue from"bn.js";var Ee=9e15,Ie=1e9,Ct="0123456789abcdef",at="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ut="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Vt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ee,maxE:Ee,crypto:!1},Cr,ye,B=!0,lt="[DecimalError] ",Ae=lt+"Invalid argument: ",Vr=lt+"Precision limit exceeded",Fr=lt+"crypto unavailable",Nr="[object Decimal]",ie=Math.floor,te=Math.pow,On=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Wn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Un=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Er=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,de=1e7,S=7,qn=9007199254740991,Gn=at.length-1,Ft=ut.length-1,b={toStringTag:Nr};b.absoluteValue=b.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),A(e)};b.ceil=function(){return A(new this.constructor(this),this.e+1,2)};b.clampedTo=b.clamp=function(e,t){var r,n=this,o=n.constructor;if(e=new o(e),t=new o(t),!e.s||!t.s)return new o(NaN);if(e.gt(t))throw Error(Ae+t);return r=n.cmp(e),r<0?e:n.cmp(t)>0?t:new o(n)};b.comparedTo=b.cmp=function(e){var t,r,n,o,i=this,s=i.d,a=(e=new i.constructor(e)).d,c=i.s,u=e.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(i.e!==e.e)return i.e>e.e^c<0?1:-1;for(n=s.length,o=a.length,t=0,r=n<o?n:o;t<r;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return n===o?0:n>o^c<0?1:-1};b.cosine=b.cos=function(){var e,t,r=this,n=r.constructor;return r.d?r.d[0]?(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+S,n.rounding=1,r=Hn(n,Or(n,r)),n.precision=e,n.rounding=t,A(ye==2||ye==3?r.neg():r,e,t,!0)):new n(1):new n(NaN)};b.cubeRoot=b.cbrt=function(){var e,t,r,n,o,i,s,a,c,u,d=this,l=d.constructor;if(!d.isFinite()||d.isZero())return new l(d);for(B=!1,i=d.s*te(d.s*d,1/3),!i||Math.abs(i)==1/0?(r=oe(d.d),e=d.e,(i=(e-r.length+1)%3)&&(r+=i==1||i==-2?"0":"00"),i=te(r,1/3),e=ie((e+1)/3)-(e%3==(e<0?-1:2)),i==1/0?r="5e"+e:(r=i.toExponential(),r=r.slice(0,r.indexOf("e")+1)+e),n=new l(r),n.s=d.s):n=new l(i.toString()),s=(e=l.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(d),n=q(u.plus(d).times(a),u.plus(c),s+2,1),oe(a.d).slice(0,s)===(r=oe(n.d)).slice(0,s))if(r=r.slice(s-3,s+1),r=="9999"||!o&&r=="4999"){if(!o&&(A(a,e+1,0),a.times(a).times(a).eq(d))){n=a;break}s+=4,o=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(A(n,e+1,1),t=!n.times(n).times(n).eq(d));break}return B=!0,A(n,e,l.rounding,t)};b.decimalPlaces=b.dp=function(){var e,t=this.d,r=NaN;if(t){if(e=t.length-1,r=(e-ie(this.e/S))*S,e=t[e],e)for(;e%10==0;e/=10)r--;r<0&&(r=0)}return r};b.dividedBy=b.div=function(e){return q(this,new this.constructor(e))};b.dividedToIntegerBy=b.divToInt=function(e){var t=this,r=t.constructor;return A(q(t,new r(e),0,1,1),r.precision,r.rounding)};b.equals=b.eq=function(e){return this.cmp(e)===0};b.floor=function(){return A(new this.constructor(this),this.e+1,3)};b.greaterThan=b.gt=function(e){return this.cmp(e)>0};b.greaterThanOrEqualTo=b.gte=function(e){var t=this.cmp(e);return t==1||t===0};b.hyperbolicCosine=b.cosh=function(){var e,t,r,n,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;r=s.precision,n=s.rounding,s.precision=r+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(e=Math.ceil(o/3),t=(1/ft(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=Me(s,1,i.times(t),new s(1),!0);for(var c,u=e,d=new s(8);u--;)c=i.times(i),i=a.minus(c.times(d.minus(c.times(d))));return A(i,s.precision=r,s.rounding=n,!0)};b.hyperbolicSine=b.sinh=function(){var e,t,r,n,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(t=i.precision,r=i.rounding,i.precision=t+Math.max(o.e,o.sd())+4,i.rounding=1,n=o.d.length,n<3)o=Me(i,2,o,o,!0);else{e=1.4*Math.sqrt(n),e=e>16?16:e|0,o=o.times(1/ft(5,e)),o=Me(i,2,o,o,!0);for(var s,a=new i(5),c=new i(16),u=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(c.times(s).plus(u))))}return i.precision=t,i.rounding=r,A(o,t,r,!0)};b.hyperbolicTangent=b.tanh=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+7,n.rounding=1,q(r.sinh(),r.cosh(),n.precision=e,n.rounding=t)):new n(r.s)};b.inverseCosine=b.acos=function(){var e,t=this,r=t.constructor,n=t.abs().cmp(1),o=r.precision,i=r.rounding;return n!==-1?n===0?t.isNeg()?le(r,o,i):new r(0):new r(NaN):t.isZero()?le(r,o+4,i).times(.5):(r.precision=o+6,r.rounding=1,t=t.asin(),e=le(r,o+4,i).times(.5),r.precision=o,r.rounding=i,e.minus(t))};b.inverseHyperbolicCosine=b.acosh=function(){var e,t,r=this,n=r.constructor;return r.lte(1)?new n(r.eq(1)?0:NaN):r.isFinite()?(e=n.precision,t=n.rounding,n.precision=e+Math.max(Math.abs(r.e),r.sd())+4,n.rounding=1,B=!1,r=r.times(r).minus(1).sqrt().plus(r),B=!0,n.precision=e,n.rounding=t,r.ln()):new n(r)};b.inverseHyperbolicSine=b.asinh=function(){var e,t,r=this,n=r.constructor;return!r.isFinite()||r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+2*Math.max(Math.abs(r.e),r.sd())+6,n.rounding=1,B=!1,r=r.times(r).plus(1).sqrt().plus(r),B=!0,n.precision=e,n.rounding=t,r.ln())};b.inverseHyperbolicTangent=b.atanh=function(){var e,t,r,n,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,n=o.sd(),Math.max(n,e)<2*-o.e-1?A(new i(o),e,t,!0):(i.precision=r=n-o.e,o=q(o.plus(1),new i(1).minus(o),r+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};b.inverseSine=b.asin=function(){var e,t,r,n,o=this,i=o.constructor;return o.isZero()?new i(o):(t=o.abs().cmp(1),r=i.precision,n=i.rounding,t!==-1?t===0?(e=le(i,r+4,n).times(.5),e.s=o.s,e):new i(NaN):(i.precision=r+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=r,i.rounding=n,o.times(2)))};b.inverseTangent=b.atan=function(){var e,t,r,n,o,i,s,a,c,u=this,d=u.constructor,l=d.precision,f=d.rounding;if(u.isFinite()){if(u.isZero())return new d(u);if(u.abs().eq(1)&&l+4<=Ft)return s=le(d,l+4,f).times(.25),s.s=u.s,s}else{if(!u.s)return new d(NaN);if(l+4<=Ft)return s=le(d,l+4,f).times(.5),s.s=u.s,s}for(d.precision=a=l+10,d.rounding=1,r=Math.min(28,a/S+2|0),e=r;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(B=!1,t=Math.ceil(a/S),n=1,c=u.times(u),s=new d(u),o=u;e!==-1;)if(o=o.times(c),i=s.minus(o.div(n+=2)),o=o.times(c),s=i.plus(o.div(n+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===i.d[e]&&e--;);return r&&(s=s.times(2<<r-1)),B=!0,A(s,d.precision=l,d.rounding=f,!0)};b.isFinite=function(){return!!this.d};b.isInteger=b.isInt=function(){return!!this.d&&ie(this.e/S)>this.d.length-2};b.isNaN=function(){return!this.s};b.isNegative=b.isNeg=function(){return this.s<0};b.isPositive=b.isPos=function(){return this.s>0};b.isZero=function(){return!!this.d&&this.d[0]===0};b.lessThan=b.lt=function(e){return this.cmp(e)<0};b.lessThanOrEqualTo=b.lte=function(e){return this.cmp(e)<1};b.logarithm=b.log=function(e){var t,r,n,o,i,s,a,c,u=this,d=u.constructor,l=d.precision,f=d.rounding,p=5;if(e==null)e=new d(10),t=!0;else{if(e=new d(e),r=e.d,e.s<0||!r||!r[0]||e.eq(1))return new d(NaN);t=e.eq(10)}if(r=u.d,u.s<0||!r||!r[0]||u.eq(1))return new d(r&&!r[0]?-1/0:u.s!=1?NaN:r?0:1/0);if(t)if(r.length>1)i=!0;else{for(o=r[0];o%10===0;)o/=10;i=o!==1}if(B=!1,a=l+p,s=ke(u,a),n=t?ct(d,a+10):ke(e,a),c=q(s,n,a,1),We(c.d,o=l,f))do if(a+=10,s=ke(u,a),n=t?ct(d,a+10):ke(e,a),c=q(s,n,a,1),!i){+oe(c.d).slice(o+1,o+15)+1==1e14&&(c=A(c,l+1,0));break}while(We(c.d,o+=10,f));return B=!0,A(c,l,f)};b.minus=b.sub=function(e){var t,r,n,o,i,s,a,c,u,d,l,f,p=this,h=p.constructor;if(e=new h(e),!p.d||!e.d)return!p.s||!e.s?e=new h(NaN):p.d?e.s=-e.s:e=new h(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(u=p.d,f=e.d,a=h.precision,c=h.rounding,!u[0]||!f[0]){if(f[0])e.s=-e.s;else if(u[0])e=new h(p);else return new h(c===3?-0:0);return B?A(e,a,c):e}if(r=ie(e.e/S),d=ie(p.e/S),u=u.slice(),i=d-r,i){for(l=i<0,l?(t=u,i=-i,s=f.length):(t=f,r=d,s=u.length),n=Math.max(Math.ceil(a/S),s)+2,i>n&&(i=n,t.length=1),t.reverse(),n=i;n--;)t.push(0);t.reverse()}else{for(n=u.length,s=f.length,l=n<s,l&&(s=n),n=0;n<s;n++)if(u[n]!=f[n]){l=u[n]<f[n];break}i=0}for(l&&(t=u,u=f,f=t,e.s=-e.s),s=u.length,n=f.length-s;n>0;--n)u[s++]=0;for(n=f.length;n>i;){if(u[--n]<f[n]){for(o=n;o&&u[--o]===0;)u[o]=de-1;--u[o],u[n]+=de}u[n]-=f[n]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--r;return u[0]?(e.d=u,e.e=dt(u,r),B?A(e,a,c):e):new h(c===3?-0:0)};b.modulo=b.mod=function(e){var t,r=this,n=r.constructor;return e=new n(e),!r.d||!e.s||e.d&&!e.d[0]?new n(NaN):!e.d||r.d&&!r.d[0]?A(new n(r),n.precision,n.rounding):(B=!1,n.modulo==9?(t=q(r,e.abs(),0,3,1),t.s*=e.s):t=q(r,e,0,n.modulo,1),t=t.times(e),B=!0,r.minus(t))};b.naturalExponential=b.exp=function(){return Nt(this)};b.naturalLogarithm=b.ln=function(){return ke(this)};b.negated=b.neg=function(){var e=new this.constructor(this);return e.s=-e.s,A(e)};b.plus=b.add=function(e){var t,r,n,o,i,s,a,c,u,d,l=this,f=l.constructor;if(e=new f(e),!l.d||!e.d)return!l.s||!e.s?e=new f(NaN):l.d||(e=new f(e.d||l.s===e.s?l:NaN)),e;if(l.s!=e.s)return e.s=-e.s,l.minus(e);if(u=l.d,d=e.d,a=f.precision,c=f.rounding,!u[0]||!d[0])return d[0]||(e=new f(l)),B?A(e,a,c):e;if(i=ie(l.e/S),n=ie(e.e/S),u=u.slice(),o=i-n,o){for(o<0?(r=u,o=-o,s=d.length):(r=d,n=i,s=u.length),i=Math.ceil(a/S),s=i>s?i+1:s+1,o>s&&(o=s,r.length=1),r.reverse();o--;)r.push(0);r.reverse()}for(s=u.length,o=d.length,s-o<0&&(o=s,r=d,d=u,u=r),t=0;o;)t=(u[--o]=u[o]+d[o]+t)/de|0,u[o]%=de;for(t&&(u.unshift(t),++n),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=dt(u,n),B?A(e,a,c):e};b.precision=b.sd=function(e){var t,r=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Ae+e);return r.d?(t=Mr(r.d),e&&r.e+1>t&&(t=r.e+1)):t=NaN,t};b.round=function(){var e=this,t=e.constructor;return A(new t(e),e.e+1,t.rounding)};b.sine=b.sin=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+S,n.rounding=1,r=Yn(n,Or(n,r)),n.precision=e,n.rounding=t,A(ye>2?r.neg():r,e,t,!0)):new n(NaN)};b.squareRoot=b.sqrt=function(){var e,t,r,n,o,i,s=this,a=s.d,c=s.e,u=s.s,d=s.constructor;if(u!==1||!a||!a[0])return new d(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(B=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=oe(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=ie((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),n=new d(t)):n=new d(u.toString()),r=(c=d.precision)+3;;)if(i=n,n=i.plus(q(s,i,r+2,1)).times(.5),oe(i.d).slice(0,r)===(t=oe(n.d)).slice(0,r))if(t=t.slice(r-3,r+1),t=="9999"||!o&&t=="4999"){if(!o&&(A(i,c+1,0),i.times(i).eq(s))){n=i;break}r+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(A(n,c+1,1),e=!n.times(n).eq(s));break}return B=!0,A(n,c,d.rounding,e)};b.tangent=b.tan=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+10,n.rounding=1,r=r.sin(),r.s=1,r=q(r,new n(1).minus(r.times(r)).sqrt(),e+10,0),n.precision=e,n.rounding=t,A(ye==2||ye==4?r.neg():r,e,t,!0)):new n(NaN)};b.times=b.mul=function(e){var t,r,n,o,i,s,a,c,u,d=this,l=d.constructor,f=d.d,p=(e=new l(e)).d;if(e.s*=d.s,!f||!f[0]||!p||!p[0])return new l(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(r=ie(d.e/S)+ie(e.e/S),c=f.length,u=p.length,c<u&&(i=f,f=p,p=i,s=c,c=u,u=s),i=[],s=c+u,n=s;n--;)i.push(0);for(n=u;--n>=0;){for(t=0,o=c+n;o>n;)a=i[o]+p[n]*f[o-n-1]+t,i[o--]=a%de|0,t=a/de|0;i[o]=(i[o]+t)%de|0}for(;!i[--s];)i.pop();return t?++r:i.shift(),e.d=i,e.e=dt(i,r),B?A(e,l.precision,l.rounding):e};b.toBinary=function(e,t){return Mt(this,2,e,t)};b.toDecimalPlaces=b.toDP=function(e,t){var r=this,n=r.constructor;return r=new n(r),e===void 0?r:(ae(e,0,Ie),t===void 0?t=n.rounding:ae(t,0,8),A(r,e+r.e+1,t))};b.toExponential=function(e,t){var r,n=this,o=n.constructor;return e===void 0?r=me(n,!0):(ae(e,0,Ie),t===void 0?t=o.rounding:ae(t,0,8),n=A(new o(n),e+1,t),r=me(n,!0,e+1)),n.isNeg()&&!n.isZero()?"-"+r:r};b.toFixed=function(e,t){var r,n,o=this,i=o.constructor;return e===void 0?r=me(o):(ae(e,0,Ie),t===void 0?t=i.rounding:ae(t,0,8),n=A(new i(o),e+o.e+1,t),r=me(n,!1,e+n.e+1)),o.isNeg()&&!o.isZero()?"-"+r:r};b.toFraction=function(e){var t,r,n,o,i,s,a,c,u,d,l,f,p=this,h=p.d,m=p.constructor;if(!h)return new m(p);if(u=r=new m(1),n=c=new m(0),t=new m(n),i=t.e=Mr(h)-p.e-1,s=i%S,t.d[0]=te(10,s<0?S+s:s),e==null)e=i>0?t:u;else{if(a=new m(e),!a.isInt()||a.lt(u))throw Error(Ae+a);e=a.gt(t)?i>0?t:u:a}for(B=!1,a=new m(oe(h)),d=m.precision,m.precision=i=h.length*S*2;l=q(a,t,0,1,1),o=r.plus(l.times(n)),o.cmp(e)!=1;)r=n,n=o,o=u,u=c.plus(l.times(o)),c=o,o=t,t=a.minus(l.times(o)),a=o;return o=q(e.minus(r),n,0,1,1),c=c.plus(o.times(u)),r=r.plus(o.times(n)),c.s=u.s=p.s,f=q(u,n,i,1).minus(p).abs().cmp(q(c,r,i,1).minus(p).abs())<1?[u,n]:[c,r],m.precision=d,B=!0,f};b.toHexadecimal=b.toHex=function(e,t){return Mt(this,16,e,t)};b.toNearest=function(e,t){var r=this,n=r.constructor;if(r=new n(r),e==null){if(!r.d)return r;e=new n(1),t=n.rounding}else{if(e=new n(e),t===void 0?t=n.rounding:ae(t,0,8),!r.d)return e.s?r:e;if(!e.d)return e.s&&(e.s=r.s),e}return e.d[0]?(B=!1,r=q(r,e,0,t,1).times(e),B=!0,A(r)):(e.s=r.s,r=e),r};b.toNumber=function(){return+this};b.toOctal=function(e,t){return Mt(this,8,e,t)};b.toPower=b.pow=function(e){var t,r,n,o,i,s,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(te(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,i=c.rounding,e.eq(1))return A(a,n,i);if(t=ie(e.e/S),t>=e.d.length-1&&(r=u<0?-u:u)<=qn)return o=vr(c,a,r,n),e.s<0?new c(1).div(o):A(o,n,i);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return r=te(+a,u),t=r==0||!isFinite(r)?ie(u*(Math.log("0."+oe(a.d))/Math.LN10+a.e+1)):new c(r+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(B=!1,c.rounding=a.s=1,r=Math.min(12,(t+"").length),o=Nt(e.times(ke(a,n+r)),n),o.d&&(o=A(o,n+5,1),We(o.d,n,i)&&(t=n+10,o=A(Nt(e.times(ke(a,t+r)),t),t+5,1),+oe(o.d).slice(n+1,n+15)+1==1e14&&(o=A(o,n+1,0)))),o.s=s,B=!0,c.rounding=i,A(o,n,i))};b.toPrecision=function(e,t){var r,n=this,o=n.constructor;return e===void 0?r=me(n,n.e<=o.toExpNeg||n.e>=o.toExpPos):(ae(e,1,Ie),t===void 0?t=o.rounding:ae(t,0,8),n=A(new o(n),e,t),r=me(n,e<=n.e||n.e<=o.toExpNeg,e)),n.isNeg()&&!n.isZero()?"-"+r:r};b.toSignificantDigits=b.toSD=function(e,t){var r=this,n=r.constructor;return e===void 0?(e=n.precision,t=n.rounding):(ae(e,1,Ie),t===void 0?t=n.rounding:ae(t,0,8)),A(new n(r),e,t)};b.toString=function(){var e=this,t=e.constructor,r=me(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+r:r};b.truncated=b.trunc=function(){return A(new this.constructor(this),this.e+1,1)};b.valueOf=b.toJSON=function(){var e=this,t=e.constructor,r=me(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+r:r};function oe(e){var t,r,n,o=e.length-1,i="",s=e[0];if(o>0){for(i+=s,t=1;t<o;t++)n=e[t]+"",r=S-n.length,r&&(i+=Te(r)),i+=n;s=e[t],n=s+"",r=S-n.length,r&&(i+=Te(r))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function ae(e,t,r){if(e!==~~e||e<t||e>r)throw Error(Ae+e)}function We(e,t,r,n){var o,i,s,a;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=S,o=0):(o=Math.ceil((t+1)/S),t%=S),i=te(10,S-t),a=e[o]%i|0,n==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=r<4&&a==99999||r>3&&a==49999||a==5e4||a==0):s=(r<4&&a+1==i||r>3&&a+1==i/2)&&(e[o+1]/i/100|0)==te(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=(n||r<4)&&a==9999||!n&&r>3&&a==4999):s=((n||r<4)&&a+1==i||!n&&r>3&&a+1==i/2)&&(e[o+1]/i/1e3|0)==te(10,t-3)-1,s}function st(e,t,r){for(var n,o=[0],i,s=0,a=e.length;s<a;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=Ct.indexOf(e.charAt(s++)),n=0;n<o.length;n++)o[n]>r-1&&(o[n+1]===void 0&&(o[n+1]=0),o[n+1]+=o[n]/r|0,o[n]%=r)}return o.reverse()}function Hn(e,t){var r,n,o;if(t.isZero())return t;n=t.d.length,n<32?(r=Math.ceil(n/3),o=(1/ft(4,r)).toString()):(r=16,o="2.3283064365386962890625e-10"),e.precision+=r,t=Me(e,1,t.times(o),new e(1));for(var i=r;i--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=r,t}var q=function(){function e(n,o,i){var s,a=0,c=n.length;for(n=n.slice();c--;)s=n[c]*o+a,n[c]=s%i|0,a=s/i|0;return a&&n.unshift(a),n}function t(n,o,i,s){var a,c;if(i!=s)c=i>s?1:-1;else for(a=c=0;a<i;a++)if(n[a]!=o[a]){c=n[a]>o[a]?1:-1;break}return c}function r(n,o,i,s){for(var a=0;i--;)n[i]-=a,a=n[i]<o[i]?1:0,n[i]=a*s+n[i]-o[i];for(;!n[0]&&n.length>1;)n.shift()}return function(n,o,i,s,a,c){var u,d,l,f,p,h,m,T,g,x,y,k,I,C,M,U,L,E,D,z,V=n.constructor,ne=n.s==o.s?1:-1,J=n.d,O=o.d;if(!J||!J[0]||!O||!O[0])return new V(!n.s||!o.s||(J?O&&J[0]==O[0]:!O)?NaN:J&&J[0]==0||!O?ne*0:ne/0);for(c?(p=1,d=n.e-o.e):(c=de,p=S,d=ie(n.e/p)-ie(o.e/p)),D=O.length,L=J.length,g=new V(ne),x=g.d=[],l=0;O[l]==(J[l]||0);l++);if(O[l]>(J[l]||0)&&d--,i==null?(C=i=V.precision,s=V.rounding):a?C=i+(n.e-o.e)+1:C=i,C<0)x.push(1),h=!0;else{if(C=C/p+2|0,l=0,D==1){for(f=0,O=O[0],C++;(l<L||f)&&C--;l++)M=f*c+(J[l]||0),x[l]=M/O|0,f=M%O|0;h=f||l<L}else{for(f=c/(O[0]+1)|0,f>1&&(O=e(O,f,c),J=e(J,f,c),D=O.length,L=J.length),U=D,y=J.slice(0,D),k=y.length;k<D;)y[k++]=0;z=O.slice(),z.unshift(0),E=O[0],O[1]>=c/2&&++E;do f=0,u=t(O,y,D,k),u<0?(I=y[0],D!=k&&(I=I*c+(y[1]||0)),f=I/E|0,f>1?(f>=c&&(f=c-1),m=e(O,f,c),T=m.length,k=y.length,u=t(m,y,T,k),u==1&&(f--,r(m,D<T?z:O,T,c))):(f==0&&(u=f=1),m=O.slice()),T=m.length,T<k&&m.unshift(0),r(y,m,k,c),u==-1&&(k=y.length,u=t(O,y,D,k),u<1&&(f++,r(y,D<k?z:O,k,c))),k=y.length):u===0&&(f++,y=[0]),x[l++]=f,u&&y[0]?y[k++]=J[U]||0:(y=[J[U]],k=1);while((U++<L||y[0]!==void 0)&&C--);h=y[0]!==void 0}x[0]||x.shift()}if(p==1)g.e=d,Cr=h;else{for(l=1,f=x[0];f>=10;f/=10)l++;g.e=l+d*p-1,A(g,a?i+g.e+1:i,s,h)}return g}}();function A(e,t,r,n){var o,i,s,a,c,u,d,l,f,p=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+=S,s=t,d=l[f=0],c=d/te(10,o-s-1)%10|0;else if(f=Math.ceil((i+1)/S),a=l.length,f>=a)if(n){for(;a++<=f;)l.push(0);d=c=0,o=1,i%=S,s=i-S+1}else break e;else{for(d=a=l[f],o=1;a>=10;a/=10)o++;i%=S,s=i-S+o,c=s<0?0:d/te(10,o-s-1)%10|0}if(n=n||t<0||l[f+1]!==void 0||(s<0?d:d%te(10,o-s-1)),u=r<4?(c||n)&&(r==0||r==(e.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(i>0?s>0?d/te(10,o-s):0:l[f-1])%10&1||r==(e.s<0?8:7)),t<1||!l[0])return l.length=0,u?(t-=e.e+1,l[0]=te(10,(S-t%S)%S),e.e=-t||0):l[0]=e.e=0,e;if(i==0?(l.length=f,a=1,f--):(l.length=f+1,a=te(10,S-i),l[f]=s>0?(d/te(10,o-s)%te(10,s)|0)*a:0),u)for(;;)if(f==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]==de&&(l[0]=1));break}else{if(l[f]+=a,l[f]!=de)break;l[f--]=0,a=1}for(i=l.length;l[--i]===0;)l.pop()}return B&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function me(e,t,r){if(!e.isFinite())return Dr(e);var n,o=e.e,i=oe(e.d),s=i.length;return t?(r&&(n=r-s)>0?i=i.charAt(0)+"."+i.slice(1)+Te(n):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+Te(-o-1)+i,r&&(n=r-s)>0&&(i+=Te(n))):o>=s?(i+=Te(o+1-s),r&&(n=r-o-1)>0&&(i=i+"."+Te(n))):((n=o+1)<s&&(i=i.slice(0,n)+"."+i.slice(n)),r&&(n=r-s)>0&&(o+1===s&&(i+="."),i+=Te(n))),i}function dt(e,t){var r=e[0];for(t*=S;r>=10;r/=10)t++;return t}function ct(e,t,r){if(t>Gn)throw B=!0,r&&(e.precision=r),Error(Vr);return A(new e(at),t,1,!0)}function le(e,t,r){if(t>Ft)throw Error(Vr);return A(new e(ut),t,r,!0)}function Mr(e){var t=e.length-1,r=t*S+1;if(t=e[t],t){for(;t%10==0;t/=10)r--;for(t=e[0];t>=10;t/=10)r++}return r}function Te(e){for(var t="";e--;)t+="0";return t}function vr(e,t,r,n){var o,i=new e(1),s=Math.ceil(n/S+4);for(B=!1;;){if(r%2&&(i=i.times(t),Rr(i.d,s)&&(o=!0)),r=ie(r/2),r===0){r=i.d.length-1,o&&i.d[r]===0&&++i.d[r];break}t=t.times(t),Rr(t.d,s)}return B=!0,i}function Br(e){return e.d[e.d.length-1]&1}function _r(e,t,r){for(var n,o=new e(t[0]),i=0;++i<t.length;)if(n=new e(t[i]),n.s)o[r](n)&&(o=n);else{o=n;break}return o}function Nt(e,t){var r,n,o,i,s,a,c,u=0,d=0,l=0,f=e.constructor,p=f.rounding,h=f.precision;if(!e.d||!e.d[0]||e.e>17)return new f(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,c=h):c=t,a=new f(.03125);e.e>-2;)e=e.times(a),l+=5;for(n=Math.log(te(2,l))/Math.LN10*2+5|0,c+=n,r=i=s=new f(1),f.precision=c;;){if(i=A(i.times(e),c,1),r=r.times(++d),a=s.plus(q(i,r,c,1)),oe(a.d).slice(0,c)===oe(s.d).slice(0,c)){for(o=l;o--;)s=A(s.times(s),c,1);if(t==null)if(u<3&&We(s.d,c-n,p,u))f.precision=c+=10,r=i=a=new f(1),d=0,u++;else return A(s,f.precision=h,p,B=!0);else return f.precision=h,s}s=a}}function ke(e,t){var r,n,o,i,s,a,c,u,d,l,f,p=1,h=10,m=e,T=m.d,g=m.constructor,x=g.rounding,y=g.precision;if(m.s<0||!T||!T[0]||!m.e&&T[0]==1&&T.length==1)return new g(T&&!T[0]?-1/0:m.s!=1?NaN:T?0:m);if(t==null?(B=!1,d=y):d=t,g.precision=d+=h,r=oe(T),n=r.charAt(0),Math.abs(i=m.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)m=m.times(e),r=oe(m.d),n=r.charAt(0),p++;i=m.e,n>1?(m=new g("0."+r),i++):m=new g(n+"."+r.slice(1))}else return u=ct(g,d+2,y).times(i+""),m=ke(new g(n+"."+r.slice(1)),d-h).plus(u),g.precision=y,t==null?A(m,y,x,B=!0):m;for(l=m,c=s=m=q(m.minus(1),m.plus(1),d,1),f=A(m.times(m),d,1),o=3;;){if(s=A(s.times(f),d,1),u=c.plus(q(s,new g(o),d,1)),oe(u.d).slice(0,d)===oe(c.d).slice(0,d))if(c=c.times(2),i!==0&&(c=c.plus(ct(g,d+2,y).times(i+""))),c=q(c,new g(p),d,1),t==null)if(We(c.d,d-h,x,a))g.precision=d+=h,u=s=m=q(l.minus(1),l.plus(1),d,1),f=A(m.times(m),d,1),o=a=1;else return A(c,g.precision=y,x,B=!0);else return g.precision=y,c;c=u,o+=2}}function Dr(e){return String(e.s*e.s/0)}function Et(e,t){var r,n,o;for((r=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(r<0&&(r=n),r+=+t.slice(n+1),t=t.substring(0,n)):r<0&&(r=t.length),n=0;t.charCodeAt(n)===48;n++);for(o=t.length;t.charCodeAt(o-1)===48;--o);if(t=t.slice(n,o),t){if(o-=n,e.e=r=r-n-1,e.d=[],n=(r+1)%S,r<0&&(n+=S),n<o){for(n&&e.d.push(+t.slice(0,n)),o-=S;n<o;)e.d.push(+t.slice(n,n+=S));t=t.slice(n),n=S-t.length}else n-=o;for(;n--;)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 jn(e,t){var r,n,o,i,s,a,c,u,d;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Er.test(t))return Et(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Wn.test(t))r=16,t=t.toLowerCase();else if(On.test(t))r=2;else if(Un.test(t))r=8;else throw Error(Ae+t);for(i=t.search(/p/i),i>0?(c=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,n=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=vr(n,new n(r),i,i*2)),u=st(t,r,de),d=u.length-1,i=d;u[i]===0;--i)u.pop();return i<0?new n(e.s*0):(e.e=dt(u,d),e.d=u,B=!1,s&&(e=q(e,o,a*4)),c&&(e=e.times(Math.abs(c)<54?te(2,c):Ue.pow(2,c))),B=!0,e)}function Yn(e,t){var r,n=t.d.length;if(n<3)return t.isZero()?t:Me(e,2,t,t);r=1.4*Math.sqrt(n),r=r>16?16:r|0,t=t.times(1/ft(5,r)),t=Me(e,2,t,t);for(var o,i=new e(5),s=new e(16),a=new e(20);r--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(a))));return t}function Me(e,t,r,n,o){var i,s,a,c,u=1,d=e.precision,l=Math.ceil(d/S);for(B=!1,c=r.times(r),a=new e(n);;){if(s=q(a.times(c),new e(t++*t++),d,1),a=o?n.plus(s):n.minus(s),n=q(s.times(c),new e(t++*t++),d,1),s=a.plus(n),s.d[l]!==void 0){for(i=l;s.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=n,n=s,s=i,u++}return B=!0,s.d.length=l+1,s}function ft(e,t){for(var r=e;--t;)r*=e;return r}function Or(e,t){var r,n=t.s<0,o=le(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return ye=n?4:1,t;if(r=t.divToInt(o),r.isZero())ye=n?3:2;else{if(t=t.minus(r.times(o)),t.lte(i))return ye=Br(r)?n?2:3:n?4:1,t;ye=Br(r)?n?1:4:n?3:2}return t.minus(o).abs()}function Mt(e,t,r,n){var o,i,s,a,c,u,d,l,f,p=e.constructor,h=r!==void 0;if(h?(ae(r,1,Ie),n===void 0?n=p.rounding:ae(n,0,8)):(r=p.precision,n=p.rounding),!e.isFinite())d=Dr(e);else{for(d=me(e),s=d.indexOf("."),h?(o=2,t==16?r=r*4-3:t==8&&(r=r*3-2)):o=t,s>=0&&(d=d.replace(".",""),f=new p(1),f.e=d.length-s,f.d=st(me(f),10,o),f.e=f.d.length),l=st(d,10,o),i=c=l.length;l[--c]==0;)l.pop();if(!l[0])d=h?"0p+0":"0";else{if(s<0?i--:(e=new p(e),e.d=l,e.e=i,e=q(e,f,r,n,0,o),l=e.d,i=e.e,u=Cr),s=l[r],a=o/2,u=u||l[r+1]!==void 0,u=n<4?(s!==void 0||u)&&(n===0||n===(e.s<0?3:2)):s>a||s===a&&(n===4||u||n===6&&l[r-1]&1||n===(e.s<0?8:7)),l.length=r,u)for(;++l[--r]>o-1;)l[r]=0,r||(++i,l.unshift(1));for(c=l.length;!l[c-1];--c);for(s=0,d="";s<c;s++)d+=Ct.charAt(l[s]);if(h){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)d+="0";for(l=st(d,o,t),c=l.length;!l[c-1];--c);for(s=1,d="1.";s<c;s++)d+=Ct.charAt(l[s])}else d=d.charAt(0)+"."+d.slice(1);d=d+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)d="0"+d;d="0."+d}else if(++i>c)for(i-=c;i--;)d+="0";else i<c&&(d=d.slice(0,i)+"."+d.slice(i))}d=(t==16?"0x":t==2?"0b":t==8?"0o":"")+d}return e.s<0?"-"+d:d}function Rr(e,t){if(e.length>t)return e.length=t,!0}function zn(e){return new this(e).abs()}function Zn(e){return new this(e).acos()}function Xn(e){return new this(e).acosh()}function Jn(e,t){return new this(e).plus(t)}function Qn(e){return new this(e).asin()}function $n(e){return new this(e).asinh()}function eo(e){return new this(e).atan()}function to(e){return new this(e).atanh()}function ro(e,t){e=new this(e),t=new this(t);var r,n=this.precision,o=this.rounding,i=n+4;return!e.s||!t.s?r=new this(NaN):!e.d&&!t.d?(r=le(this,i,1).times(t.s>0?.25:.75),r.s=e.s):!t.d||e.isZero()?(r=t.s<0?le(this,n,o):new this(0),r.s=e.s):!e.d||t.isZero()?(r=le(this,i,1).times(.5),r.s=e.s):t.s<0?(this.precision=i,this.rounding=1,r=this.atan(q(e,t,i,1)),t=le(this,i,1),this.precision=n,this.rounding=o,r=e.s<0?r.minus(t):r.plus(t)):r=this.atan(q(e,t,i,1)),r}function no(e){return new this(e).cbrt()}function oo(e){return A(e=new this(e),e.e+1,2)}function io(e,t,r){return new this(e).clamp(t,r)}function so(e){if(!e||typeof e!="object")throw Error(lt+"Object expected");var t,r,n,o=e.defaults===!0,i=["precision",1,Ie,"rounding",0,8,"toExpNeg",-Ee,0,"toExpPos",0,Ee,"maxE",0,Ee,"minE",-Ee,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(r=i[t],o&&(this[r]=Vt[r]),(n=e[r])!==void 0)if(ie(n)===n&&n>=i[t+1]&&n<=i[t+2])this[r]=n;else throw Error(Ae+r+": "+n);if(r="crypto",o&&(this[r]=Vt[r]),(n=e[r])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(Fr);else this[r]=!1;else throw Error(Ae+r+": "+n);return this}function ao(e){return new this(e).cos()}function uo(e){return new this(e).cosh()}function Wr(e){var t,r,n;function o(i){var s,a,c,u=this;if(!(u instanceof o))return new o(i);if(u.constructor=o,Kr(i)){u.s=i.s,B?!i.d||i.e>o.maxE?(u.e=NaN,u.d=null):i.e<o.minE?(u.e=0,u.d=[0]):(u.e=i.e,u.d=i.d.slice()):(u.e=i.e,u.d=i.d?i.d.slice():i.d);return}if(c=typeof i,c==="number"){if(i===0){u.s=1/i<0?-1:1,u.e=0,u.d=[0];return}if(i<0?(i=-i,u.s=-1):u.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;B?s>o.maxE?(u.e=NaN,u.d=null):s<o.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[i]):(u.e=s,u.d=[i]);return}else if(i*0!==0){i||(u.s=NaN),u.e=NaN,u.d=null;return}return Et(u,i.toString())}else if(c!=="string")throw Error(Ae+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),u.s=-1):(a===43&&(i=i.slice(1)),u.s=1),Er.test(i)?Et(u,i):jn(u,i)}if(o.prototype=b,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=so,o.clone=Wr,o.isDecimal=Kr,o.abs=zn,o.acos=Zn,o.acosh=Xn,o.add=Jn,o.asin=Qn,o.asinh=$n,o.atan=eo,o.atanh=to,o.atan2=ro,o.cbrt=no,o.ceil=oo,o.clamp=io,o.cos=ao,o.cosh=uo,o.div=co,o.exp=lo,o.floor=fo,o.hypot=po,o.ln=mo,o.log=go,o.log10=ho,o.log2=yo,o.max=bo,o.min=wo,o.mod=xo,o.mul=Po,o.pow=To,o.random=ko,o.round=Ao,o.sign=Io,o.sin=So,o.sinh=Lo,o.sqrt=Bo,o.sub=Ro,o.sum=Ko,o.tan=Co,o.tanh=Vo,o.trunc=Fo,e===void 0&&(e={}),e&&e.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<n.length;)e.hasOwnProperty(r=n[t++])||(e[r]=this[r]);return o.config(e),o}function co(e,t){return new this(e).div(t)}function lo(e){return new this(e).exp()}function fo(e){return A(e=new this(e),e.e+1,3)}function po(){var e,t,r=new this(0);for(B=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)r.d&&(r=r.plus(t.times(t)));else{if(t.s)return B=!0,new this(1/0);r=t}return B=!0,r.sqrt()}function Kr(e){return e instanceof Ue||e&&e.toStringTag===Nr||!1}function mo(e){return new this(e).ln()}function go(e,t){return new this(e).log(t)}function yo(e){return new this(e).log(2)}function ho(e){return new this(e).log(10)}function bo(){return _r(this,arguments,"lt")}function wo(){return _r(this,arguments,"gt")}function xo(e,t){return new this(e).mod(t)}function Po(e,t){return new this(e).mul(t)}function To(e,t){return new this(e).pow(t)}function ko(e){var t,r,n,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:ae(e,1,Ie),n=Math.ceil(e/S),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));i<n;)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(n*=4);i<n;)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=n/4}else throw Error(Fr);else for(;i<n;)a[i++]=Math.random()*1e7|0;for(n=a[--i],e%=S,n&&e&&(o=te(10,S-e),a[i]=(n/o|0)*o);a[i]===0;i--)a.pop();if(i<0)r=0,a=[0];else{for(r=-1;a[0]===0;r-=S)a.shift();for(n=1,o=a[0];o>=10;o/=10)n++;n<S&&(r-=S-n)}return s.e=r,s.d=a,s}function Ao(e){return A(e=new this(e),e.e+1,this.rounding)}function Io(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function So(e){return new this(e).sin()}function Lo(e){return new this(e).sinh()}function Bo(e){return new this(e).sqrt()}function Ro(e,t){return new this(e).sub(t)}function Ko(){var e=0,t=arguments,r=new this(t[e]);for(B=!1;r.s&&++e<t.length;)r=r.plus(t[e]);return B=!0,A(r,this.precision,this.rounding)}function Co(e){return new this(e).tan()}function Vo(e){return new this(e).tanh()}function Fo(e){return A(e=new this(e),e.e+1,1)}b[Symbol.for("nodejs.util.inspect.custom")]=b.toString;b[Symbol.toStringTag]="Decimal";var Ue=b.constructor=Wr(Vt);at=new Ue(at);ut=new Ue(ut);var vt=Ue;import{PublicKey as Ot}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as No}from"@solana/spl-token";import{PublicKey as Z,SystemProgram as Ur,SYSVAR_RENT_PUBKEY as Eo}from"@solana/web3.js";function w({pubkey:e,isSigner:t=!1,isWritable:r=!0}){return{pubkey:e,isWritable:r,isSigner:t}}var _t=[w({pubkey:No,isWritable:!1}),w({pubkey:Ur.programId,isWritable:!1}),w({pubkey:Eo,isWritable:!1})];function qr({publicKey:e,transformSol:t}){let r=Dt(e.toString());if(r instanceof Z)return t&&r.equals(re)?Se:r;if(t&&r.toString()===re.toBase58())return Se;if(typeof r=="string"){if(r===Z.default.toBase58())return Z.default;try{return new Z(r)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Dt(e){try{return new Z(e)}catch{return e}}var cs=new Z("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ls=new Z("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Mo=new Z("SysvarRent111111111111111111111111111111111"),ds=new Z("SysvarC1ock11111111111111111111111111111111"),fs=new Z("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),vo=new Z("Sysvar1nstructions1111111111111111111111111"),ps=Ur.programId,ms=new Z("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),gs=new Z("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),ys=new Z("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),hs=new Z("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),bs=new Z("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),ws=new Z("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),xs=new Z("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Ps=new Z("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ts=new Z("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),ks=new Z("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),As=new Z("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Se=new Z("So11111111111111111111111111111111111111112"),re=Z.default;import{PublicKey as _o}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Gr}from"@solana/spl-token";var Hr={chainId:101,address:_o.default.toBase58(),programId:Gr.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},se={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Gr.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 Wt=class{constructor({mint:t,decimals:r,symbol:n,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===re.toBase58()||t instanceof Ot&&re.equals(t)){this.decimals=se.decimals,this.symbol=se.symbol,this.name=se.name,this.mint=new Ot(se.address),this.isToken2022=!1;return}this.decimals=r,this.symbol=n||t.toString().substring(0,6),this.name=o||t.toString().substring(0,6),this.mint=i?Ot.default:qr({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},Ce=Wt;Ce.WSOL=new Wt(ee(G({},se),{mint:se.address}));import mt from"big.js";import Wo from"bn.js";import Uo from"decimal.js-light";import Do from"toformat";var Oo=Do,qe=Oo;var pt=Q("module/fraction"),Ut=qe(mt),Ge=qe(Uo),qo={[0]:Ge.ROUND_DOWN,[1]:Ge.ROUND_HALF_UP,[2]:Ge.ROUND_UP},Go={[0]:mt.roundDown,[1]:mt.roundHalfUp,[2]:mt.roundUp},W=class{constructor(t,r=new Wo(1)){this.numerator=F(t),this.denominator=F(r)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new W(this.denominator,this.numerator)}add(t){let r=t instanceof W?t:new W(F(t));return this.denominator.eq(r.denominator)?new W(this.numerator.add(r.numerator),this.denominator):new W(this.numerator.mul(r.denominator).add(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}sub(t){let r=t instanceof W?t:new W(F(t));return this.denominator.eq(r.denominator)?new W(this.numerator.sub(r.numerator),this.denominator):new W(this.numerator.mul(r.denominator).sub(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}mul(t){let r=t instanceof W?t:new W(F(t));return new W(this.numerator.mul(r.numerator),this.denominator.mul(r.denominator))}div(t){let r=t instanceof W?t:new W(F(t));return new W(this.numerator.mul(r.denominator),this.denominator.mul(r.numerator))}toSignificant(t,r={groupSeparator:""},n=1){Number.isInteger(t)||pt.logWithError(`${t} is not an integer.`),t<=0&&pt.logWithError(`${t} is not positive.`),Ge.set({precision:t+1,rounding:qo[n]});let o=new Ge(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),r)}toFixed(t,r={groupSeparator:""},n=1){return Number.isInteger(t)||pt.logWithError(`${t} is not an integer.`),t<0&&pt.logWithError(`${t} is negative.`),Ut.DP=t,Ut.RM=Go[n]||1,new Ut(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)}isZero(){return this.numerator.isZero()}};var jo=Q("Raydium_price"),he=class extends W{constructor(r){let{baseToken:n,quoteToken:o,numerator:i,denominator:s}=r;super(i,s);this.baseToken=n,this.quoteToken=o,this.scalar=new W(qt(n.decimals),qt(o.decimals))}get raw(){return new W(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new he({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(r){this.quoteToken!==r.baseToken&&jo.logWithError("mul token not equals");let n=super.mul(r);return new he({baseToken:this.baseToken,quoteToken:r.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(r=this.quoteToken.decimals,n,o){return this.adjusted.toSignificant(r,n,o)}toFixed(r=this.quoteToken.decimals,n,o){return this.adjusted.toFixed(r,n,o)}};var Gt=class{constructor({decimals:t,symbol:r="UNKNOWN",name:n="UNKNOWN"}){this.decimals=t,this.symbol=r,this.name=n}equals(t){return this===t}},gt=Gt;gt.SOL=new Gt(Hr);import Yo from"bn.js";var jr=new W(new Yo(100)),ve=class extends W{toSignificant(t=5,r,n){return this.mul(jr).toSignificant(t,r,n)}toFixed(t=2,r,n){return this.mul(jr).toFixed(t,r,n)}};var Ht=new ue(0),xa=new ue(1),Pa=new ue(2),Ta=new ue(3),ka=new ue(5),jt=new ue(10),Aa=new ue(100),Ia=new ue(1e3),Sa=new ue(1e4),Yr=9007199254740991;function F(e){let t=Q("Raydium_parseBigNumberish");if(e instanceof ue)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new ue(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=Yr||e<=-Yr)&&t.logWithError(`BigNumberish number overflow: ${e}`),new ue(String(e))):typeof e=="bigint"?new ue(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new ue(0))}function qt(e){return jt.pow(F(e))}var Zo=Q("Raydium_amount"),Zr=qe(zo);function Xo(e,t){let r="0",n="0";if(e.includes(".")){let o=e.split(".");o.length===2?([r,n]=o,n=n.padEnd(t,"0")):Zo.logWithError(`invalid number string, num: ${e}`)}else r=e;return[r,n.slice(0,t)||n]}var be=class extends W{constructor(r,n,o=!0,i){let s=new yt(0),a=jt.pow(new yt(r.decimals));if(o)s=F(n);else{let c=new yt(0),u=new yt(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[d,l]=Xo(n.toString(),r.decimals);c=F(d),u=F(l)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=Q(i||"TokenAmount"),this.token=r}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(r){return this.token.equals(r.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(r.raw)}lt(r){return this.token.equals(r.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(r.raw)}add(r){return this.token.equals(r.token)||this.logger.logWithError("add token not equals"),new be(this.token,this.raw.add(r.raw))}subtract(r){return this.token.equals(r.token)||this.logger.logWithError("sub token not equals"),new be(this.token,this.raw.sub(r.raw))}toSignificant(r=this.token.decimals,n,o=0){return super.toSignificant(r,n,o)}toFixed(r=this.token.decimals,n,o=0){return r>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(r,n,o)}toExact(r={groupSeparator:""}){return Zr.DP=this.token.decimals,new Zr(this.numerator.toString()).div(this.denominator.toString()).toFormat(r)}};function zr(e){return typeof e=="object"&&e!==null&&![Ce,be,Jo,W,Qo,he,ve].some(t=>typeof t=="object"&&e instanceof t)}function we(e){return typeof e=="string"?Dt(e):Array.isArray(e)?e.map(t=>we(t)):zr(e)?Object.fromEntries(Object.entries(e).map(([t,r])=>[t,we(r)])):e}import{PublicKey as Ye,sendAndConfirmTransaction as ze,Transaction as Ze,TransactionMessage as Xe,VersionedTransaction as Je}from"@solana/web3.js";import si from"axios";var H={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut"};import{PublicKey as $o,ComputeBudgetProgram as Xr,Transaction as Qr,TransactionMessage as ei,Keypair as $r,VersionedTransaction as en}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ti}from"@solana/spl-token";var Jr=Q("Raydium_txUtil"),tn=1644;function ht(e){let t=[],r=[];return e.microLamports&&(t.push(Xr.setComputeUnitPrice({microLamports:e.microLamports})),r.push(H.SetComputeUnitPrice)),e.units&&(t.push(Xr.setComputeUnitLimit({units:e.units})),r.push(H.SetComputeUnitLimit)),{instructions:t,instructionTypes:r}}async function _e(e){var t,r;try{return((r=await((t=e.getLatestBlockhash)==null?void 0:t.call(e)))==null?void 0:r.blockhash)||(await e.getRecentBlockhash()).blockhash}catch{return(await e.getRecentBlockhash()).blockhash}}function ri(e,t){e.length<1&&Jr.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&Jr.logWithError(`no signers provided:, ${t.toString()}`);let r=new Qr;r.recentBlockhash="11111111111111111111111111111111",r.feePayer=t[0],r.add(...e);try{return Buffer.from(r.serialize({verifySignatures:!1})).toString("base64").length<tn}catch{return!1}}function Ve(e,t){let[r,n]=$o.findProgramAddressSync(e,t);return{publicKey:r,nonce:n}}function He({instructions:e,payer:t,signers:r}){return ri(e,[t,...r])}function je({instructions:e,payer:t,lookupTableAddressAccount:r,recentBlockhash:n=$r.generate().publicKey.toString()}){let i=new ei({payerKey:t,recentBlockhash:n,instructions:e}).compileToV0Message(Object.values(r!=null?r:{}));try{return Buffer.from(new en(i).serialize()).toString("base64").length<tn}catch{return!1}}var ni=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);function Fe(e){let t=[];return e.forEach(r=>{r instanceof Qr&&(r.recentBlockhash||(r.recentBlockhash=ti.toBase58()),r.feePayer||(r.feePayer=$r.generate().publicKey));let n=r.serialize({requireAllSignatures:!1,verifySignatures:!1});r instanceof en&&(n=ni(n));let o=n.toString("base64");t.push(o)}),console.log("simulate tx string:",t),t}import{PublicKey as nn,AddressLookupTableAccount as bt}from"@solana/web3.js";import{PublicKey as oi}from"@solana/web3.js";import{getTransferFeeConfig as pu,unpackMint as mu}from"@solana/spl-token";var Yt=Q("Raydium_accountInfo_util");async function rn(e,t,r){let{batchRequest:n,commitment:o="confirmed"}=G({batchRequest:!1},r),i=zt(t,100),s=new Array(i.length).fill([]);if(n){let a=i.map(d=>{let l=e._buildArgs([d.map(f=>f.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:l}}),c=zt(a,10);s=(await(await Promise.all(c.map(async d=>await e._rpcBatchRequest(d)))).flat()).map(d=>(d.error&&Yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${d.error.message}`),d.result.value.map(l=>{if(l){let{data:f,executable:p,lamports:h,owner:m,rentEpoch:T}=l;return f.length!==2&&f[1]!=="base64"&&Yt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(f[0],"base64"),executable:p,lamports:h,owner:new oi(m),rentEpoch:T}}return null})))}else try{s=await Promise.all(i.map(a=>e.getMultipleAccountsInfo(a,o)))}catch(a){a instanceof Error&&Yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${a.message}`)}return s.flat()}async function Zt({connection:e,address:t}){let r=await rn(e,[...new Set(t.map(o=>o.toString()))].map(o=>new nn(o))),n={};for(let o=0;o<t.length;o++){let i=r[o],s=t[o];if(!i)continue;let a=new bt({key:s,state:bt.deserialize(i.data)});n[s.toString()]=a,wt[s.toString()]=a}return n}var wt={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new bt({key:new nn("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:bt.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 xt=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 n;let t=(await si.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:r}=(n=t==null?void 0:t[15])!=null?n:{};if(!!r)return{units:6e5,microLamports:Math.min(Math.ceil(r*1e6/6e5),25e3)}}addCustomComputeBudget(t){if(t){let{instructions:r,instructionTypes:n}=ht(t);return this.instructions.unshift(...r),this.instructionTypes.unshift(...n),!0}return!1}async calComputeBudget({config:t,defaultIns:r}){try{let n=t||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(n))return;r&&this.instructions.unshift(...r)}catch{r&&this.instructions.unshift(...r)}}addInstruction({instructions:t=[],endInstructions:r=[],signers:n=[],instructionTypes:o=[],endInstructionTypes:i=[],lookupTableAddress:s=[]}){return this.instructions.push(...t),this.endInstructions.push(...r),this.signers.push(...n),this.instructionTypes.push(...o),this.endInstructionTypes.push(...i),this.lookupTableAddress.push(...s.filter(a=>a!==Ye.default.toString())),this}async versionBuild({txVersion:t,extInfo:r}){return t===0?await this.buildV0(G({},r||{})):this.build(r)}build(t){let r=new Ze;return this.allInstructions.length&&r.add(...this.allInstructions),r.feePayer=this.feePayer,{builder:this,transaction:r,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async n=>{var a;let{recentBlockHash:o,skipPreflight:i=!0}=n||{},s=o!=null?o:await _e(this.connection);if(r.recentBlockhash=s,this.signers.length&&r.sign(...this.signers),Fe([r]),(a=this.owner)!=null&&a.isKeyPair)return{txId:await ze(this.connection,r,this.signers.find(c=>c.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:i}),signedTx:r};if(this.signAllTransactions){let c=await this.signAllTransactions([r]);return{txId:await this.connection.sendRawTransaction(c[0].serialize(),{skipPreflight:i}),signedTx:c[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:t||{}}}buildMultiTx(t){let{extraPreBuildData:r=[],extInfo:n}=t,{transaction:o}=this.build(n),i=r.filter(u=>u.transaction.instructions.length>0),s=[o,...i.map(u=>u.transaction)],a=[this.signers,...i.map(u=>u.signers)],c=[...this.instructionTypes,...i.map(u=>u.instructionTypes).flat()];return{builder:this,transactions:s,signers:a,instructionTypes:c,execute:async u=>{var m;let{sequentially:d,onTxUpdate:l,recentBlockHash:f,skipPreflight:p=!0}=u||{},h=f!=null?f:await _e(this.connection);if((m=this.owner)!=null&&m.isKeyPair){if(d){let T=[];for(let g of s){let x=await ze(this.connection,g,this.signers.find(y=>y.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:p});T.push(x)}return{txIds:T,signedTxs:s}}return{txIds:await await Promise.all(s.map(async(T,g)=>(T.recentBlockhash=h,await ze(this.connection,T,a[g].find(x=>x.publicKey.equals(this.owner.publicKey))?a[g]:[...a[g],this.owner.signer],{skipPreflight:p})))),signedTxs:s}}if(this.signAllTransactions){let T=s.map((x,y)=>(x.recentBlockhash=h,a[y].length&&x.sign(...a[y]),x));Fe(T);let g=await this.signAllTransactions(T);if(d){let x=0,y=[],k=async()=>{if(!g[x])return;let I=await this.connection.sendRawTransaction(g[x].serialize(),{skipPreflight:p});y.push({txId:I,status:"sent",signedTx:g[x]}),l==null||l([...y]),x++,this.connection.onSignature(I,C=>{let M=y.findIndex(U=>U.txId===I);M>-1&&(y[M].status=C.err?"error":"success"),l==null||l([...y]),C.err||k()},"processed"),this.connection.getSignatureStatus(I)};return await k(),{txIds:y.map(I=>I.txId),signedTxs:g}}else{let x=[];for(let y=0;y<g.length;y+=1){let k=await this.connection.sendRawTransaction(g[y].serialize(),{skipPreflight:p});x.push(k)}return{txIds:x,signedTxs:g}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:n||{}}}async versionMultiBuild({extraPreBuildData:t,txVersion:r,extInfo:n}){return r===0?await this.buildV0MultiTx({extraPreBuildData:t,buildProps:n||{}}):this.buildMultiTx({extraPreBuildData:t,extInfo:n})}async buildV0(t){let f=t||{},{lookupTableCache:r={},lookupTableAddress:n=[],forerunCreate:o}=f,i=it(f,["lookupTableCache","lookupTableAddress","forerunCreate"]),s=G(G({},this.cluster==="devnet"?{}:wt),r),a=Array.from(new Set([...n,...this.lookupTableAddress])),c=[];for(let p of a)s[p]===void 0&&c.push(new Ye(p));let u=await Zt({connection:this.connection,address:c});for(let[p,h]of Object.entries(u))s[p]=h;let d=new Xe({payerKey:this.feePayer,recentBlockhash:o?Ye.default.toBase58():await _e(this.connection),instructions:[...this.allInstructions]}).compileToV0Message(Object.values(s)),l=new Je(d);return l.sign(this.signers),{builder:this,transaction:l,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async p=>{var T;let{recentBlockHash:h,skipPreflight:m=!0}=p||{};if(h&&(l.message.recentBlockhash=h),Fe([l]),(T=this.owner)!=null&&T.isKeyPair){this.signers.find(k=>k.publicKey.equals(this.owner.publicKey))||l.sign([this.owner.signer]);let g=await this.connection.sendTransaction(l,{skipPreflight:m}),{lastValidBlockHeight:x,blockhash:y}=await this.connection.getLatestBlockhash();return await this.connection.confirmTransaction({blockhash:y,lastValidBlockHeight:x,signature:g},"confirmed"),{txId:g,signedTx:l}}if(this.signAllTransactions){let g=await this.signAllTransactions([l]);return{txId:await this.connection.sendTransaction(g[0],{skipPreflight:m}),signedTx:g[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async buildV0MultiTx(t){let{extraPreBuildData:r=[],buildProps:n}=t,{transaction:o}=await this.buildV0(n),i=r.filter(u=>u.builder.instructions.length>0),s=[o,...i.map(u=>u.transaction)],a=[this.signers,...i.map(u=>u.signers)],c=[...this.instructionTypes,...i.map(u=>u.instructionTypes).flat()];return s.forEach(async(u,d)=>{u.sign(a[d])}),{builder:this,transactions:s,signers:a,instructionTypes:c,buildProps:n,execute:async u=>{var h;let{sequentially:d,onTxUpdate:l,recentBlockHash:f,skipPreflight:p=!0}=u||{};if(f&&s.forEach(m=>m.message.recentBlockhash=f),Fe(s),(h=this.owner)!=null&&h.isKeyPair){let{lastValidBlockHeight:m,blockhash:T}=await this.connection.getLatestBlockhash();if(s.forEach((g,x)=>{a[x].find(y=>y.publicKey.equals(this.owner.publicKey))||g.sign([this.owner.signer])}),d){let g=[];for(let x of s){let y=await this.connection.sendTransaction(x,{skipPreflight:p}),{lastValidBlockHeight:k,blockhash:I}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:I,lastValidBlockHeight:k,signature:y},"confirmed"),g.push(y)}return{txIds:g,signedTxs:s}}return{txIds:await Promise.all(s.map(async g=>{let x=await this.connection.sendTransaction(g,{skipPreflight:p});return await this.connection.confirmTransaction({blockhash:T,lastValidBlockHeight:m,signature:x},"confirmed"),x})),signedTxs:s}}if(this.signAllTransactions){let m=await this.signAllTransactions(s);if(d){let T=0,g=[],x=async()=>{if(!m[T])return;let y=await this.connection.sendTransaction(m[T],{skipPreflight:p});g.push({txId:y,status:"sent",signedTx:m[T]}),l==null||l([...g]),T++,this.connection.onSignature(y,k=>{let I=g.findIndex(C=>C.txId===y);I>-1&&(g[I].status=k.err?"error":"success"),l==null||l([...g]),k.err||x()},"processed"),this.connection.getSignatureStatus(y)};return x(),{txIds:[],signedTxs:m}}else{let T=[];for(let g=0;g<m.length;g+=1){let x=await this.connection.sendTransaction(m[g],{skipPreflight:p});T.push(x)}return{txIds:T,signedTxs:m}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:n||{}}}async sizeCheckBuild(t){let u=t||{},{computeBudgetConfig:r}=u,n=it(u,["computeBudgetConfig"]),o=r?ht(r):{instructions:[],instructionTypes:[]},i=this.signers.reduce((d,l)=>ee(G({},d),{[l.publicKey.toBase58()]:l}),{}),s=[],a=[],c=[];if(this.allInstructions.forEach(d=>{let l=[...c,d],f=r?[...o.instructions,...l]:l,h=[...new Set(l.map(m=>m.keys.filter(T=>T.isSigner).map(T=>T.pubkey.toString())).flat()).values()].map(m=>new Ye(m));if(c.length<12&&He({instructions:f,payer:this.feePayer,signers:h})||He({instructions:l,payer:this.feePayer,signers:h}))c.push(d);else{if(c.length===0)throw Error("item ins too big");He({instructions:r?[...o.instructions,...c]:[...c],payer:this.feePayer,signers:h})?s.push(new Ze().add(...o.instructions,...c)):s.push(new Ze().add(...c)),a.push(Array.from(new Set(c.map(m=>m.keys.filter(T=>T.isSigner).map(T=>T.pubkey.toString())).flat())).map(m=>i[m]).filter(m=>m!==void 0)),c=[d]}}),c.length>0){let l=[...new Set(c.map(f=>f.keys.filter(p=>p.isSigner).map(p=>p.pubkey.toString())).flat()).values()].map(f=>i[f]).filter(f=>f!==void 0);He({instructions:r?[...o.instructions,...c]:[...c],payer:this.feePayer,signers:l.map(f=>f.publicKey)})?s.push(new Ze().add(...o.instructions,...c)):s.push(new Ze().add(...c)),a.push(l)}return s.forEach(d=>d.feePayer=this.feePayer),{builder:this,transactions:s,signers:a,instructionTypes:this.instructionTypes,execute:async d=>{var T;let{sequentially:l,onTxUpdate:f,recentBlockHash:p,skipPreflight:h=!0}=d||{},m=p!=null?p:await _e(this.connection);if(s.forEach(async(g,x)=>{g.recentBlockhash=m,a[x].length&&g.sign(...a[x])}),Fe(s),(T=this.owner)!=null&&T.isKeyPair){if(l){let g=[];for(let x of s){let y=await ze(this.connection,x,this.signers.find(k=>k.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:h});g.push(y)}return{txIds:g,signedTxs:s}}return{txIds:await Promise.all(s.map(async(g,x)=>await ze(this.connection,g,a[x].find(y=>y.publicKey.equals(this.owner.publicKey))?a[x]:[...a[x],this.owner.signer],{skipPreflight:h}))),signedTxs:s}}if(this.signAllTransactions){let g=await this.signAllTransactions(s);if(l){let x=0,y=[],k=async()=>{if(!g[x])return;let I=await this.connection.sendRawTransaction(g[x].serialize(),{skipPreflight:h});y.push({txId:I,status:"sent",signedTx:g[x]}),f==null||f([...y]),x++,this.connection.onSignature(I,C=>{let M=y.findIndex(U=>U.txId===I);M>-1&&(y[M].status=C.err?"error":"success"),f==null||f([...y]),C.err||k()},"processed"),this.connection.getSignatureStatus(I)};return await k(),{txIds:y.map(I=>I.txId),signedTxs:g}}else{let x=[];for(let y=0;y<g.length;y+=1){let k=await this.connection.sendRawTransaction(g[y].serialize(),{skipPreflight:h});x.push(k)}return{txIds:x,signedTxs:g}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:n||{}}}async sizeCheckBuildV0(t){let T=t||{},{computeBudgetConfig:r,lookupTableCache:n={},lookupTableAddress:o=[]}=T,i=it(T,["computeBudgetConfig","lookupTableCache","lookupTableAddress"]),s=G(G({},this.cluster==="devnet"?{}:wt),n),a=Array.from(new Set([...this.lookupTableAddress,...o])),c=[];for(let g of a)s[g]===void 0&&c.push(new Ye(g));let u=await Zt({connection:this.connection,address:c});for(let[g,x]of Object.entries(u))s[g]=x;let d=r?ht(r):{instructions:[],instructionTypes:[]},l=await _e(this.connection),f=this.signers.reduce((g,x)=>ee(G({},g),{[x.publicKey.toBase58()]:x}),{}),p=[],h=[],m=[];if(this.allInstructions.forEach(g=>{let x=[...m,g],y=r?[...d.instructions,...x]:x;if(m.length<12&&je({instructions:y,payer:this.feePayer,lookupTableAddressAccount:s})||je({instructions:x,payer:this.feePayer,lookupTableAddressAccount:s}))m.push(g);else{if(m.length===0)throw Error("item ins too big");let k={};for(let I of[...new Set(a)])s[I]!==void 0&&(k[I]=s[I]);if(r&&je({instructions:[...d.instructions,...m],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let I=new Xe({payerKey:this.feePayer,recentBlockhash:l,instructions:[...d.instructions,...m]}).compileToV0Message(Object.values(s));p.push(new Je(I))}else{let I=new Xe({payerKey:this.feePayer,recentBlockhash:l,instructions:[...m]}).compileToV0Message(Object.values(s));p.push(new Je(I))}h.push(Array.from(new Set(m.map(I=>I.keys.filter(C=>C.isSigner).map(C=>C.pubkey.toString())).flat())).map(I=>f[I]).filter(I=>I!==void 0)),m=[g]}}),m.length>0){let x=[...new Set(m.map(y=>y.keys.filter(k=>k.isSigner).map(k=>k.pubkey.toString())).flat()).values()].map(y=>f[y]).filter(y=>y!==void 0);if(r&&je({instructions:[...d.instructions,...m],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let y=new Xe({payerKey:this.feePayer,recentBlockhash:l,instructions:[...d.instructions,...m]}).compileToV0Message(Object.values(s));p.push(new Je(y))}else{let y=new Xe({payerKey:this.feePayer,recentBlockhash:l,instructions:[...m]}).compileToV0Message(Object.values(s));p.push(new Je(y))}h.push(x)}return{builder:this,transactions:p,buildProps:t,signers:h,instructionTypes:this.instructionTypes,execute:async g=>{var C;let{sequentially:x,onTxUpdate:y,recentBlockHash:k,skipPreflight:I=!0}=g||{};if(p.map(async(M,U)=>{h[U].length&&M.sign(h[U]),k&&(M.message.recentBlockhash=k)}),Fe(p),(C=this.owner)!=null&&C.isKeyPair){let{lastValidBlockHeight:M,blockhash:U}=await this.connection.getLatestBlockhash();if(p.forEach((L,E)=>{h[E].find(D=>D.publicKey.equals(this.owner.publicKey))||L.sign([this.owner.signer])}),x){let L=[];for(let E of p){let D=await this.connection.sendTransaction(E,{skipPreflight:I}),{lastValidBlockHeight:z,blockhash:V}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:V,lastValidBlockHeight:z,signature:D},"confirmed"),L.push(D)}return{txIds:L,signedTxs:p}}return{txIds:await Promise.all(p.map(async L=>{let E=await this.connection.sendTransaction(L,{skipPreflight:I});return await this.connection.confirmTransaction({blockhash:U,lastValidBlockHeight:M,signature:E},"confirmed"),E})),signedTxs:p}}if(this.signAllTransactions){let M=await this.signAllTransactions(p);if(x){let U=0,L=[],E=async()=>{if(!M[U])return;let D=await this.connection.sendTransaction(M[U],{skipPreflight:I});L.push({txId:D,status:"sent",signedTx:M[U]}),y==null||y([...L]),U++,this.connection.onSignature(D,z=>{let V=L.findIndex(ne=>ne.txId===D);V>-1&&(L[V].status=z.err?"error":"success"),y==null||y([...L]),z.err||E()},"processed"),this.connection.getSignatureStatus(D)};return E(),{txIds:[],signedTxs:M}}else{let U=[];for(let L=0;L<M.length;L+=1){let E=await this.connection.sendTransaction(M[L],{skipPreflight:I});U.push(E)}return{txIds:U,signedTxs:M}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}};function zt(e,t=1,r=[]){let n=[...e];if(t<=0)return r;for(;n.length;)r.push(n.splice(0,t));return r}import{PublicKey as v}from"@solana/web3.js";var on=new v("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),sn=new v("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Qe=new v("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Mu=new v("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),vu=new v("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),_u=new v("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Du=new v("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ou=new v("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Wu=new v("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Uu=new v("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),qu=new v("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Gu=new v("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Hu=new v("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),ju=new v("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Yu=new v("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),zu=new v("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Zu=new v("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Xu=new v("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ai=new v("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),ui=new v("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),ci=new v("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2");var Ju={SERUM_MARKET:v.default,OPENBOOK_MARKET:new v("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:v.default,FarmV3:new v("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new v("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new v("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new v("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new v("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new v("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),Router:new v("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:ai,CREATE_CPMM_POOL_AUTH:ui,CREATE_CPMM_POOL_FEE_ACC:ci,FEE_DESTINATION_ID:new v("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR")};import{PublicKey as li}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as di}from"@solana/spl-token";function De(e,t,r){return Ve([e.toBuffer(),(r!=null?r:di).toBuffer(),t.toBuffer()],new li("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import oc from"bn.js";import{PublicKey as Ii,Keypair as Si}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Li}from"@solana/spl-token";import Wl from"bn.js";import{PublicKey as bi}from"@solana/web3.js";import ln,{isBN as dn}from"bn.js";import{bits as Ac,BitStructure as Ic,blob as fi,Blob as Sc,cstr as Lc,f32 as Bc,f32be as Rc,f64 as Kc,f64be as Cc,greedy as Vc,Layout as pi,ns64 as Fc,ns64be as Nc,nu64 as Ec,nu64be as Mc,offset as vc,s16 as _c,s16be as Dc,s24 as Oc,s24be as Wc,s32 as Uc,s32be as qc,s40 as Gc,s40be as Hc,s48 as jc,s48be as Yc,s8 as zc,seq as mi,struct as Zc,Structure as gi,u16 as Xc,u16be as Jc,u24 as Qc,u24be as $c,u32 as el,u32be as tl,u40 as rl,u40be as nl,u48 as ol,u48be as il,u8 as yi,UInt as hi,union as sl,Union as al,unionLayoutDiscriminator as ul,utf8 as cl}from"@solana/buffer-layout";var Xt=pi,an=gi;var Jt=hi;var un=yi;var cn=mi;var Ne=fi;var Oe=class extends Xt{constructor(r,n,o){super(r,o);this.blob=Ne(r),this.signed=n}decode(r,n=0){let o=new ln(this.blob.decode(r,n),10,"le");return this.signed?o.fromTwos(this.span*8).clone():o}encode(r,n,o=0){return typeof r=="number"&&(r=new ln(r)),this.signed&&(r=r.toTwos(this.span*8)),this.blob.encode(r.toArrayLike(Buffer,"le",this.span),n,o)}};function $(e){return new Jt(1,e)}function $e(e){return new Jt(4,e)}function P(e){return new Oe(8,!1,e)}function xe(e){return new Oe(16,!1,e)}function fn(e){return new Oe(1,!0,e)}function Tt(e){return new Oe(8,!0,e)}var Pt=class extends Xt{constructor(r,n,o,i){super(r.span,i);this.layout=r,this.decoder=n,this.encoder=o}decode(r,n){return this.decoder(this.layout.decode(r,n))}encode(r,n,o){return this.layout.encode(this.encoder(r),n,o)}getSpan(r,n){return this.layout.getSpan(r,n)}};function N(e){return new Pt(Ne(32),t=>new bi(t),t=>t.toBuffer(),e)}function kt(e){return new Pt(un(),wi,xi,e)}function wi(e){if(e===0)return!1;if(e===1)return!0;throw new Error("Invalid bool: "+e)}function xi(e){return e?1:0}var Qt=class extends an{decode(t,r){return super.decode(t,r)}};function Y(e,t,r){return new Qt(e,t,r)}function X(e,t,r){let n,o=typeof t=="number"?t:dn(t)?t.toNumber():new Proxy(t,{get(i,s){if(!n){let a=Reflect.get(i,"count");n=dn(a)?a.toNumber():a,Reflect.set(i,"count",n)}return Reflect.get(i,s)},set(i,s,a){return s==="count"&&(n=a),Reflect.set(i,s,a)}});return cn(e,o,r)}var et=Y([N("mint"),N("owner"),P("amount"),$e("delegateOption"),N("delegate"),$("state"),$e("isNativeOption"),P("isNative"),P("delegatedAmount"),$e("closeAuthorityOption"),N("closeAuthority")]);function Pi(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function $t(e,...t){if(!Pi(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 er(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 pn(e,t){$t(e);let r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}var It=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),fe=(e,t)=>e<<32-t|e>>>t;var Sl=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ti(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function tr(e){return typeof e=="string"&&(e=Ti(e)),$t(e),e}var At=class{clone(){return this._cloneInto()}},Ll={}.toString;function mn(e){let t=n=>e().update(tr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ki(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,u=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+u,a,n)}var gn=(e,t,r)=>e&t^~e&r,yn=(e,t,r)=>e&t^e&r^t&r,St=class extends At{constructor(t,r,n,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,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){er(this);let{view:r,buffer:n,blockLen:o}=this;t=tr(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=It(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){er(this),pn(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;ki(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=It(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%r&&t.buffer.set(n),t}};var Ai=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]),Le=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Be=new Uint32Array(64),rr=class extends St{constructor(){super(64,32,8,!1),this.A=Le[0]|0,this.B=Le[1]|0,this.C=Le[2]|0,this.D=Le[3]|0,this.E=Le[4]|0,this.F=Le[5]|0,this.G=Le[6]|0,this.H=Le[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)Be[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=Be[l-15],p=Be[l-2],h=fe(f,7)^fe(f,18)^f>>>3,m=fe(p,17)^fe(p,19)^p>>>10;Be[l]=m+Be[l-7]+h+Be[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){let f=fe(a,6)^fe(a,11)^fe(a,25),p=d+f+gn(a,c,u)+Ai[l]+Be[l]|0,m=(fe(n,2)^fe(n,13)^fe(n,22))+yn(n,o,i)|0;d=u,u=c,c=a,a=s+p|0,s=i,i=o,o=n,n=p+m|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,i,s,a,c,u,d)}roundClean(){Be.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var hn=mn(()=>new rr);var Hl=Q("Raydium_Util");function Lt({fromPublicKey:e,programId:t=Li}){let r=Si.generate().publicKey.toBase58().slice(0,32);return{publicKey:Bi(e,r,t),seed:r}}function Bi(e,t,r){let n=Buffer.concat([e.toBuffer(),Buffer.from(t),r.toBuffer()]),o=hn(n);return new Ii(o)}import{createInitializeAccountInstruction as Ri,createCloseAccountInstruction as Ki,createTransferInstruction as zl,TOKEN_PROGRAM_ID as tt}from"@solana/spl-token";import{PublicKey as Ci,SystemProgram as Vi}from"@solana/web3.js";import Fi from"bn.js";function Ni(e){let{mint:t,tokenAccount:r,owner:n,programId:o=tt}=e;return Ri(r,t,n,o)}function Ei(e){let{tokenAccount:t,payer:r,multiSigners:n=[],owner:o,programId:i=tt}=e;return Ki(t,r,o,n,i)}async function nr(e){let{connection:t,amount:r,commitment:n,payer:o,owner:i,skipCloseAccount:s}=e,a=await t.getMinimumBalanceForRentExemption(et.span,n),c=F(r).add(new Fi(a)),u=Lt({fromPublicKey:o,programId:tt});return{addresses:{newAccount:u.publicKey},signers:[],instructions:[Vi.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:u.seed,newAccountPubkey:u.publicKey,lamports:c.toNumber(),space:et.span,programId:tt}),Ni({mint:new Ci(se.address),tokenAccount:u.publicKey,owner:i,programId:tt})],instructionTypes:[H.CreateAccount,H.InitAccount],endInstructionTypes:s?[]:[H.CloseAccount],endInstructions:s?[]:[Ei({tokenAccount:u.publicKey,payer:o,owner:i})]}}var or=(...e)=>e.map(t=>{try{return typeof t=="object"?JSON.stringify(t):t}catch{return t}}).join(", "),rt=class{constructor({scope:t,moduleName:r}){this.disabled=!1;this.scope=t,this.logger=Q(r)}createTxBuilder(t){return this.scope.checkOwner(),new xt({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(or(t))}logInfo(...t){this.logger.info(or(t))}logAndCreateError(...t){let r=or(t);throw new Error(r)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};import{PublicKey as xn}from"@solana/web3.js";var ir=Y([$("instruction")]),sr=Y([$("instruction")]),Mi=Y([P("rewardState"),P("rewardOpenTime"),P("rewardEndTime"),P("rewardLastUpdateTime"),P("totalReward"),P("totalRewardEmissioned"),P("rewardClaimed"),P("rewardPerSecond"),xe("accRewardPerShare"),N("rewardVault"),N("rewardMint"),N("rewardSender"),P("rewardType"),X(P(),15,"padding")]),vi=Y([P("state"),P("nonce"),N("lpVault"),N("rewardVault"),N(),N(),P(),P(),P("totalReward"),xe("perShareReward"),P("lastSlot"),P("perSlotReward")]),_i=Y([P("state"),P("nonce"),N("lpVault"),N("rewardVaultA"),P("totalRewardA"),xe("perShareRewardA"),P("perSlotRewardA"),$("option"),N("rewardVaultB"),Ne(7),P("totalRewardB"),xe("perShareRewardB"),P("perSlotRewardB"),P("lastSlot"),N()]),Di=Y([P(),P("state"),P("nonce"),P("validRewardTokenNum"),xe("rewardMultiplier"),P("rewardPeriodMax"),P("rewardPeriodMin"),P("rewardPeriodExtend"),N("lpMint"),N("lpVault"),X(Mi,5,"rewardInfos"),N("creator"),N(),X(P(),32,"padding")]),Oi=new Proxy(vi,{get(e,t,r){return t==="decode"?(...n)=>{let o=e.decode(...n);return ee(G({},o),{version:3,rewardInfos:[{rewardVault:o.rewardVault,totalReward:o.totalReward,perSlotReward:o.perSlotReward,perShareReward:o.perShareReward}]})}:Reflect.get(e,t,r)}}),Wi=new Proxy(_i,{get(e,t,r){return t==="decode"?(...n)=>{let o=e.decode(...n);return ee(G({},o),{version:5,rewardInfos:[{rewardVault:o.rewardVaultA,totalReward:o.totalRewardA,perSlotReward:o.perSlotRewardA,perShareReward:o.perShareRewardA},{rewardVault:o.rewardVaultB,totalReward:o.totalRewardB,perSlotReward:o.perSlotRewardB,perShareReward:o.perShareRewardB}]})}:Reflect.get(e,t,r)}}),Bt=new Proxy(Di,{get(e,t,r){return t==="decode"?(...n)=>{let o=e.decode(...n);return ee(G({},o),{version:6,rewardInfos:o.rewardInfos.map(i=>{var s;return ee(G({},i),{rewardType:((s=Object.entries(Re).find(a=>String(a[1])===i.rewardType.toString()))!=null?s:["Standard SPL"])[0]})})})}:Reflect.get(e,t,r)}}),Ui=Y([P("isSet"),P("rewardPerSecond"),P("rewardOpenTime"),P("rewardEndTime"),P("rewardType")]),ar=Y([$("instruction"),P("nonce"),X(Ui,5,"rewardTimeInfo")]),ur=Y([$("instruction"),P("rewardReopenTime"),P("rewardEndTime"),P("rewardPerSecond")]),cr=Y([$("instruction"),P("isSet"),P("rewardPerSecond"),P("rewardOpenTime"),P("rewardEndTime"),P("rewardType")]),hd=Y([P("state"),N("id"),N("owner"),P("deposited"),X(P(),1,"rewardDebts")]),lr=Y([P("state"),N("id"),N("owner"),P("deposited"),X(xe(),1,"rewardDebts"),P(""),P("voteLockedBalance"),X(P(),15)]),bd=Y([P("state"),N("id"),N("owner"),P("deposited"),X(P(),2,"rewardDebts")]),bn=Y([P("state"),N("id"),N("owner"),P("deposited"),X(xe(),2,"rewardDebts"),X(P(),17)]),wn=Y([P(),P("state"),N("id"),N("owner"),P("deposited"),X(xe(),5,"rewardDebts"),X(P(),16)]),ce=Y([$("instruction"),P("amount")]),qi=Y([N("mint"),N("grantAuthority"),P("baselineVoteWeightScaledFactor"),P("maxExtraLockupVoteWeightScaledFactor"),P("lockupSaturationSecs"),fn("digitShift"),X($(),7,"reserved1"),X(P(),7,"reserved2")]),Gi=Y([Ne(8),N("governanceProgramId"),N("realm"),N("realmGoverningTokenMint"),N("realmAuthority"),X($(),32,"reserved1"),X(qi,4,"votingMints"),Tt("timeOffset"),$("bump"),X($(),7,"reserved2"),X(P(),11,"reserved3")]),Hi=Y([Tt("startTime"),Tt("endTime"),$("kind"),X($(),15,"reserved")]),ji=Y([X(Hi,1,"lockup"),P("amountDeposited_native"),P("amountInitiallyLockedNative"),kt("isUsed"),kt("allowClawback"),$("votingMintConfigIdx"),X($(),29,"reserved")]),Yi=Y([Ne(8),N("voterAuthority"),N("registrar"),X(ji,32,"deposits"),$("voterBump"),$("voterWweightRecordBump"),X($(),94,"reserved")]);var Sd=Q("Raydium_farm_config"),Pn=new xn("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Tn=new xn("FrspKwj8i3pNmKwXreTveC4fu7KL5ZbGeXdZBe2XViu1");var kn={3:lr,5:bn,6:wn},dr=e=>[3,5,6].indexOf(e)!==-1,fr=e=>{var s;let{version:t,rewardInfos:r,rewardTokenAccountsPublicKeys:n}=e,o=`rewardInfo:${JSON.stringify(r)}, rewardAccount:${JSON.stringify(n)}`,i={3:()=>{if(r.length!==1||n.length!==1)return`rewardInfos or rewardTokenAccounts lengths not equal 1: ${o}`},5:()=>{if(r.length!==n.length)return`rewardInfos and rewardTokenAccounts lengths not equal: ${o}`},6:()=>{if(!n.length||r.length!==n.length)return`no rewardTokenAccounts or rewardInfos and rewardTokenAccounts lengths not equal: ${o}`}};return(s=i[t])==null?void 0:s.call(i)},Re={"Standard SPL":0,"Option tokens":1},Pe={[on.toString()]:3,[sn.toString()]:5,[Qe.toString()]:6};import{PublicKey as _,SystemProgram as Sn,SYSVAR_RENT_PUBKEY as Xi,SYSVAR_CLOCK_PUBKEY as Rt,TransactionInstruction as pe}from"@solana/web3.js";import{createAssociatedTokenAccountInstruction as of,TOKEN_PROGRAM_ID as Ke,ASSOCIATED_TOKEN_PROGRAM_ID as sf}from"@solana/spl-token";import Ln from"bn.js";import zi from"bn.js";var Zi=Q("Raydium.farm.util");function nt({programId:e,poolId:t,mint:r,type:n}){let{publicKey:o}=Ve([t.toBuffer(),r.toBuffer(),Buffer.from(n==="lpVault"?"lp_vault_associated_seed":n==="rewardVault"?"reward_vault_associated_seed":"","utf-8")],e);return o}function ge({programId:e,poolId:t,owner:r,version:n}){let{publicKey:o}=Ve([t.toBuffer(),r.toBuffer(),Buffer.from(n===6?"farmer_info_associated_seed":"staker_info_v2_associated_seed","utf-8")],e);return o}var An=({programId:e,poolId:t})=>Ve([t.toBuffer()],e);function In(e){return{isSet:new zi(1),rewardPerSecond:F(e.perSecond),rewardOpenTime:F(e.openTime),rewardEndTime:F(e.endTime),rewardType:F(Re[e.rewardType])}}function pr(e){return F(e.endTime).sub(F(e.openTime)).mul(F(e.perSecond))}function mr(e){let t=kn[e];return t||Zi.logWithError("invalid version",e),t}var Ji=Q("Raydium_farm_instruction"),wf={voterStakeRegistryCreateVoter:Buffer.from([6,24,245,52,243,255,148,25]),voterStakeRegistryCreateDepositEntry:Buffer.from([185,131,167,186,159,125,19,67]),voterStakeRegistryDeposit:Buffer.from([242,35,198,137,82,225,242,182]),voterStakeRegistryWithdraw:Buffer.from([183,18,70,156,148,109,161,34]),voterStakeRegistryUpdateVoterWeightRecord:Buffer.from([45,185,3,36,109,190,115,169])};function Bn(e){let{version:t,id:r,ledger:n,programId:o,owner:i}=e,s={3:9,5:10}[t];s||Ji.logWithError(`invalid farm pool version: ${t}`);let a=Buffer.alloc(ir.span);ir.encode({instruction:s},a);let c=[w({pubkey:r}),w({pubkey:n}),w({pubkey:i,isWritable:!1}),w({pubkey:Sn.programId,isWritable:!1}),w({pubkey:Xi,isWritable:!1})];return{instruction:new pe({programId:o,keys:c,data:a}),instructionType:H.FarmV3CreateLedger}}function Rn(e){var n;let t=Buffer.alloc(ar.span);ar.encode({instruction:0,nonce:new Ln(e.nonce),rewardTimeInfo:e.rewardInfoConfig},t);let r=[..._t,w({pubkey:e.farmId}),w({pubkey:e.farmAuthority,isWritable:!1}),w({pubkey:e.lpVault}),w({pubkey:e.lpMint,isWritable:!1}),w({pubkey:e.lockVault}),w({pubkey:e.lockMint,isWritable:!1}),w({pubkey:(n=e.lockUserAccount)!=null?n:re}),w({pubkey:e.owner,isWritable:!1,isSigner:!0})];for(let o of e.rewardInfo)r.push(w({pubkey:o.rewardMint,isWritable:!1}),w({pubkey:o.rewardVault}),w({pubkey:o.userRewardToken}));return{instruction:new pe({programId:e.programId,keys:r,data:t}),instructionType:H.FarmV6Create}}function Kn(e){let t=Buffer.alloc(sr.span);sr.encode({instruction:5},t);let r=[w({pubkey:Ke,isWritable:!1}),w({pubkey:e.id}),w({pubkey:e.authority,isWritable:!1}),w({pubkey:e.lpVault,isWritable:!1}),w({pubkey:e.rewardVault}),w({pubkey:e.userRewardToken}),w({pubkey:e.owner,isWritable:!1,isSigner:!0})];return{instruction:new pe({programId:e.programId,keys:r,data:t}),instructionType:H.FarmV6CreatorWithdraw}}function gr({payer:e,rewardVault:t,userRewardTokenPub:r,farmKeys:n,rewardInfo:o}){let i=Buffer.alloc(ur.span);ur.encode({instruction:3,rewardReopenTime:F(o.openTime),rewardEndTime:F(o.endTime),rewardPerSecond:F(o.perSecond)},i);let s=[w({pubkey:Ke,isWritable:!1}),w({pubkey:n.id}),w({pubkey:n.lpVault,isWritable:!1}),w({pubkey:t}),w({pubkey:r}),w({pubkey:e,isWritable:!1,isSigner:!0})];return new pe({programId:n.programId,keys:s,data:i})}function yr({payer:e,userRewardTokenPub:t,farmKeys:r,rewardVault:n,rewardInfo:o}){let i=Buffer.alloc(cr.span);cr.encode({instruction:4,isSet:new Ln(1),rewardPerSecond:F(o.perSecond),rewardOpenTime:F(o.openTime),rewardEndTime:F(o.endTime),rewardType:F(Re[o.rewardType])},i);let s=[..._t,w({pubkey:r.id}),w({pubkey:r.authority,isWritable:!1}),w({pubkey:o.mint,isWritable:!1}),w({pubkey:n}),w({pubkey:t}),w({pubkey:e,isWritable:!1,isSigner:!0})];return new pe({programId:r.programId,keys:s,data:i})}function hr(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s}=e,[a,c]=[new _(t.programId),new _(t.id)],u=ge({programId:a,poolId:c,owner:i,version:6}),d=Buffer.alloc(ce.span);ce.encode({instruction:2,amount:F(s)},d);let l=[w({pubkey:Ke,isWritable:!1}),w({pubkey:c}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:new _(r.lpVault)}),w({pubkey:u}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n})];for(let f=0;f<r.rewardInfos.length;f++)l.push(w({pubkey:new _(r.rewardInfos[f].vault)})),l.push(w({pubkey:o[f]}));return new pe({programId:a,keys:l,data:d})}function br(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new _(t.programId),new _(t.id)],d=ge({programId:c,poolId:u,owner:i,version:5}),l=Buffer.alloc(ce.span);ce.encode({instruction:12,amount:F(s)},l);let f=[w({pubkey:u}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:d}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n}),w({pubkey:new _(r.lpVault)}),w({pubkey:o[0]}),w({pubkey:new _(r.rewardInfos[0].vault)}),w({pubkey:Rt,isWritable:!1}),w({pubkey:Ke,isWritable:!1})];for(let p=1;p<r.rewardInfos.length;p++)f.push(w({pubkey:o[p]})),f.push(w({pubkey:new _(r.rewardInfos[p].vault)}));if(a)for(let p of a)f.push(w({pubkey:p}));return new pe({programId:c,keys:f,data:l})}function wr(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new _(t.programId),new _(t.id)],d=ge({programId:c,poolId:u,owner:i,version:3}),l=Buffer.alloc(ce.span);ce.encode({instruction:11,amount:F(s)},l);let f=[w({pubkey:u}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:d}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n}),w({pubkey:new _(r.lpVault)}),w({pubkey:o[0]}),w({pubkey:new _(r.rewardInfos[0].vault)}),w({pubkey:Rt,isWritable:!1}),w({pubkey:Ke,isWritable:!1})];if(a)for(let p of a)f.push(w({pubkey:p}));return new pe({programId:c,keys:f,data:l})}function Cn(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new _(t.programId),new _(t.id)],d=ge({programId:c,poolId:u,owner:i,version:3}),l=Buffer.alloc(ce.span);ce.encode({instruction:10,amount:F(s)},l);let f=[w({pubkey:u}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:d}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n}),w({pubkey:new _(r.lpVault)}),w({pubkey:o[0]}),w({pubkey:new _(r.rewardInfos[0].vault)}),w({pubkey:Rt,isWritable:!1}),w({pubkey:Ke,isWritable:!1})];if(a)for(let p of a)f.push(w({pubkey:p}));return new pe({programId:c,keys:f,data:l})}function Vn(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new _(t.programId),new _(t.id)],d=ge({programId:c,poolId:u,owner:i,version:5}),l=Buffer.alloc(ce.span);ce.encode({instruction:11,amount:F(s)},l);let f=[w({pubkey:u}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:d}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n}),w({pubkey:new _(r.lpVault)}),w({pubkey:o[0]}),w({pubkey:new _(r.rewardInfos[0].vault)}),w({pubkey:Rt,isWritable:!1}),w({pubkey:Ke,isWritable:!1})];for(let p=1;p<r.rewardInfos.length;p++)f.push(w({pubkey:o[p]})),f.push(w({pubkey:new _(r.rewardInfos[p].vault)}));if(a)for(let p of a)f.push(w({pubkey:p}));return new pe({programId:c,keys:f,data:l})}function Fn(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s}=e,[a,c]=[new _(t.programId),new _(t.id)],u=ge({programId:a,poolId:c,owner:i,version:6}),d=Buffer.alloc(ce.span);ce.encode({instruction:1,amount:F(s)},d);let l=[w({pubkey:Ke,isWritable:!1}),w({pubkey:Sn.programId,isWritable:!1}),w({pubkey:c}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:new _(r.lpVault)}),w({pubkey:u}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n})];for(let f=0;f<r.rewardInfos.length;f++)l.push(w({pubkey:new _(r.rewardInfos[f].vault)})),l.push(w({pubkey:o[f]}));return new pe({programId:a,keys:l,data:d})}var xr=class extends rt{async _getUserRewardInfo({payer:t,rewardInfo:r}){if(r.mint.equals(re)){let n=await nr({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:t,amount:pr(ee(G({},r),{openTime:r.openTime.toString(),endTime:r.endTime.toString()}))});return{rewardPubKey:n.addresses.newAccount,newInstruction:n}}return{rewardPubKey:await this.scope.account.getCreatedTokenAccount({mint:r.mint,associatedOnly:!1})}}async create({poolInfo:t,rewardInfos:r,payer:n,programId:o=Qe,txVersion:i}){this.checkDisabled(),this.scope.checkOwner();let a={lpMint:new j(t.lpMint.address),lockInfo:{lockMint:Pn,lockVault:Tn},version:6,rewardInfos:r,programId:o},c=this.createTxBuilder(),u=n!=null?n:this.scope.ownerPubKey,d=Lt({fromPublicKey:u,programId:a.programId}),l=await this.scope.connection.getMinimumBalanceForRentExemption(Bt.span);c.addInstruction({instructions:[$i.createAccountWithSeed({fromPubkey:u,basePubkey:u,seed:d.seed,newAccountPubkey:d.publicKey,lamports:l,space:Bt.span,programId:a.programId})]});let{publicKey:f,nonce:p}=An({programId:new j(a.programId),poolId:d.publicKey}),h=nt({programId:a.programId,poolId:d.publicKey,mint:a.lpMint,type:"lpVault"}),m=[],T=[];for(let k of a.rewardInfos){k.openTime>=k.endTime&&this.logAndCreateError("start time error","rewardInfo.rewardOpenTime",k.openTime.toString()),isNaN(Re[k.rewardType])&&this.logAndCreateError("rewardType error",k.rewardType),Number(k.perSecond)<=0&&this.logAndCreateError("rewardPerSecond error",k.perSecond),m.push(In(k));let{rewardPubKey:I,newInstruction:C}=await this._getUserRewardInfo({rewardInfo:k,payer:u});C&&c.addInstruction(C),I||this.logAndCreateError("cannot found target token accounts",this.scope.account.tokenAccounts);let M=k.mint.equals(re)?new j(se.address):k.mint;T.push({rewardMint:M,rewardVault:nt({programId:a.programId,poolId:d.publicKey,mint:M,type:"rewardVault"}),userRewardToken:I})}let g=await this.scope.account.getCreatedTokenAccount({mint:a.lockInfo.lockMint});g||this.logAndCreateError("cannot found lock vault","tokenAccounts",this.scope.account.tokenAccounts);let{instruction:x,instructionType:y}=Rn({farmId:d.publicKey,owner:this.scope.ownerPubKey,farmAuthority:f,lpVault:h,lpMint:a.lpMint,lockVault:a.lockInfo.lockVault,lockMint:a.lockInfo.lockMint,lockUserAccount:g,programId:a.programId,rewardInfo:T,rewardInfoConfig:m,nonce:p});return c.addInstruction({instructions:[x],instructionTypes:[y]}).versionBuild({txVersion:i,extInfo:{farmId:d.publicKey,farmAuthority:f,lpVault:h,lockUserAccount:g,nonce:p}})}async restartReward({farmInfo:t,payer:r,newRewardInfo:n,txVersion:o}){var T;let i=Pe[t.programId];i!==6&&this.logAndCreateError("invalid farm version ",i);let s=we((await this.scope.api.fetchFarmKeysById({ids:t.id}))[0]),a={id:s.id,rewardInfos:t.rewardInfos,lpVault:s.lpVault,programId:s.programId};n.openTime>=n.endTime&&this.logAndCreateError("start time error","newRewardInfo",n);let c=r||this.scope.ownerPubKey,u=n.mint.equals(re)?new j(se.address):n.mint,d=a.rewardInfos.findIndex(g=>new j(g.mint.address).equals(u)),l=s.rewardInfos[d];l||this.logAndCreateError("configuration does not exist","rewardMint",u);let f=(T=l.vault)!=null?T:re,p=this.createTxBuilder(),{rewardPubKey:h,newInstruction:m}=await this._getUserRewardInfo({rewardInfo:n,payer:c});return m&&p.addInstruction(m),h||this.logAndCreateError("cannot found target token accounts",this.scope.account.tokenAccounts),p.addInstruction({instructions:[gr({payer:this.scope.ownerPubKey,rewardVault:f,userRewardTokenPub:h,farmKeys:a,rewardInfo:n})],instructionTypes:[H.FarmV6Restart]}).versionBuild({txVersion:o})}async restartRewards({farmInfo:t,payer:r,newRewardInfos:n,txVersion:o}){var d;let i=Pe[t.programId];i!==6&&this.logAndCreateError("invalid farm version ",i);let s=we((await this.scope.api.fetchFarmKeysById({ids:t.id}))[0]),a={id:s.id,rewardInfos:t.rewardInfos,lpVault:s.lpVault,programId:s.programId};n.forEach(l=>{l.openTime>=l.endTime&&this.logAndCreateError("start time error","newRewardInfo",l)});let c=r||this.scope.ownerPubKey,u=this.createTxBuilder();for(let l of n){let f=l.mint.equals(re)?new j(se.address):l.mint,p=a.rewardInfos.findIndex(y=>new j(y.mint.address).equals(f)),h=s.rewardInfos[p];h||this.logAndCreateError("configuration does not exist","rewardMint",f);let m=(d=h.vault)!=null?d:re,{rewardPubKey:T,newInstruction:g}=await this._getUserRewardInfo({rewardInfo:l,payer:c});g&&u.addInstruction(g),T||this.logAndCreateError("cannot found target token accounts",this.scope.account.tokenAccounts);let x=gr({payer:this.scope.ownerPubKey,rewardVault:m,userRewardTokenPub:T,farmKeys:a,rewardInfo:l});u.addInstruction({instructions:[x],instructionTypes:[H.FarmV6Restart]})}return u.versionBuild({txVersion:o})}async addNewRewardToken(t){let{txVersion:r,farmInfo:n,newRewardInfo:o,payer:i}=t,s=Pe[n.programId];s!==6&&this.logAndCreateError("invalid farm version ",s);let a=we((await this.scope.api.fetchFarmKeysById({ids:n.id}))[0]),c=i!=null?i:this.scope.ownerPubKey,u=this.createTxBuilder(),d=o.mint.equals(re)?new j(se.address):o.mint,l=nt({programId:new j(n.programId),poolId:new j(n.id),mint:d,type:"rewardVault"}),{rewardPubKey:f,newInstruction:p}=await this._getUserRewardInfo({rewardInfo:o,payer:c});return p&&u.addInstruction(p),f||this.logAndCreateError("annot found target token accounts",this.scope.account.tokenAccounts),o.mint=d,u.addInstruction({instructions:[yr({payer:this.scope.ownerPubKey,userRewardTokenPub:f,farmKeys:a,rewardVault:l,rewardInfo:o})],instructionTypes:[H.FarmV6CreatorAddReward]}).versionBuild({txVersion:r})}async addNewRewardsToken(t){let{txVersion:r,farmInfo:n,newRewardInfos:o,payer:i}=t,s=Pe[n.programId];s!==6&&this.logAndCreateError("invalid farm version ",s);let a=we((await this.scope.api.fetchFarmKeysById({ids:n.id}))[0]),c=i!=null?i:this.scope.ownerPubKey,u=this.createTxBuilder();for(let d of o){let l=d.mint.equals(re)?new j(se.address):d.mint,f=nt({programId:new j(n.programId),poolId:new j(n.id),mint:l,type:"rewardVault"}),{rewardPubKey:p,newInstruction:h}=await this._getUserRewardInfo({rewardInfo:d,payer:c});h&&u.addInstruction(h),p||this.logAndCreateError("cannot found target token accounts",this.scope.account.tokenAccounts);let m=yr({payer:this.scope.ownerPubKey,userRewardTokenPub:p,farmKeys:a,rewardVault:f,rewardInfo:ee(G({},d),{mint:l})});u.addInstruction({instructions:[m],instructionTypes:[H.FarmV6CreatorAddReward]})}return u.versionBuild({txVersion:r})}async deposit(t){let{txVersion:r,farmInfo:n,amount:o,feePayer:i,useSOLBalance:s,associatedOnly:a=!0,checkCreateATAOwner:c=!1,userAuxiliaryLedgers:u,computeBudgetConfig:d}=t;this.scope.availability.addFarm===!1&&this.logAndCreateError("farm deposit feature disabled in your region");let{rewardInfos:l,programId:f}=n,p=Pe[f];dr(p)||this.logAndCreateError("invalid farm program:",n.programId);let[h,m]=[new j(n.programId),new j(n.id)],T=(await this.scope.api.fetchFarmKeysById({ids:n.id}))[0],g=ge({programId:h,poolId:m,owner:this.scope.ownerPubKey,version:p}),x=this.createTxBuilder();x.addCustomComputeBudget(d);let y={};for(let V of this.scope.account.tokenAccounts)if(a){let ne=De(this.scope.ownerPubKey,V.mint,V.programId).publicKey;V.publicKey&&ne.equals(V.publicKey)&&(y[V.mint.toString()]=V.publicKey)}else y[V.mint.toString()]=V.publicKey;let k=T.lpMint,I=y[k.address];I||this.logAndCreateError("you don't have any lp","lp zero",y);let C=[];for(let V of l){let ne=s&&V.mint.address===Se.toString(),J=y[V.mint.address];if(!J){let{account:O,instructionParams:Pr}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:V.mint.programId,mint:new j(V.mint.address),notUseTokenAccount:ne,createInfo:{payer:i||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!ne,associatedOnly:ne?!1:a,checkCreateATAOwner:c});J=O,Pr&&x.addInstruction(Pr)}y[V.mint.address]=J,C.push(J)}let M,U=await this.scope.connection.getAccountInfo(g);if(U&&(M=mr(p).decode(U.data)),n.programId!==Qe.toString()&&!M){let{instruction:V,instructionType:ne}=Bn({id:m,programId:h,version:p,ledger:g,owner:this.scope.ownerPubKey});x.addInstruction({instructions:[V],instructionTypes:[ne]})}let L=fr({version:p,rewardInfos:l,rewardTokenAccountsPublicKeys:C});L&&this.logAndCreateError(L);let E={amount:F(o),owner:this.scope.ownerPubKey,farmInfo:n,farmKeys:T,lpAccount:I,rewardAccounts:C,userAuxiliaryLedgers:u==null?void 0:u.map(V=>new j(V))},D=p===6?Fn(E):p===5?Vn(E):Cn(E),z={3:H.FarmV3Deposit,5:H.FarmV5Deposit,6:H.FarmV6Deposit};return x.addInstruction({instructions:[D],instructionTypes:[z[p]]}).versionBuild({txVersion:r})}async withdraw(t){let{txVersion:r,farmInfo:n,amount:o,deposited:i,useSOLBalance:s,feePayer:a,associatedOnly:c=!0,checkCreateATAOwner:u=!1,userAuxiliaryLedgers:d,computeBudgetConfig:l}=t,{rewardInfos:f}=n;this.scope.availability.removeFarm===!1&&this.logAndCreateError("farm withdraw feature disabled in your region");let p=Pe[n.programId];dr(p)||this.logAndCreateError("invalid farm program:",n.programId);let h=(await this.scope.api.fetchFarmKeysById({ids:n.id}))[0],m=this.createTxBuilder();m.addCustomComputeBudget(l);let T={};for(let L of this.scope.account.tokenAccounts)if(c){let E=De(this.scope.ownerPubKey,L.mint).publicKey;L.publicKey&&E.equals(L.publicKey)&&(T[L.mint.toString()]=L.publicKey)}else T[L.mint.toString()]=L.publicKey;if(i)i.isZero()&&this.logAndCreateError("no deposited lp",{farmId:n.id});else{let L=ge({programId:new j(n.programId),poolId:new j(n.id),owner:this.scope.ownerPubKey,version:p}),E=await this.scope.connection.getAccountInfo(L);E||this.logAndCreateError("no lp data",{farmId:n.id,version:p,ledgerData:E}),mr(p).decode(E.data).deposited.isZero()&&this.logAndCreateError("no deposited lp",{farmId:n.id})}let g=h.lpMint.address,x=s&&g===Se.toString(),y=T[g.toString()];if(!y){let{account:L,instructionParams:E}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:h.lpMint.programId,mint:new j(g),notUseTokenAccount:x,createInfo:{payer:a||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!0,associatedOnly:x?!1:c,checkCreateATAOwner:u});y=L,E&&m.addInstruction(E)}T[g.toString()]=y;let k=[];for(let L of f){let E=s&&L.mint.address===Se.toString(),D=T[L.mint.address];if(!D){let{account:z,instructionParams:V}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:L.mint.programId,mint:new j(L.mint.address),notUseTokenAccount:E,createInfo:{payer:a||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!E,associatedOnly:E?!1:c,checkCreateATAOwner:u});D=z,V&&m.addInstruction(V)}T[L.mint.address]=D,k.push(D)}let I=fr({version:p,rewardInfos:f,rewardTokenAccountsPublicKeys:k});I&&this.logAndCreateError(I);let C={amount:F(o),owner:this.scope.ownerPubKey,farmInfo:n,farmKeys:h,lpAccount:y,rewardAccounts:k,userAuxiliaryLedgers:d==null?void 0:d.map(L=>new j(L))},M=p===6?hr(C):p===5?br(C):wr(C),U={3:H.FarmV3Withdraw,5:H.FarmV5Withdraw,6:H.FarmV6Withdraw};return m.addInstruction({instructions:[M],instructionTypes:[U[p]]}).versionBuild({txVersion:r})}async withdrawFarmReward({farmInfo:t,withdrawMint:r,txVersion:n}){var p;this.scope.checkOwner();let o=we((await this.scope.api.fetchFarmKeysById({ids:t.id}))[0]),i=Pe[t.programId];i!==6&&this.logAndCreateError("invalid farm version",i);let s=t.rewardInfos.findIndex(h=>h.mint.address===re.toString()?new j(se.address):r),a=o.rewardInfos[s];a||this.logAndCreateError("withdraw mint error","rewardInfos",t);let c=(p=a==null?void 0:a.vault)!=null?p:re,u=this.createTxBuilder(),d;if(r.equals(re)){let h=await nr({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:this.scope.ownerPubKey,amount:pr(ee(G({},a),{openTime:a.openTime,endTime:a.endTime,perSecond:new vt(a.perSecond).mul(10**a.mint.decimals).toString()}))});d=h.addresses.newAccount,u.addInstruction(h)}else{let h=await this.scope.account.getCreatedTokenAccount({mint:r});h===null?(d=await this.scope.account.getAssociatedTokenAccount(r),u.addInstruction({instructions:[Qi(this.scope.ownerPubKey,d,this.scope.ownerPubKey,r)],instructionTypes:[H.CreateATA]})):d=h}let{instruction:l,instructionType:f}=Kn({programId:o.programId,id:o.id,authority:o.authority,lpVault:o.lpVault,rewardVault:c,userRewardToken:d,owner:this.scope.ownerPubKey});return u.addInstruction({instructions:[l],instructionTypes:[f]}).versionBuild({txVersion:n})}async harvestAllRewards(t){let{farmInfoList:r,useSOLBalance:n,feePayer:o,associatedOnly:i=!0,checkCreateATAOwner:s=!1,userAuxiliaryLedgers:a,txVersion:c,computeBudgetConfig:u}=t,d=this.createTxBuilder(),l={};for(let h of this.scope.account.tokenAccounts)if(i){let m=De(this.scope.ownerPubKey,h.mint).publicKey;h.publicKey&&m.equals(h.publicKey)&&(l[h.mint.toString()]=h.publicKey)}else l[h.mint.toString()]=h.publicKey;let p=(await this.scope.api.fetchFarmKeysById({ids:Object.values(r).map(h=>h.id).join(",")})).reduce((h,m)=>ee(G({},h),{[m.id]:m}),{});for(let h of Object.values(r)){let{programId:m,lpMint:T,rewardInfos:g,id:x}=h,y=Pe[m],k=T.address,I=n&&k===Se.toString(),C=l[k];if(!C){let{account:z,instructionParams:V}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:T.programId,mint:new j(k),notUseTokenAccount:I,createInfo:{payer:o||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!0,associatedOnly:I?!1:i,checkCreateATAOwner:s});C=z,V&&d.addInstruction(V)}l[k.toString()]=C;let M=[];for(let z of g){let V=n&&z.mint.address===Se.toString(),ne=l[z.mint.address];if(!ne){let{account:J,instructionParams:O}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:z.mint.programId,mint:new j(z.mint.address),notUseTokenAccount:V,createInfo:{payer:o||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!V,associatedOnly:V?!1:i,checkCreateATAOwner:s});ne=J,O&&d.addInstruction(O)}l[z.mint.address]=ne,M.push(ne)}let U=p[x],L={amount:Ht,owner:this.scope.ownerPubKey,farmInfo:h,farmKeys:U,lpAccount:C,rewardAccounts:M,userAuxiliaryLedgers:a==null?void 0:a.map(z=>new j(z))},E=y===6?hr(L):y===5?br(L):wr(L),D={3:H.FarmV3Withdraw,5:H.FarmV5Withdraw,6:H.FarmV6Withdraw};d.addInstruction({instructions:[E],instructionTypes:[D[y]]})}return c===1?d.sizeCheckBuild({computeBudgetConfig:u}):d.sizeCheckBuildV0({computeBudgetConfig:u})}};export{xr as default};
|
|
1
|
+
var Nn=Object.defineProperty,En=Object.defineProperties;var Mn=Object.getOwnPropertyDescriptors;var ot=Object.getOwnPropertySymbols;var kr=Object.prototype.hasOwnProperty,Ar=Object.prototype.propertyIsEnumerable;var Tr=(e,t,r)=>t in e?Nn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,H=(e,t)=>{for(var r in t||(t={}))kr.call(t,r)&&Tr(e,r,t[r]);if(ot)for(var r of ot(t))Ar.call(t,r)&&Tr(e,r,t[r]);return e},ee=(e,t)=>En(e,Mn(t));var it=(e,t)=>{var r={};for(var n in e)kr.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&ot)for(var n of ot(e))t.indexOf(n)<0&&Ar.call(e,n)&&(r[n]=e[n]);return r};import{createAssociatedTokenAccountInstruction as Qi}from"@solana/spl-token";import{PublicKey as G,SystemProgram as $i}from"@solana/web3.js";import{get as Ir,set as vn}from"lodash";import Lr from"dayjs";import _n from"dayjs/plugin/utc";Lr.extend(_n);var Kt=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 Lr().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 r=t.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(r)}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}},Sr={},Dn={};function Q(e){let t=Ir(Sr,e);if(!t){let r=Ir(Dn,e);t=new Kt({name:e,logLevel:r}),vn(Sr,e,t)}return t}import{PublicKey as Jo}from"@solana/web3.js";import Qo from"bn.js";import zo from"big.js";import yt from"bn.js";import ue from"bn.js";var Ee=9e15,Ie=1e9,Ct="0123456789abcdef",at="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ut="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Vt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ee,maxE:Ee,crypto:!1},Cr,ye,B=!0,lt="[DecimalError] ",Ae=lt+"Invalid argument: ",Vr=lt+"Precision limit exceeded",Fr=lt+"crypto unavailable",Nr="[object Decimal]",ie=Math.floor,te=Math.pow,On=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Wn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Un=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Er=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,de=1e7,S=7,qn=9007199254740991,Gn=at.length-1,Ft=ut.length-1,b={toStringTag:Nr};b.absoluteValue=b.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),I(e)};b.ceil=function(){return I(new this.constructor(this),this.e+1,2)};b.clampedTo=b.clamp=function(e,t){var r,n=this,o=n.constructor;if(e=new o(e),t=new o(t),!e.s||!t.s)return new o(NaN);if(e.gt(t))throw Error(Ae+t);return r=n.cmp(e),r<0?e:n.cmp(t)>0?t:new o(n)};b.comparedTo=b.cmp=function(e){var t,r,n,o,i=this,s=i.d,a=(e=new i.constructor(e)).d,c=i.s,u=e.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(i.e!==e.e)return i.e>e.e^c<0?1:-1;for(n=s.length,o=a.length,t=0,r=n<o?n:o;t<r;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return n===o?0:n>o^c<0?1:-1};b.cosine=b.cos=function(){var e,t,r=this,n=r.constructor;return r.d?r.d[0]?(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+S,n.rounding=1,r=Hn(n,Or(n,r)),n.precision=e,n.rounding=t,I(ye==2||ye==3?r.neg():r,e,t,!0)):new n(1):new n(NaN)};b.cubeRoot=b.cbrt=function(){var e,t,r,n,o,i,s,a,c,u,d=this,l=d.constructor;if(!d.isFinite()||d.isZero())return new l(d);for(B=!1,i=d.s*te(d.s*d,1/3),!i||Math.abs(i)==1/0?(r=oe(d.d),e=d.e,(i=(e-r.length+1)%3)&&(r+=i==1||i==-2?"0":"00"),i=te(r,1/3),e=ie((e+1)/3)-(e%3==(e<0?-1:2)),i==1/0?r="5e"+e:(r=i.toExponential(),r=r.slice(0,r.indexOf("e")+1)+e),n=new l(r),n.s=d.s):n=new l(i.toString()),s=(e=l.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(d),n=q(u.plus(d).times(a),u.plus(c),s+2,1),oe(a.d).slice(0,s)===(r=oe(n.d)).slice(0,s))if(r=r.slice(s-3,s+1),r=="9999"||!o&&r=="4999"){if(!o&&(I(a,e+1,0),a.times(a).times(a).eq(d))){n=a;break}s+=4,o=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(I(n,e+1,1),t=!n.times(n).times(n).eq(d));break}return B=!0,I(n,e,l.rounding,t)};b.decimalPlaces=b.dp=function(){var e,t=this.d,r=NaN;if(t){if(e=t.length-1,r=(e-ie(this.e/S))*S,e=t[e],e)for(;e%10==0;e/=10)r--;r<0&&(r=0)}return r};b.dividedBy=b.div=function(e){return q(this,new this.constructor(e))};b.dividedToIntegerBy=b.divToInt=function(e){var t=this,r=t.constructor;return I(q(t,new r(e),0,1,1),r.precision,r.rounding)};b.equals=b.eq=function(e){return this.cmp(e)===0};b.floor=function(){return I(new this.constructor(this),this.e+1,3)};b.greaterThan=b.gt=function(e){return this.cmp(e)>0};b.greaterThanOrEqualTo=b.gte=function(e){var t=this.cmp(e);return t==1||t===0};b.hyperbolicCosine=b.cosh=function(){var e,t,r,n,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;r=s.precision,n=s.rounding,s.precision=r+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(e=Math.ceil(o/3),t=(1/ft(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=Me(s,1,i.times(t),new s(1),!0);for(var c,u=e,d=new s(8);u--;)c=i.times(i),i=a.minus(c.times(d.minus(c.times(d))));return I(i,s.precision=r,s.rounding=n,!0)};b.hyperbolicSine=b.sinh=function(){var e,t,r,n,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(t=i.precision,r=i.rounding,i.precision=t+Math.max(o.e,o.sd())+4,i.rounding=1,n=o.d.length,n<3)o=Me(i,2,o,o,!0);else{e=1.4*Math.sqrt(n),e=e>16?16:e|0,o=o.times(1/ft(5,e)),o=Me(i,2,o,o,!0);for(var s,a=new i(5),c=new i(16),u=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(c.times(s).plus(u))))}return i.precision=t,i.rounding=r,I(o,t,r,!0)};b.hyperbolicTangent=b.tanh=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+7,n.rounding=1,q(r.sinh(),r.cosh(),n.precision=e,n.rounding=t)):new n(r.s)};b.inverseCosine=b.acos=function(){var e,t=this,r=t.constructor,n=t.abs().cmp(1),o=r.precision,i=r.rounding;return n!==-1?n===0?t.isNeg()?le(r,o,i):new r(0):new r(NaN):t.isZero()?le(r,o+4,i).times(.5):(r.precision=o+6,r.rounding=1,t=t.asin(),e=le(r,o+4,i).times(.5),r.precision=o,r.rounding=i,e.minus(t))};b.inverseHyperbolicCosine=b.acosh=function(){var e,t,r=this,n=r.constructor;return r.lte(1)?new n(r.eq(1)?0:NaN):r.isFinite()?(e=n.precision,t=n.rounding,n.precision=e+Math.max(Math.abs(r.e),r.sd())+4,n.rounding=1,B=!1,r=r.times(r).minus(1).sqrt().plus(r),B=!0,n.precision=e,n.rounding=t,r.ln()):new n(r)};b.inverseHyperbolicSine=b.asinh=function(){var e,t,r=this,n=r.constructor;return!r.isFinite()||r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+2*Math.max(Math.abs(r.e),r.sd())+6,n.rounding=1,B=!1,r=r.times(r).plus(1).sqrt().plus(r),B=!0,n.precision=e,n.rounding=t,r.ln())};b.inverseHyperbolicTangent=b.atanh=function(){var e,t,r,n,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,n=o.sd(),Math.max(n,e)<2*-o.e-1?I(new i(o),e,t,!0):(i.precision=r=n-o.e,o=q(o.plus(1),new i(1).minus(o),r+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};b.inverseSine=b.asin=function(){var e,t,r,n,o=this,i=o.constructor;return o.isZero()?new i(o):(t=o.abs().cmp(1),r=i.precision,n=i.rounding,t!==-1?t===0?(e=le(i,r+4,n).times(.5),e.s=o.s,e):new i(NaN):(i.precision=r+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=r,i.rounding=n,o.times(2)))};b.inverseTangent=b.atan=function(){var e,t,r,n,o,i,s,a,c,u=this,d=u.constructor,l=d.precision,f=d.rounding;if(u.isFinite()){if(u.isZero())return new d(u);if(u.abs().eq(1)&&l+4<=Ft)return s=le(d,l+4,f).times(.25),s.s=u.s,s}else{if(!u.s)return new d(NaN);if(l+4<=Ft)return s=le(d,l+4,f).times(.5),s.s=u.s,s}for(d.precision=a=l+10,d.rounding=1,r=Math.min(28,a/S+2|0),e=r;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(B=!1,t=Math.ceil(a/S),n=1,c=u.times(u),s=new d(u),o=u;e!==-1;)if(o=o.times(c),i=s.minus(o.div(n+=2)),o=o.times(c),s=i.plus(o.div(n+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===i.d[e]&&e--;);return r&&(s=s.times(2<<r-1)),B=!0,I(s,d.precision=l,d.rounding=f,!0)};b.isFinite=function(){return!!this.d};b.isInteger=b.isInt=function(){return!!this.d&&ie(this.e/S)>this.d.length-2};b.isNaN=function(){return!this.s};b.isNegative=b.isNeg=function(){return this.s<0};b.isPositive=b.isPos=function(){return this.s>0};b.isZero=function(){return!!this.d&&this.d[0]===0};b.lessThan=b.lt=function(e){return this.cmp(e)<0};b.lessThanOrEqualTo=b.lte=function(e){return this.cmp(e)<1};b.logarithm=b.log=function(e){var t,r,n,o,i,s,a,c,u=this,d=u.constructor,l=d.precision,f=d.rounding,p=5;if(e==null)e=new d(10),t=!0;else{if(e=new d(e),r=e.d,e.s<0||!r||!r[0]||e.eq(1))return new d(NaN);t=e.eq(10)}if(r=u.d,u.s<0||!r||!r[0]||u.eq(1))return new d(r&&!r[0]?-1/0:u.s!=1?NaN:r?0:1/0);if(t)if(r.length>1)i=!0;else{for(o=r[0];o%10===0;)o/=10;i=o!==1}if(B=!1,a=l+p,s=ke(u,a),n=t?ct(d,a+10):ke(e,a),c=q(s,n,a,1),We(c.d,o=l,f))do if(a+=10,s=ke(u,a),n=t?ct(d,a+10):ke(e,a),c=q(s,n,a,1),!i){+oe(c.d).slice(o+1,o+15)+1==1e14&&(c=I(c,l+1,0));break}while(We(c.d,o+=10,f));return B=!0,I(c,l,f)};b.minus=b.sub=function(e){var t,r,n,o,i,s,a,c,u,d,l,f,p=this,h=p.constructor;if(e=new h(e),!p.d||!e.d)return!p.s||!e.s?e=new h(NaN):p.d?e.s=-e.s:e=new h(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(u=p.d,f=e.d,a=h.precision,c=h.rounding,!u[0]||!f[0]){if(f[0])e.s=-e.s;else if(u[0])e=new h(p);else return new h(c===3?-0:0);return B?I(e,a,c):e}if(r=ie(e.e/S),d=ie(p.e/S),u=u.slice(),i=d-r,i){for(l=i<0,l?(t=u,i=-i,s=f.length):(t=f,r=d,s=u.length),n=Math.max(Math.ceil(a/S),s)+2,i>n&&(i=n,t.length=1),t.reverse(),n=i;n--;)t.push(0);t.reverse()}else{for(n=u.length,s=f.length,l=n<s,l&&(s=n),n=0;n<s;n++)if(u[n]!=f[n]){l=u[n]<f[n];break}i=0}for(l&&(t=u,u=f,f=t,e.s=-e.s),s=u.length,n=f.length-s;n>0;--n)u[s++]=0;for(n=f.length;n>i;){if(u[--n]<f[n]){for(o=n;o&&u[--o]===0;)u[o]=de-1;--u[o],u[n]+=de}u[n]-=f[n]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--r;return u[0]?(e.d=u,e.e=dt(u,r),B?I(e,a,c):e):new h(c===3?-0:0)};b.modulo=b.mod=function(e){var t,r=this,n=r.constructor;return e=new n(e),!r.d||!e.s||e.d&&!e.d[0]?new n(NaN):!e.d||r.d&&!r.d[0]?I(new n(r),n.precision,n.rounding):(B=!1,n.modulo==9?(t=q(r,e.abs(),0,3,1),t.s*=e.s):t=q(r,e,0,n.modulo,1),t=t.times(e),B=!0,r.minus(t))};b.naturalExponential=b.exp=function(){return Nt(this)};b.naturalLogarithm=b.ln=function(){return ke(this)};b.negated=b.neg=function(){var e=new this.constructor(this);return e.s=-e.s,I(e)};b.plus=b.add=function(e){var t,r,n,o,i,s,a,c,u,d,l=this,f=l.constructor;if(e=new f(e),!l.d||!e.d)return!l.s||!e.s?e=new f(NaN):l.d||(e=new f(e.d||l.s===e.s?l:NaN)),e;if(l.s!=e.s)return e.s=-e.s,l.minus(e);if(u=l.d,d=e.d,a=f.precision,c=f.rounding,!u[0]||!d[0])return d[0]||(e=new f(l)),B?I(e,a,c):e;if(i=ie(l.e/S),n=ie(e.e/S),u=u.slice(),o=i-n,o){for(o<0?(r=u,o=-o,s=d.length):(r=d,n=i,s=u.length),i=Math.ceil(a/S),s=i>s?i+1:s+1,o>s&&(o=s,r.length=1),r.reverse();o--;)r.push(0);r.reverse()}for(s=u.length,o=d.length,s-o<0&&(o=s,r=d,d=u,u=r),t=0;o;)t=(u[--o]=u[o]+d[o]+t)/de|0,u[o]%=de;for(t&&(u.unshift(t),++n),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=dt(u,n),B?I(e,a,c):e};b.precision=b.sd=function(e){var t,r=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(Ae+e);return r.d?(t=Mr(r.d),e&&r.e+1>t&&(t=r.e+1)):t=NaN,t};b.round=function(){var e=this,t=e.constructor;return I(new t(e),e.e+1,t.rounding)};b.sine=b.sin=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+S,n.rounding=1,r=Yn(n,Or(n,r)),n.precision=e,n.rounding=t,I(ye>2?r.neg():r,e,t,!0)):new n(NaN)};b.squareRoot=b.sqrt=function(){var e,t,r,n,o,i,s=this,a=s.d,c=s.e,u=s.s,d=s.constructor;if(u!==1||!a||!a[0])return new d(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(B=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=oe(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=ie((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),n=new d(t)):n=new d(u.toString()),r=(c=d.precision)+3;;)if(i=n,n=i.plus(q(s,i,r+2,1)).times(.5),oe(i.d).slice(0,r)===(t=oe(n.d)).slice(0,r))if(t=t.slice(r-3,r+1),t=="9999"||!o&&t=="4999"){if(!o&&(I(i,c+1,0),i.times(i).eq(s))){n=i;break}r+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(I(n,c+1,1),e=!n.times(n).eq(s));break}return B=!0,I(n,c,d.rounding,e)};b.tangent=b.tan=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+10,n.rounding=1,r=r.sin(),r.s=1,r=q(r,new n(1).minus(r.times(r)).sqrt(),e+10,0),n.precision=e,n.rounding=t,I(ye==2||ye==4?r.neg():r,e,t,!0)):new n(NaN)};b.times=b.mul=function(e){var t,r,n,o,i,s,a,c,u,d=this,l=d.constructor,f=d.d,p=(e=new l(e)).d;if(e.s*=d.s,!f||!f[0]||!p||!p[0])return new l(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(r=ie(d.e/S)+ie(e.e/S),c=f.length,u=p.length,c<u&&(i=f,f=p,p=i,s=c,c=u,u=s),i=[],s=c+u,n=s;n--;)i.push(0);for(n=u;--n>=0;){for(t=0,o=c+n;o>n;)a=i[o]+p[n]*f[o-n-1]+t,i[o--]=a%de|0,t=a/de|0;i[o]=(i[o]+t)%de|0}for(;!i[--s];)i.pop();return t?++r:i.shift(),e.d=i,e.e=dt(i,r),B?I(e,l.precision,l.rounding):e};b.toBinary=function(e,t){return Mt(this,2,e,t)};b.toDecimalPlaces=b.toDP=function(e,t){var r=this,n=r.constructor;return r=new n(r),e===void 0?r:(ae(e,0,Ie),t===void 0?t=n.rounding:ae(t,0,8),I(r,e+r.e+1,t))};b.toExponential=function(e,t){var r,n=this,o=n.constructor;return e===void 0?r=me(n,!0):(ae(e,0,Ie),t===void 0?t=o.rounding:ae(t,0,8),n=I(new o(n),e+1,t),r=me(n,!0,e+1)),n.isNeg()&&!n.isZero()?"-"+r:r};b.toFixed=function(e,t){var r,n,o=this,i=o.constructor;return e===void 0?r=me(o):(ae(e,0,Ie),t===void 0?t=i.rounding:ae(t,0,8),n=I(new i(o),e+o.e+1,t),r=me(n,!1,e+n.e+1)),o.isNeg()&&!o.isZero()?"-"+r:r};b.toFraction=function(e){var t,r,n,o,i,s,a,c,u,d,l,f,p=this,h=p.d,m=p.constructor;if(!h)return new m(p);if(u=r=new m(1),n=c=new m(0),t=new m(n),i=t.e=Mr(h)-p.e-1,s=i%S,t.d[0]=te(10,s<0?S+s:s),e==null)e=i>0?t:u;else{if(a=new m(e),!a.isInt()||a.lt(u))throw Error(Ae+a);e=a.gt(t)?i>0?t:u:a}for(B=!1,a=new m(oe(h)),d=m.precision,m.precision=i=h.length*S*2;l=q(a,t,0,1,1),o=r.plus(l.times(n)),o.cmp(e)!=1;)r=n,n=o,o=u,u=c.plus(l.times(o)),c=o,o=t,t=a.minus(l.times(o)),a=o;return o=q(e.minus(r),n,0,1,1),c=c.plus(o.times(u)),r=r.plus(o.times(n)),c.s=u.s=p.s,f=q(u,n,i,1).minus(p).abs().cmp(q(c,r,i,1).minus(p).abs())<1?[u,n]:[c,r],m.precision=d,B=!0,f};b.toHexadecimal=b.toHex=function(e,t){return Mt(this,16,e,t)};b.toNearest=function(e,t){var r=this,n=r.constructor;if(r=new n(r),e==null){if(!r.d)return r;e=new n(1),t=n.rounding}else{if(e=new n(e),t===void 0?t=n.rounding:ae(t,0,8),!r.d)return e.s?r:e;if(!e.d)return e.s&&(e.s=r.s),e}return e.d[0]?(B=!1,r=q(r,e,0,t,1).times(e),B=!0,I(r)):(e.s=r.s,r=e),r};b.toNumber=function(){return+this};b.toOctal=function(e,t){return Mt(this,8,e,t)};b.toPower=b.pow=function(e){var t,r,n,o,i,s,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(te(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,i=c.rounding,e.eq(1))return I(a,n,i);if(t=ie(e.e/S),t>=e.d.length-1&&(r=u<0?-u:u)<=qn)return o=vr(c,a,r,n),e.s<0?new c(1).div(o):I(o,n,i);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return r=te(+a,u),t=r==0||!isFinite(r)?ie(u*(Math.log("0."+oe(a.d))/Math.LN10+a.e+1)):new c(r+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(B=!1,c.rounding=a.s=1,r=Math.min(12,(t+"").length),o=Nt(e.times(ke(a,n+r)),n),o.d&&(o=I(o,n+5,1),We(o.d,n,i)&&(t=n+10,o=I(Nt(e.times(ke(a,t+r)),t),t+5,1),+oe(o.d).slice(n+1,n+15)+1==1e14&&(o=I(o,n+1,0)))),o.s=s,B=!0,c.rounding=i,I(o,n,i))};b.toPrecision=function(e,t){var r,n=this,o=n.constructor;return e===void 0?r=me(n,n.e<=o.toExpNeg||n.e>=o.toExpPos):(ae(e,1,Ie),t===void 0?t=o.rounding:ae(t,0,8),n=I(new o(n),e,t),r=me(n,e<=n.e||n.e<=o.toExpNeg,e)),n.isNeg()&&!n.isZero()?"-"+r:r};b.toSignificantDigits=b.toSD=function(e,t){var r=this,n=r.constructor;return e===void 0?(e=n.precision,t=n.rounding):(ae(e,1,Ie),t===void 0?t=n.rounding:ae(t,0,8)),I(new n(r),e,t)};b.toString=function(){var e=this,t=e.constructor,r=me(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+r:r};b.truncated=b.trunc=function(){return I(new this.constructor(this),this.e+1,1)};b.valueOf=b.toJSON=function(){var e=this,t=e.constructor,r=me(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+r:r};function oe(e){var t,r,n,o=e.length-1,i="",s=e[0];if(o>0){for(i+=s,t=1;t<o;t++)n=e[t]+"",r=S-n.length,r&&(i+=Te(r)),i+=n;s=e[t],n=s+"",r=S-n.length,r&&(i+=Te(r))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function ae(e,t,r){if(e!==~~e||e<t||e>r)throw Error(Ae+e)}function We(e,t,r,n){var o,i,s,a;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=S,o=0):(o=Math.ceil((t+1)/S),t%=S),i=te(10,S-t),a=e[o]%i|0,n==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=r<4&&a==99999||r>3&&a==49999||a==5e4||a==0):s=(r<4&&a+1==i||r>3&&a+1==i/2)&&(e[o+1]/i/100|0)==te(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=(n||r<4)&&a==9999||!n&&r>3&&a==4999):s=((n||r<4)&&a+1==i||!n&&r>3&&a+1==i/2)&&(e[o+1]/i/1e3|0)==te(10,t-3)-1,s}function st(e,t,r){for(var n,o=[0],i,s=0,a=e.length;s<a;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=Ct.indexOf(e.charAt(s++)),n=0;n<o.length;n++)o[n]>r-1&&(o[n+1]===void 0&&(o[n+1]=0),o[n+1]+=o[n]/r|0,o[n]%=r)}return o.reverse()}function Hn(e,t){var r,n,o;if(t.isZero())return t;n=t.d.length,n<32?(r=Math.ceil(n/3),o=(1/ft(4,r)).toString()):(r=16,o="2.3283064365386962890625e-10"),e.precision+=r,t=Me(e,1,t.times(o),new e(1));for(var i=r;i--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=r,t}var q=function(){function e(n,o,i){var s,a=0,c=n.length;for(n=n.slice();c--;)s=n[c]*o+a,n[c]=s%i|0,a=s/i|0;return a&&n.unshift(a),n}function t(n,o,i,s){var a,c;if(i!=s)c=i>s?1:-1;else for(a=c=0;a<i;a++)if(n[a]!=o[a]){c=n[a]>o[a]?1:-1;break}return c}function r(n,o,i,s){for(var a=0;i--;)n[i]-=a,a=n[i]<o[i]?1:0,n[i]=a*s+n[i]-o[i];for(;!n[0]&&n.length>1;)n.shift()}return function(n,o,i,s,a,c){var u,d,l,f,p,h,m,T,g,x,y,A,k,C,M,D,L,E,O,z,V=n.constructor,ne=n.s==o.s?1:-1,J=n.d,W=o.d;if(!J||!J[0]||!W||!W[0])return new V(!n.s||!o.s||(J?W&&J[0]==W[0]:!W)?NaN:J&&J[0]==0||!W?ne*0:ne/0);for(c?(p=1,d=n.e-o.e):(c=de,p=S,d=ie(n.e/p)-ie(o.e/p)),O=W.length,L=J.length,g=new V(ne),x=g.d=[],l=0;W[l]==(J[l]||0);l++);if(W[l]>(J[l]||0)&&d--,i==null?(C=i=V.precision,s=V.rounding):a?C=i+(n.e-o.e)+1:C=i,C<0)x.push(1),h=!0;else{if(C=C/p+2|0,l=0,O==1){for(f=0,W=W[0],C++;(l<L||f)&&C--;l++)M=f*c+(J[l]||0),x[l]=M/W|0,f=M%W|0;h=f||l<L}else{for(f=c/(W[0]+1)|0,f>1&&(W=e(W,f,c),J=e(J,f,c),O=W.length,L=J.length),D=O,y=J.slice(0,O),A=y.length;A<O;)y[A++]=0;z=W.slice(),z.unshift(0),E=W[0],W[1]>=c/2&&++E;do f=0,u=t(W,y,O,A),u<0?(k=y[0],O!=A&&(k=k*c+(y[1]||0)),f=k/E|0,f>1?(f>=c&&(f=c-1),m=e(W,f,c),T=m.length,A=y.length,u=t(m,y,T,A),u==1&&(f--,r(m,O<T?z:W,T,c))):(f==0&&(u=f=1),m=W.slice()),T=m.length,T<A&&m.unshift(0),r(y,m,A,c),u==-1&&(A=y.length,u=t(W,y,O,A),u<1&&(f++,r(y,O<A?z:W,A,c))),A=y.length):u===0&&(f++,y=[0]),x[l++]=f,u&&y[0]?y[A++]=J[D]||0:(y=[J[D]],A=1);while((D++<L||y[0]!==void 0)&&C--);h=y[0]!==void 0}x[0]||x.shift()}if(p==1)g.e=d,Cr=h;else{for(l=1,f=x[0];f>=10;f/=10)l++;g.e=l+d*p-1,I(g,a?i+g.e+1:i,s,h)}return g}}();function I(e,t,r,n){var o,i,s,a,c,u,d,l,f,p=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+=S,s=t,d=l[f=0],c=d/te(10,o-s-1)%10|0;else if(f=Math.ceil((i+1)/S),a=l.length,f>=a)if(n){for(;a++<=f;)l.push(0);d=c=0,o=1,i%=S,s=i-S+1}else break e;else{for(d=a=l[f],o=1;a>=10;a/=10)o++;i%=S,s=i-S+o,c=s<0?0:d/te(10,o-s-1)%10|0}if(n=n||t<0||l[f+1]!==void 0||(s<0?d:d%te(10,o-s-1)),u=r<4?(c||n)&&(r==0||r==(e.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(i>0?s>0?d/te(10,o-s):0:l[f-1])%10&1||r==(e.s<0?8:7)),t<1||!l[0])return l.length=0,u?(t-=e.e+1,l[0]=te(10,(S-t%S)%S),e.e=-t||0):l[0]=e.e=0,e;if(i==0?(l.length=f,a=1,f--):(l.length=f+1,a=te(10,S-i),l[f]=s>0?(d/te(10,o-s)%te(10,s)|0)*a:0),u)for(;;)if(f==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]==de&&(l[0]=1));break}else{if(l[f]+=a,l[f]!=de)break;l[f--]=0,a=1}for(i=l.length;l[--i]===0;)l.pop()}return B&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function me(e,t,r){if(!e.isFinite())return Dr(e);var n,o=e.e,i=oe(e.d),s=i.length;return t?(r&&(n=r-s)>0?i=i.charAt(0)+"."+i.slice(1)+Te(n):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+Te(-o-1)+i,r&&(n=r-s)>0&&(i+=Te(n))):o>=s?(i+=Te(o+1-s),r&&(n=r-o-1)>0&&(i=i+"."+Te(n))):((n=o+1)<s&&(i=i.slice(0,n)+"."+i.slice(n)),r&&(n=r-s)>0&&(o+1===s&&(i+="."),i+=Te(n))),i}function dt(e,t){var r=e[0];for(t*=S;r>=10;r/=10)t++;return t}function ct(e,t,r){if(t>Gn)throw B=!0,r&&(e.precision=r),Error(Vr);return I(new e(at),t,1,!0)}function le(e,t,r){if(t>Ft)throw Error(Vr);return I(new e(ut),t,r,!0)}function Mr(e){var t=e.length-1,r=t*S+1;if(t=e[t],t){for(;t%10==0;t/=10)r--;for(t=e[0];t>=10;t/=10)r++}return r}function Te(e){for(var t="";e--;)t+="0";return t}function vr(e,t,r,n){var o,i=new e(1),s=Math.ceil(n/S+4);for(B=!1;;){if(r%2&&(i=i.times(t),Rr(i.d,s)&&(o=!0)),r=ie(r/2),r===0){r=i.d.length-1,o&&i.d[r]===0&&++i.d[r];break}t=t.times(t),Rr(t.d,s)}return B=!0,i}function Br(e){return e.d[e.d.length-1]&1}function _r(e,t,r){for(var n,o=new e(t[0]),i=0;++i<t.length;)if(n=new e(t[i]),n.s)o[r](n)&&(o=n);else{o=n;break}return o}function Nt(e,t){var r,n,o,i,s,a,c,u=0,d=0,l=0,f=e.constructor,p=f.rounding,h=f.precision;if(!e.d||!e.d[0]||e.e>17)return new f(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,c=h):c=t,a=new f(.03125);e.e>-2;)e=e.times(a),l+=5;for(n=Math.log(te(2,l))/Math.LN10*2+5|0,c+=n,r=i=s=new f(1),f.precision=c;;){if(i=I(i.times(e),c,1),r=r.times(++d),a=s.plus(q(i,r,c,1)),oe(a.d).slice(0,c)===oe(s.d).slice(0,c)){for(o=l;o--;)s=I(s.times(s),c,1);if(t==null)if(u<3&&We(s.d,c-n,p,u))f.precision=c+=10,r=i=a=new f(1),d=0,u++;else return I(s,f.precision=h,p,B=!0);else return f.precision=h,s}s=a}}function ke(e,t){var r,n,o,i,s,a,c,u,d,l,f,p=1,h=10,m=e,T=m.d,g=m.constructor,x=g.rounding,y=g.precision;if(m.s<0||!T||!T[0]||!m.e&&T[0]==1&&T.length==1)return new g(T&&!T[0]?-1/0:m.s!=1?NaN:T?0:m);if(t==null?(B=!1,d=y):d=t,g.precision=d+=h,r=oe(T),n=r.charAt(0),Math.abs(i=m.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)m=m.times(e),r=oe(m.d),n=r.charAt(0),p++;i=m.e,n>1?(m=new g("0."+r),i++):m=new g(n+"."+r.slice(1))}else return u=ct(g,d+2,y).times(i+""),m=ke(new g(n+"."+r.slice(1)),d-h).plus(u),g.precision=y,t==null?I(m,y,x,B=!0):m;for(l=m,c=s=m=q(m.minus(1),m.plus(1),d,1),f=I(m.times(m),d,1),o=3;;){if(s=I(s.times(f),d,1),u=c.plus(q(s,new g(o),d,1)),oe(u.d).slice(0,d)===oe(c.d).slice(0,d))if(c=c.times(2),i!==0&&(c=c.plus(ct(g,d+2,y).times(i+""))),c=q(c,new g(p),d,1),t==null)if(We(c.d,d-h,x,a))g.precision=d+=h,u=s=m=q(l.minus(1),l.plus(1),d,1),f=I(m.times(m),d,1),o=a=1;else return I(c,g.precision=y,x,B=!0);else return g.precision=y,c;c=u,o+=2}}function Dr(e){return String(e.s*e.s/0)}function Et(e,t){var r,n,o;for((r=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(r<0&&(r=n),r+=+t.slice(n+1),t=t.substring(0,n)):r<0&&(r=t.length),n=0;t.charCodeAt(n)===48;n++);for(o=t.length;t.charCodeAt(o-1)===48;--o);if(t=t.slice(n,o),t){if(o-=n,e.e=r=r-n-1,e.d=[],n=(r+1)%S,r<0&&(n+=S),n<o){for(n&&e.d.push(+t.slice(0,n)),o-=S;n<o;)e.d.push(+t.slice(n,n+=S));t=t.slice(n),n=S-t.length}else n-=o;for(;n--;)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 jn(e,t){var r,n,o,i,s,a,c,u,d;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Er.test(t))return Et(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Wn.test(t))r=16,t=t.toLowerCase();else if(On.test(t))r=2;else if(Un.test(t))r=8;else throw Error(Ae+t);for(i=t.search(/p/i),i>0?(c=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,n=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=vr(n,new n(r),i,i*2)),u=st(t,r,de),d=u.length-1,i=d;u[i]===0;--i)u.pop();return i<0?new n(e.s*0):(e.e=dt(u,d),e.d=u,B=!1,s&&(e=q(e,o,a*4)),c&&(e=e.times(Math.abs(c)<54?te(2,c):Ue.pow(2,c))),B=!0,e)}function Yn(e,t){var r,n=t.d.length;if(n<3)return t.isZero()?t:Me(e,2,t,t);r=1.4*Math.sqrt(n),r=r>16?16:r|0,t=t.times(1/ft(5,r)),t=Me(e,2,t,t);for(var o,i=new e(5),s=new e(16),a=new e(20);r--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(a))));return t}function Me(e,t,r,n,o){var i,s,a,c,u=1,d=e.precision,l=Math.ceil(d/S);for(B=!1,c=r.times(r),a=new e(n);;){if(s=q(a.times(c),new e(t++*t++),d,1),a=o?n.plus(s):n.minus(s),n=q(s.times(c),new e(t++*t++),d,1),s=a.plus(n),s.d[l]!==void 0){for(i=l;s.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=n,n=s,s=i,u++}return B=!0,s.d.length=l+1,s}function ft(e,t){for(var r=e;--t;)r*=e;return r}function Or(e,t){var r,n=t.s<0,o=le(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return ye=n?4:1,t;if(r=t.divToInt(o),r.isZero())ye=n?3:2;else{if(t=t.minus(r.times(o)),t.lte(i))return ye=Br(r)?n?2:3:n?4:1,t;ye=Br(r)?n?1:4:n?3:2}return t.minus(o).abs()}function Mt(e,t,r,n){var o,i,s,a,c,u,d,l,f,p=e.constructor,h=r!==void 0;if(h?(ae(r,1,Ie),n===void 0?n=p.rounding:ae(n,0,8)):(r=p.precision,n=p.rounding),!e.isFinite())d=Dr(e);else{for(d=me(e),s=d.indexOf("."),h?(o=2,t==16?r=r*4-3:t==8&&(r=r*3-2)):o=t,s>=0&&(d=d.replace(".",""),f=new p(1),f.e=d.length-s,f.d=st(me(f),10,o),f.e=f.d.length),l=st(d,10,o),i=c=l.length;l[--c]==0;)l.pop();if(!l[0])d=h?"0p+0":"0";else{if(s<0?i--:(e=new p(e),e.d=l,e.e=i,e=q(e,f,r,n,0,o),l=e.d,i=e.e,u=Cr),s=l[r],a=o/2,u=u||l[r+1]!==void 0,u=n<4?(s!==void 0||u)&&(n===0||n===(e.s<0?3:2)):s>a||s===a&&(n===4||u||n===6&&l[r-1]&1||n===(e.s<0?8:7)),l.length=r,u)for(;++l[--r]>o-1;)l[r]=0,r||(++i,l.unshift(1));for(c=l.length;!l[c-1];--c);for(s=0,d="";s<c;s++)d+=Ct.charAt(l[s]);if(h){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)d+="0";for(l=st(d,o,t),c=l.length;!l[c-1];--c);for(s=1,d="1.";s<c;s++)d+=Ct.charAt(l[s])}else d=d.charAt(0)+"."+d.slice(1);d=d+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)d="0"+d;d="0."+d}else if(++i>c)for(i-=c;i--;)d+="0";else i<c&&(d=d.slice(0,i)+"."+d.slice(i))}d=(t==16?"0x":t==2?"0b":t==8?"0o":"")+d}return e.s<0?"-"+d:d}function Rr(e,t){if(e.length>t)return e.length=t,!0}function zn(e){return new this(e).abs()}function Zn(e){return new this(e).acos()}function Xn(e){return new this(e).acosh()}function Jn(e,t){return new this(e).plus(t)}function Qn(e){return new this(e).asin()}function $n(e){return new this(e).asinh()}function eo(e){return new this(e).atan()}function to(e){return new this(e).atanh()}function ro(e,t){e=new this(e),t=new this(t);var r,n=this.precision,o=this.rounding,i=n+4;return!e.s||!t.s?r=new this(NaN):!e.d&&!t.d?(r=le(this,i,1).times(t.s>0?.25:.75),r.s=e.s):!t.d||e.isZero()?(r=t.s<0?le(this,n,o):new this(0),r.s=e.s):!e.d||t.isZero()?(r=le(this,i,1).times(.5),r.s=e.s):t.s<0?(this.precision=i,this.rounding=1,r=this.atan(q(e,t,i,1)),t=le(this,i,1),this.precision=n,this.rounding=o,r=e.s<0?r.minus(t):r.plus(t)):r=this.atan(q(e,t,i,1)),r}function no(e){return new this(e).cbrt()}function oo(e){return I(e=new this(e),e.e+1,2)}function io(e,t,r){return new this(e).clamp(t,r)}function so(e){if(!e||typeof e!="object")throw Error(lt+"Object expected");var t,r,n,o=e.defaults===!0,i=["precision",1,Ie,"rounding",0,8,"toExpNeg",-Ee,0,"toExpPos",0,Ee,"maxE",0,Ee,"minE",-Ee,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(r=i[t],o&&(this[r]=Vt[r]),(n=e[r])!==void 0)if(ie(n)===n&&n>=i[t+1]&&n<=i[t+2])this[r]=n;else throw Error(Ae+r+": "+n);if(r="crypto",o&&(this[r]=Vt[r]),(n=e[r])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(Fr);else this[r]=!1;else throw Error(Ae+r+": "+n);return this}function ao(e){return new this(e).cos()}function uo(e){return new this(e).cosh()}function Wr(e){var t,r,n;function o(i){var s,a,c,u=this;if(!(u instanceof o))return new o(i);if(u.constructor=o,Kr(i)){u.s=i.s,B?!i.d||i.e>o.maxE?(u.e=NaN,u.d=null):i.e<o.minE?(u.e=0,u.d=[0]):(u.e=i.e,u.d=i.d.slice()):(u.e=i.e,u.d=i.d?i.d.slice():i.d);return}if(c=typeof i,c==="number"){if(i===0){u.s=1/i<0?-1:1,u.e=0,u.d=[0];return}if(i<0?(i=-i,u.s=-1):u.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;B?s>o.maxE?(u.e=NaN,u.d=null):s<o.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[i]):(u.e=s,u.d=[i]);return}else if(i*0!==0){i||(u.s=NaN),u.e=NaN,u.d=null;return}return Et(u,i.toString())}else if(c!=="string")throw Error(Ae+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),u.s=-1):(a===43&&(i=i.slice(1)),u.s=1),Er.test(i)?Et(u,i):jn(u,i)}if(o.prototype=b,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=so,o.clone=Wr,o.isDecimal=Kr,o.abs=zn,o.acos=Zn,o.acosh=Xn,o.add=Jn,o.asin=Qn,o.asinh=$n,o.atan=eo,o.atanh=to,o.atan2=ro,o.cbrt=no,o.ceil=oo,o.clamp=io,o.cos=ao,o.cosh=uo,o.div=co,o.exp=lo,o.floor=fo,o.hypot=po,o.ln=mo,o.log=go,o.log10=ho,o.log2=yo,o.max=bo,o.min=wo,o.mod=xo,o.mul=Po,o.pow=To,o.random=ko,o.round=Ao,o.sign=Io,o.sin=So,o.sinh=Lo,o.sqrt=Bo,o.sub=Ro,o.sum=Ko,o.tan=Co,o.tanh=Vo,o.trunc=Fo,e===void 0&&(e={}),e&&e.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<n.length;)e.hasOwnProperty(r=n[t++])||(e[r]=this[r]);return o.config(e),o}function co(e,t){return new this(e).div(t)}function lo(e){return new this(e).exp()}function fo(e){return I(e=new this(e),e.e+1,3)}function po(){var e,t,r=new this(0);for(B=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)r.d&&(r=r.plus(t.times(t)));else{if(t.s)return B=!0,new this(1/0);r=t}return B=!0,r.sqrt()}function Kr(e){return e instanceof Ue||e&&e.toStringTag===Nr||!1}function mo(e){return new this(e).ln()}function go(e,t){return new this(e).log(t)}function yo(e){return new this(e).log(2)}function ho(e){return new this(e).log(10)}function bo(){return _r(this,arguments,"lt")}function wo(){return _r(this,arguments,"gt")}function xo(e,t){return new this(e).mod(t)}function Po(e,t){return new this(e).mul(t)}function To(e,t){return new this(e).pow(t)}function ko(e){var t,r,n,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:ae(e,1,Ie),n=Math.ceil(e/S),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));i<n;)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(n*=4);i<n;)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=n/4}else throw Error(Fr);else for(;i<n;)a[i++]=Math.random()*1e7|0;for(n=a[--i],e%=S,n&&e&&(o=te(10,S-e),a[i]=(n/o|0)*o);a[i]===0;i--)a.pop();if(i<0)r=0,a=[0];else{for(r=-1;a[0]===0;r-=S)a.shift();for(n=1,o=a[0];o>=10;o/=10)n++;n<S&&(r-=S-n)}return s.e=r,s.d=a,s}function Ao(e){return I(e=new this(e),e.e+1,this.rounding)}function Io(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function So(e){return new this(e).sin()}function Lo(e){return new this(e).sinh()}function Bo(e){return new this(e).sqrt()}function Ro(e,t){return new this(e).sub(t)}function Ko(){var e=0,t=arguments,r=new this(t[e]);for(B=!1;r.s&&++e<t.length;)r=r.plus(t[e]);return B=!0,I(r,this.precision,this.rounding)}function Co(e){return new this(e).tan()}function Vo(e){return new this(e).tanh()}function Fo(e){return I(e=new this(e),e.e+1,1)}b[Symbol.for("nodejs.util.inspect.custom")]=b.toString;b[Symbol.toStringTag]="Decimal";var Ue=b.constructor=Wr(Vt);at=new Ue(at);ut=new Ue(ut);var vt=Ue;import{PublicKey as Ot}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as No}from"@solana/spl-token";import{PublicKey as Z,SystemProgram as Ur,SYSVAR_RENT_PUBKEY as Eo}from"@solana/web3.js";function w({pubkey:e,isSigner:t=!1,isWritable:r=!0}){return{pubkey:e,isWritable:r,isSigner:t}}var _t=[w({pubkey:No,isWritable:!1}),w({pubkey:Ur.programId,isWritable:!1}),w({pubkey:Eo,isWritable:!1})];function qr({publicKey:e,transformSol:t}){let r=Dt(e.toString());if(r instanceof Z)return t&&r.equals(re)?Se:r;if(t&&r.toString()===re.toBase58())return Se;if(typeof r=="string"){if(r===Z.default.toBase58())return Z.default;try{return new Z(r)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Dt(e){try{return new Z(e)}catch{return e}}var cs=new Z("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ls=new Z("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Mo=new Z("SysvarRent111111111111111111111111111111111"),ds=new Z("SysvarC1ock11111111111111111111111111111111"),fs=new Z("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),vo=new Z("Sysvar1nstructions1111111111111111111111111"),ps=Ur.programId,ms=new Z("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),gs=new Z("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),ys=new Z("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),hs=new Z("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),bs=new Z("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),ws=new Z("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),xs=new Z("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Ps=new Z("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ts=new Z("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),ks=new Z("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),As=new Z("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Se=new Z("So11111111111111111111111111111111111111112"),re=Z.default;import{PublicKey as _o}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Gr}from"@solana/spl-token";var Hr={chainId:101,address:_o.default.toBase58(),programId:Gr.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},se={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Gr.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 Wt=class{constructor({mint:t,decimals:r,symbol:n,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===re.toBase58()||t instanceof Ot&&re.equals(t)){this.decimals=se.decimals,this.symbol=se.symbol,this.name=se.name,this.mint=new Ot(se.address),this.isToken2022=!1;return}this.decimals=r,this.symbol=n||t.toString().substring(0,6),this.name=o||t.toString().substring(0,6),this.mint=i?Ot.default:qr({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},Ce=Wt;Ce.WSOL=new Wt(ee(H({},se),{mint:se.address}));import mt from"big.js";import Wo from"bn.js";import Uo from"decimal.js-light";import Do from"toformat";var Oo=Do,qe=Oo;var pt=Q("module/fraction"),Ut=qe(mt),Ge=qe(Uo),qo={[0]:Ge.ROUND_DOWN,[1]:Ge.ROUND_HALF_UP,[2]:Ge.ROUND_UP},Go={[0]:mt.roundDown,[1]:mt.roundHalfUp,[2]:mt.roundUp},U=class{constructor(t,r=new Wo(1)){this.numerator=F(t),this.denominator=F(r)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new U(this.denominator,this.numerator)}add(t){let r=t instanceof U?t:new U(F(t));return this.denominator.eq(r.denominator)?new U(this.numerator.add(r.numerator),this.denominator):new U(this.numerator.mul(r.denominator).add(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}sub(t){let r=t instanceof U?t:new U(F(t));return this.denominator.eq(r.denominator)?new U(this.numerator.sub(r.numerator),this.denominator):new U(this.numerator.mul(r.denominator).sub(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}mul(t){let r=t instanceof U?t:new U(F(t));return new U(this.numerator.mul(r.numerator),this.denominator.mul(r.denominator))}div(t){let r=t instanceof U?t:new U(F(t));return new U(this.numerator.mul(r.denominator),this.denominator.mul(r.numerator))}toSignificant(t,r={groupSeparator:""},n=1){Number.isInteger(t)||pt.logWithError(`${t} is not an integer.`),t<=0&&pt.logWithError(`${t} is not positive.`),Ge.set({precision:t+1,rounding:qo[n]});let o=new Ge(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),r)}toFixed(t,r={groupSeparator:""},n=1){return Number.isInteger(t)||pt.logWithError(`${t} is not an integer.`),t<0&&pt.logWithError(`${t} is negative.`),Ut.DP=t,Ut.RM=Go[n]||1,new Ut(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)}isZero(){return this.numerator.isZero()}};var jo=Q("Raydium_price"),he=class extends U{constructor(r){let{baseToken:n,quoteToken:o,numerator:i,denominator:s}=r;super(i,s);this.baseToken=n,this.quoteToken=o,this.scalar=new U(qt(n.decimals),qt(o.decimals))}get raw(){return new U(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new he({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numerator,numerator:this.denominator})}mul(r){this.quoteToken!==r.baseToken&&jo.logWithError("mul token not equals");let n=super.mul(r);return new he({baseToken:this.baseToken,quoteToken:r.quoteToken,denominator:n.denominator,numerator:n.numerator})}toSignificant(r=this.quoteToken.decimals,n,o){return this.adjusted.toSignificant(r,n,o)}toFixed(r=this.quoteToken.decimals,n,o){return this.adjusted.toFixed(r,n,o)}};var Gt=class{constructor({decimals:t,symbol:r="UNKNOWN",name:n="UNKNOWN"}){this.decimals=t,this.symbol=r,this.name=n}equals(t){return this===t}},gt=Gt;gt.SOL=new Gt(Hr);import Yo from"bn.js";var jr=new U(new Yo(100)),ve=class extends U{toSignificant(t=5,r,n){return this.mul(jr).toSignificant(t,r,n)}toFixed(t=2,r,n){return this.mul(jr).toFixed(t,r,n)}};var Ht=new ue(0),xa=new ue(1),Pa=new ue(2),Ta=new ue(3),ka=new ue(5),jt=new ue(10),Aa=new ue(100),Ia=new ue(1e3),Sa=new ue(1e4),Yr=9007199254740991;function F(e){let t=Q("Raydium_parseBigNumberish");if(e instanceof ue)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new ue(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=Yr||e<=-Yr)&&t.logWithError(`BigNumberish number overflow: ${e}`),new ue(String(e))):typeof e=="bigint"?new ue(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new ue(0))}function qt(e){return jt.pow(F(e))}var Zo=Q("Raydium_amount"),Zr=qe(zo);function Xo(e,t){let r="0",n="0";if(e.includes(".")){let o=e.split(".");o.length===2?([r,n]=o,n=n.padEnd(t,"0")):Zo.logWithError(`invalid number string, num: ${e}`)}else r=e;return[r,n.slice(0,t)||n]}var be=class extends U{constructor(r,n,o=!0,i){let s=new yt(0),a=jt.pow(new yt(r.decimals));if(o)s=F(n);else{let c=new yt(0),u=new yt(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[d,l]=Xo(n.toString(),r.decimals);c=F(d),u=F(l)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=Q(i||"TokenAmount"),this.token=r}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(r){return this.token.equals(r.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(r.raw)}lt(r){return this.token.equals(r.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(r.raw)}add(r){return this.token.equals(r.token)||this.logger.logWithError("add token not equals"),new be(this.token,this.raw.add(r.raw))}subtract(r){return this.token.equals(r.token)||this.logger.logWithError("sub token not equals"),new be(this.token,this.raw.sub(r.raw))}toSignificant(r=this.token.decimals,n,o=0){return super.toSignificant(r,n,o)}toFixed(r=this.token.decimals,n,o=0){return r>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(r,n,o)}toExact(r={groupSeparator:""}){return Zr.DP=this.token.decimals,new Zr(this.numerator.toString()).div(this.denominator.toString()).toFormat(r)}};function zr(e){return typeof e=="object"&&e!==null&&![Ce,be,Jo,U,Qo,he,ve].some(t=>typeof t=="object"&&e instanceof t)}function we(e){return typeof e=="string"?Dt(e):Array.isArray(e)?e.map(t=>we(t)):zr(e)?Object.fromEntries(Object.entries(e).map(([t,r])=>[t,we(r)])):e}import{PublicKey as Ye,sendAndConfirmTransaction as ze,Transaction as Ze,TransactionMessage as Xe,VersionedTransaction as Je}from"@solana/web3.js";import si from"axios";var j={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut"};import{PublicKey as $o,ComputeBudgetProgram as Xr,Transaction as Qr,TransactionMessage as ei,Keypair as $r,VersionedTransaction as en}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ti}from"@solana/spl-token";var Jr=Q("Raydium_txUtil"),tn=1644;function ht(e){let t=[],r=[];return e.microLamports&&(t.push(Xr.setComputeUnitPrice({microLamports:e.microLamports})),r.push(j.SetComputeUnitPrice)),e.units&&(t.push(Xr.setComputeUnitLimit({units:e.units})),r.push(j.SetComputeUnitLimit)),{instructions:t,instructionTypes:r}}async function _e(e){var t,r;try{return((r=await((t=e.getLatestBlockhash)==null?void 0:t.call(e)))==null?void 0:r.blockhash)||(await e.getRecentBlockhash()).blockhash}catch{return(await e.getRecentBlockhash()).blockhash}}function ri(e,t){e.length<1&&Jr.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&Jr.logWithError(`no signers provided:, ${t.toString()}`);let r=new Qr;r.recentBlockhash="11111111111111111111111111111111",r.feePayer=t[0],r.add(...e);try{return Buffer.from(r.serialize({verifySignatures:!1})).toString("base64").length<tn}catch{return!1}}function Ve(e,t){let[r,n]=$o.findProgramAddressSync(e,t);return{publicKey:r,nonce:n}}function He({instructions:e,payer:t,signers:r}){return ri(e,[t,...r])}function je({instructions:e,payer:t,lookupTableAddressAccount:r,recentBlockhash:n=$r.generate().publicKey.toString()}){let i=new ei({payerKey:t,recentBlockhash:n,instructions:e}).compileToV0Message(Object.values(r!=null?r:{}));try{return Buffer.from(new en(i).serialize()).toString("base64").length<tn}catch{return!1}}var ni=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);function Fe(e){let t=[];return e.forEach(r=>{r instanceof Qr&&(r.recentBlockhash||(r.recentBlockhash=ti.toBase58()),r.feePayer||(r.feePayer=$r.generate().publicKey));let n=r.serialize({requireAllSignatures:!1,verifySignatures:!1});r instanceof en&&(n=ni(n));let o=n.toString("base64");t.push(o)}),console.log("simulate tx string:",t),t}import{PublicKey as nn,AddressLookupTableAccount as bt}from"@solana/web3.js";import{PublicKey as oi}from"@solana/web3.js";import{getTransferFeeConfig as pu,unpackMint as mu}from"@solana/spl-token";var Yt=Q("Raydium_accountInfo_util");async function rn(e,t,r){let{batchRequest:n,commitment:o="confirmed"}=H({batchRequest:!1},r),i=zt(t,100),s=new Array(i.length).fill([]);if(n){let a=i.map(d=>{let l=e._buildArgs([d.map(f=>f.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:l}}),c=zt(a,10);s=(await(await Promise.all(c.map(async d=>await e._rpcBatchRequest(d)))).flat()).map(d=>(d.error&&Yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${d.error.message}`),d.result.value.map(l=>{if(l){let{data:f,executable:p,lamports:h,owner:m,rentEpoch:T}=l;return f.length!==2&&f[1]!=="base64"&&Yt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(f[0],"base64"),executable:p,lamports:h,owner:new oi(m),rentEpoch:T}}return null})))}else try{s=await Promise.all(i.map(a=>e.getMultipleAccountsInfo(a,o)))}catch(a){a instanceof Error&&Yt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${a.message}`)}return s.flat()}async function Zt({connection:e,address:t}){let r=await rn(e,[...new Set(t.map(o=>o.toString()))].map(o=>new nn(o))),n={};for(let o=0;o<t.length;o++){let i=r[o],s=t[o];if(!i)continue;let a=new bt({key:s,state:bt.deserialize(i.data)});n[s.toString()]=a,wt[s.toString()]=a}return n}var wt={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new bt({key:new nn("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:bt.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 xt=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 n;let t=(await si.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:r}=(n=t==null?void 0:t[15])!=null?n:{};if(!!r)return{units:6e5,microLamports:Math.min(Math.ceil(r*1e6/6e5),25e3)}}addCustomComputeBudget(t){if(t){let{instructions:r,instructionTypes:n}=ht(t);return this.instructions.unshift(...r),this.instructionTypes.unshift(...n),!0}return!1}async calComputeBudget({config:t,defaultIns:r}){try{let n=t||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(n))return;r&&this.instructions.unshift(...r)}catch{r&&this.instructions.unshift(...r)}}addInstruction({instructions:t=[],endInstructions:r=[],signers:n=[],instructionTypes:o=[],endInstructionTypes:i=[],lookupTableAddress:s=[]}){return this.instructions.push(...t),this.endInstructions.push(...r),this.signers.push(...n),this.instructionTypes.push(...o),this.endInstructionTypes.push(...i),this.lookupTableAddress.push(...s.filter(a=>a!==Ye.default.toString())),this}async versionBuild({txVersion:t,extInfo:r}){return t===0?await this.buildV0(H({},r||{})):this.build(r)}build(t){let r=new Ze;return this.allInstructions.length&&r.add(...this.allInstructions),r.feePayer=this.feePayer,{builder:this,transaction:r,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async n=>{var a;let{recentBlockHash:o,skipPreflight:i=!0}=n||{},s=o!=null?o:await _e(this.connection);if(r.recentBlockhash=s,this.signers.length&&r.sign(...this.signers),Fe([r]),(a=this.owner)!=null&&a.isKeyPair)return{txId:await ze(this.connection,r,this.signers.find(c=>c.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:i}),signedTx:r};if(this.signAllTransactions){let c=await this.signAllTransactions([r]);return{txId:await this.connection.sendRawTransaction(c[0].serialize(),{skipPreflight:i}),signedTx:c[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:t||{}}}buildMultiTx(t){let{extraPreBuildData:r=[],extInfo:n}=t,{transaction:o}=this.build(n),i=r.filter(u=>u.transaction.instructions.length>0),s=[o,...i.map(u=>u.transaction)],a=[this.signers,...i.map(u=>u.signers)],c=[...this.instructionTypes,...i.map(u=>u.instructionTypes).flat()];return{builder:this,transactions:s,signers:a,instructionTypes:c,execute:async u=>{var m;let{sequentially:d,onTxUpdate:l,recentBlockHash:f,skipPreflight:p=!0}=u||{},h=f!=null?f:await _e(this.connection);if((m=this.owner)!=null&&m.isKeyPair){if(d){let T=[];for(let g of s){let x=await ze(this.connection,g,this.signers.find(y=>y.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:p});T.push(x)}return{txIds:T,signedTxs:s}}return{txIds:await await Promise.all(s.map(async(T,g)=>(T.recentBlockhash=h,await ze(this.connection,T,a[g].find(x=>x.publicKey.equals(this.owner.publicKey))?a[g]:[...a[g],this.owner.signer],{skipPreflight:p})))),signedTxs:s}}if(this.signAllTransactions){let T=s.map((x,y)=>(x.recentBlockhash=h,a[y].length&&x.sign(...a[y]),x));Fe(T);let g=await this.signAllTransactions(T);if(d){let x=0,y=[],A=async()=>{if(!g[x])return;let k=await this.connection.sendRawTransaction(g[x].serialize(),{skipPreflight:p});y.push({txId:k,status:"sent",signedTx:g[x]}),l==null||l([...y]),x++,this.connection.onSignature(k,C=>{let M=y.findIndex(D=>D.txId===k);M>-1&&(y[M].status=C.err?"error":"success"),l==null||l([...y]),C.err||A()},"processed"),this.connection.getSignatureStatus(k)};return await A(),{txIds:y.map(k=>k.txId),signedTxs:g}}else{let x=[];for(let y=0;y<g.length;y+=1){let A=await this.connection.sendRawTransaction(g[y].serialize(),{skipPreflight:p});x.push(A)}return{txIds:x,signedTxs:g}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:n||{}}}async versionMultiBuild({extraPreBuildData:t,txVersion:r,extInfo:n}){return r===0?await this.buildV0MultiTx({extraPreBuildData:t,buildProps:n||{}}):this.buildMultiTx({extraPreBuildData:t,extInfo:n})}async buildV0(t){let f=t||{},{lookupTableCache:r={},lookupTableAddress:n=[],forerunCreate:o}=f,i=it(f,["lookupTableCache","lookupTableAddress","forerunCreate"]),s=H(H({},this.cluster==="devnet"?{}:wt),r),a=Array.from(new Set([...n,...this.lookupTableAddress])),c=[];for(let p of a)s[p]===void 0&&c.push(new Ye(p));let u=await Zt({connection:this.connection,address:c});for(let[p,h]of Object.entries(u))s[p]=h;let d=new Xe({payerKey:this.feePayer,recentBlockhash:o?Ye.default.toBase58():await _e(this.connection),instructions:[...this.allInstructions]}).compileToV0Message(Object.values(s)),l=new Je(d);return l.sign(this.signers),{builder:this,transaction:l,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async p=>{var T;let{recentBlockHash:h,skipPreflight:m=!0}=p||{};if(h&&(l.message.recentBlockhash=h),Fe([l]),(T=this.owner)!=null&&T.isKeyPair){this.signers.find(A=>A.publicKey.equals(this.owner.publicKey))||l.sign([this.owner.signer]);let g=await this.connection.sendTransaction(l,{skipPreflight:m}),{lastValidBlockHeight:x,blockhash:y}=await this.connection.getLatestBlockhash();return await this.connection.confirmTransaction({blockhash:y,lastValidBlockHeight:x,signature:g},"confirmed"),{txId:g,signedTx:l}}if(this.signAllTransactions){let g=await this.signAllTransactions([l]);return{txId:await this.connection.sendTransaction(g[0],{skipPreflight:m}),signedTx:g[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}async buildV0MultiTx(t){let{extraPreBuildData:r=[],buildProps:n}=t,{transaction:o}=await this.buildV0(n),i=r.filter(u=>u.builder.instructions.length>0),s=[o,...i.map(u=>u.transaction)],a=[this.signers,...i.map(u=>u.signers)],c=[...this.instructionTypes,...i.map(u=>u.instructionTypes).flat()];return s.forEach(async(u,d)=>{u.sign(a[d])}),{builder:this,transactions:s,signers:a,instructionTypes:c,buildProps:n,execute:async u=>{var h;let{sequentially:d,onTxUpdate:l,recentBlockHash:f,skipPreflight:p=!0}=u||{};if(f&&s.forEach(m=>m.message.recentBlockhash=f),Fe(s),(h=this.owner)!=null&&h.isKeyPair){let{lastValidBlockHeight:m,blockhash:T}=await this.connection.getLatestBlockhash();if(s.forEach((g,x)=>{a[x].find(y=>y.publicKey.equals(this.owner.publicKey))||g.sign([this.owner.signer])}),d){let g=[];for(let x of s){let y=await this.connection.sendTransaction(x,{skipPreflight:p}),{lastValidBlockHeight:A,blockhash:k}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:k,lastValidBlockHeight:A,signature:y},"confirmed"),g.push(y)}return{txIds:g,signedTxs:s}}return{txIds:await Promise.all(s.map(async g=>{let x=await this.connection.sendTransaction(g,{skipPreflight:p});return await this.connection.confirmTransaction({blockhash:T,lastValidBlockHeight:m,signature:x},"confirmed"),x})),signedTxs:s}}if(this.signAllTransactions){let m=await this.signAllTransactions(s);if(d){let T=0,g=[],x=async()=>{if(!m[T])return;let y=await this.connection.sendTransaction(m[T],{skipPreflight:p});g.push({txId:y,status:"sent",signedTx:m[T]}),l==null||l([...g]),T++,this.connection.onSignature(y,A=>{let k=g.findIndex(C=>C.txId===y);k>-1&&(g[k].status=A.err?"error":"success"),l==null||l([...g]),A.err||x()},"processed"),this.connection.getSignatureStatus(y)};return x(),{txIds:[],signedTxs:m}}else{let T=[];for(let g=0;g<m.length;g+=1){let x=await this.connection.sendTransaction(m[g],{skipPreflight:p});T.push(x)}return{txIds:T,signedTxs:m}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:n||{}}}async sizeCheckBuild(t){let u=t||{},{computeBudgetConfig:r}=u,n=it(u,["computeBudgetConfig"]),o=r?ht(r):{instructions:[],instructionTypes:[]},i=this.signers.reduce((d,l)=>ee(H({},d),{[l.publicKey.toBase58()]:l}),{}),s=[],a=[],c=[];if(this.allInstructions.forEach(d=>{let l=[...c,d],f=r?[...o.instructions,...l]:l,h=[...new Set(l.map(m=>m.keys.filter(T=>T.isSigner).map(T=>T.pubkey.toString())).flat()).values()].map(m=>new Ye(m));if(c.length<12&&He({instructions:f,payer:this.feePayer,signers:h})||He({instructions:l,payer:this.feePayer,signers:h}))c.push(d);else{if(c.length===0)throw Error("item ins too big");He({instructions:r?[...o.instructions,...c]:[...c],payer:this.feePayer,signers:h})?s.push(new Ze().add(...o.instructions,...c)):s.push(new Ze().add(...c)),a.push(Array.from(new Set(c.map(m=>m.keys.filter(T=>T.isSigner).map(T=>T.pubkey.toString())).flat())).map(m=>i[m]).filter(m=>m!==void 0)),c=[d]}}),c.length>0){let l=[...new Set(c.map(f=>f.keys.filter(p=>p.isSigner).map(p=>p.pubkey.toString())).flat()).values()].map(f=>i[f]).filter(f=>f!==void 0);He({instructions:r?[...o.instructions,...c]:[...c],payer:this.feePayer,signers:l.map(f=>f.publicKey)})?s.push(new Ze().add(...o.instructions,...c)):s.push(new Ze().add(...c)),a.push(l)}return s.forEach(d=>d.feePayer=this.feePayer),{builder:this,transactions:s,signers:a,instructionTypes:this.instructionTypes,execute:async d=>{var T;let{sequentially:l,onTxUpdate:f,recentBlockHash:p,skipPreflight:h=!0}=d||{},m=p!=null?p:await _e(this.connection);if(s.forEach(async(g,x)=>{g.recentBlockhash=m,a[x].length&&g.sign(...a[x])}),Fe(s),(T=this.owner)!=null&&T.isKeyPair){if(l){let g=[];for(let x of s){let y=await ze(this.connection,x,this.signers.find(A=>A.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:h});g.push(y)}return{txIds:g,signedTxs:s}}return{txIds:await Promise.all(s.map(async(g,x)=>await ze(this.connection,g,a[x].find(y=>y.publicKey.equals(this.owner.publicKey))?a[x]:[...a[x],this.owner.signer],{skipPreflight:h}))),signedTxs:s}}if(this.signAllTransactions){let g=await this.signAllTransactions(s);if(l){let x=0,y=[],A=async()=>{if(!g[x])return;let k=await this.connection.sendRawTransaction(g[x].serialize(),{skipPreflight:h});y.push({txId:k,status:"sent",signedTx:g[x]}),f==null||f([...y]),x++,this.connection.onSignature(k,C=>{let M=y.findIndex(D=>D.txId===k);M>-1&&(y[M].status=C.err?"error":"success"),f==null||f([...y]),C.err||A()},"processed"),this.connection.getSignatureStatus(k)};return await A(),{txIds:y.map(k=>k.txId),signedTxs:g}}else{let x=[];for(let y=0;y<g.length;y+=1){let A=await this.connection.sendRawTransaction(g[y].serialize(),{skipPreflight:h});x.push(A)}return{txIds:x,signedTxs:g}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:n||{}}}async sizeCheckBuildV0(t){let T=t||{},{computeBudgetConfig:r,lookupTableCache:n={},lookupTableAddress:o=[]}=T,i=it(T,["computeBudgetConfig","lookupTableCache","lookupTableAddress"]),s=H(H({},this.cluster==="devnet"?{}:wt),n),a=Array.from(new Set([...this.lookupTableAddress,...o])),c=[];for(let g of a)s[g]===void 0&&c.push(new Ye(g));let u=await Zt({connection:this.connection,address:c});for(let[g,x]of Object.entries(u))s[g]=x;let d=r?ht(r):{instructions:[],instructionTypes:[]},l=await _e(this.connection),f=this.signers.reduce((g,x)=>ee(H({},g),{[x.publicKey.toBase58()]:x}),{}),p=[],h=[],m=[];if(this.allInstructions.forEach(g=>{let x=[...m,g],y=r?[...d.instructions,...x]:x;if(m.length<12&&je({instructions:y,payer:this.feePayer,lookupTableAddressAccount:s})||je({instructions:x,payer:this.feePayer,lookupTableAddressAccount:s}))m.push(g);else{if(m.length===0)throw Error("item ins too big");let A={};for(let k of[...new Set(a)])s[k]!==void 0&&(A[k]=s[k]);if(r&&je({instructions:[...d.instructions,...m],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let k=new Xe({payerKey:this.feePayer,recentBlockhash:l,instructions:[...d.instructions,...m]}).compileToV0Message(Object.values(s));p.push(new Je(k))}else{let k=new Xe({payerKey:this.feePayer,recentBlockhash:l,instructions:[...m]}).compileToV0Message(Object.values(s));p.push(new Je(k))}h.push(Array.from(new Set(m.map(k=>k.keys.filter(C=>C.isSigner).map(C=>C.pubkey.toString())).flat())).map(k=>f[k]).filter(k=>k!==void 0)),m=[g]}}),m.length>0){let x=[...new Set(m.map(y=>y.keys.filter(A=>A.isSigner).map(A=>A.pubkey.toString())).flat()).values()].map(y=>f[y]).filter(y=>y!==void 0);if(r&&je({instructions:[...d.instructions,...m],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:l})){let y=new Xe({payerKey:this.feePayer,recentBlockhash:l,instructions:[...d.instructions,...m]}).compileToV0Message(Object.values(s));p.push(new Je(y))}else{let y=new Xe({payerKey:this.feePayer,recentBlockhash:l,instructions:[...m]}).compileToV0Message(Object.values(s));p.push(new Je(y))}h.push(x)}return{builder:this,transactions:p,buildProps:t,signers:h,instructionTypes:this.instructionTypes,execute:async g=>{var C;let{sequentially:x,onTxUpdate:y,recentBlockHash:A,skipPreflight:k=!0}=g||{};if(p.map(async(M,D)=>{h[D].length&&M.sign(h[D]),A&&(M.message.recentBlockhash=A)}),Fe(p),(C=this.owner)!=null&&C.isKeyPair){let{lastValidBlockHeight:M,blockhash:D}=await this.connection.getLatestBlockhash();if(p.forEach((L,E)=>{h[E].find(O=>O.publicKey.equals(this.owner.publicKey))||L.sign([this.owner.signer])}),x){let L=[];for(let E of p){let O=await this.connection.sendTransaction(E,{skipPreflight:k}),{lastValidBlockHeight:z,blockhash:V}=await this.connection.getLatestBlockhash();await this.connection.confirmTransaction({blockhash:V,lastValidBlockHeight:z,signature:O},"confirmed"),L.push(O)}return{txIds:L,signedTxs:p}}return{txIds:await Promise.all(p.map(async L=>{let E=await this.connection.sendTransaction(L,{skipPreflight:k});return await this.connection.confirmTransaction({blockhash:D,lastValidBlockHeight:M,signature:E},"confirmed"),E})),signedTxs:p}}if(this.signAllTransactions){let M=await this.signAllTransactions(p);if(x){let D=0,L=[],E=async()=>{if(!M[D])return;let O=await this.connection.sendTransaction(M[D],{skipPreflight:k});L.push({txId:O,status:"sent",signedTx:M[D]}),y==null||y([...L]),D++,this.connection.onSignature(O,z=>{let V=L.findIndex(ne=>ne.txId===O);V>-1&&(L[V].status=z.err?"error":"success"),y==null||y([...L]),z.err||E()},"processed"),this.connection.getSignatureStatus(O)};return E(),{txIds:[],signedTxs:M}}else{let D=[];for(let L=0;L<M.length;L+=1){let E=await this.connection.sendTransaction(M[L],{skipPreflight:k});D.push(E)}return{txIds:D,signedTxs:M}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}};function zt(e,t=1,r=[]){let n=[...e];if(t<=0)return r;for(;n.length;)r.push(n.splice(0,t));return r}import{PublicKey as v}from"@solana/web3.js";var on=new v("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),sn=new v("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Qe=new v("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Mu=new v("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),vu=new v("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),_u=new v("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Du=new v("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ou=new v("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Wu=new v("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Uu=new v("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),qu=new v("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Gu=new v("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Hu=new v("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),ju=new v("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Yu=new v("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),zu=new v("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Zu=new v("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Xu=new v("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ai=new v("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),ui=new v("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),ci=new v("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2");var Ju={SERUM_MARKET:v.default,OPENBOOK_MARKET:new v("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:v.default,FarmV3:new v("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new v("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new v("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new v("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new v("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new v("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),Router:new v("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:ai,CREATE_CPMM_POOL_AUTH:ui,CREATE_CPMM_POOL_FEE_ACC:ci,FEE_DESTINATION_ID:new v("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR")};import{PublicKey as li}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as di}from"@solana/spl-token";function De(e,t,r){return Ve([e.toBuffer(),(r!=null?r:di).toBuffer(),t.toBuffer()],new li("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import oc from"bn.js";import{PublicKey as Ii,Keypair as Si}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Li}from"@solana/spl-token";import Wl from"bn.js";import{PublicKey as bi}from"@solana/web3.js";import ln,{isBN as dn}from"bn.js";import{bits as Ac,BitStructure as Ic,blob as fi,Blob as Sc,cstr as Lc,f32 as Bc,f32be as Rc,f64 as Kc,f64be as Cc,greedy as Vc,Layout as pi,ns64 as Fc,ns64be as Nc,nu64 as Ec,nu64be as Mc,offset as vc,s16 as _c,s16be as Dc,s24 as Oc,s24be as Wc,s32 as Uc,s32be as qc,s40 as Gc,s40be as Hc,s48 as jc,s48be as Yc,s8 as zc,seq as mi,struct as Zc,Structure as gi,u16 as Xc,u16be as Jc,u24 as Qc,u24be as $c,u32 as el,u32be as tl,u40 as rl,u40be as nl,u48 as ol,u48be as il,u8 as yi,UInt as hi,union as sl,Union as al,unionLayoutDiscriminator as ul,utf8 as cl}from"@solana/buffer-layout";var Xt=pi,an=gi;var Jt=hi;var un=yi;var cn=mi;var Ne=fi;var Oe=class extends Xt{constructor(r,n,o){super(r,o);this.blob=Ne(r),this.signed=n}decode(r,n=0){let o=new ln(this.blob.decode(r,n),10,"le");return this.signed?o.fromTwos(this.span*8).clone():o}encode(r,n,o=0){return typeof r=="number"&&(r=new ln(r)),this.signed&&(r=r.toTwos(this.span*8)),this.blob.encode(r.toArrayLike(Buffer,"le",this.span),n,o)}};function $(e){return new Jt(1,e)}function $e(e){return new Jt(4,e)}function P(e){return new Oe(8,!1,e)}function xe(e){return new Oe(16,!1,e)}function fn(e){return new Oe(1,!0,e)}function Tt(e){return new Oe(8,!0,e)}var Pt=class extends Xt{constructor(r,n,o,i){super(r.span,i);this.layout=r,this.decoder=n,this.encoder=o}decode(r,n){return this.decoder(this.layout.decode(r,n))}encode(r,n,o){return this.layout.encode(this.encoder(r),n,o)}getSpan(r,n){return this.layout.getSpan(r,n)}};function N(e){return new Pt(Ne(32),t=>new bi(t),t=>t.toBuffer(),e)}function kt(e){return new Pt(un(),wi,xi,e)}function wi(e){if(e===0)return!1;if(e===1)return!0;throw new Error("Invalid bool: "+e)}function xi(e){return e?1:0}var Qt=class extends an{decode(t,r){return super.decode(t,r)}};function Y(e,t,r){return new Qt(e,t,r)}function X(e,t,r){let n,o=typeof t=="number"?t:dn(t)?t.toNumber():new Proxy(t,{get(i,s){if(!n){let a=Reflect.get(i,"count");n=dn(a)?a.toNumber():a,Reflect.set(i,"count",n)}return Reflect.get(i,s)},set(i,s,a){return s==="count"&&(n=a),Reflect.set(i,s,a)}});return cn(e,o,r)}var et=Y([N("mint"),N("owner"),P("amount"),$e("delegateOption"),N("delegate"),$("state"),$e("isNativeOption"),P("isNative"),P("delegatedAmount"),$e("closeAuthorityOption"),N("closeAuthority")]);function Pi(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function $t(e,...t){if(!Pi(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 er(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 pn(e,t){$t(e);let r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}var It=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),fe=(e,t)=>e<<32-t|e>>>t;var Sl=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Ti(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function tr(e){return typeof e=="string"&&(e=Ti(e)),$t(e),e}var At=class{clone(){return this._cloneInto()}},Ll={}.toString;function mn(e){let t=n=>e().update(tr(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function ki(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),i=BigInt(4294967295),s=Number(r>>o&i),a=Number(r&i),c=n?4:0,u=n?0:4;e.setUint32(t+c,s,n),e.setUint32(t+u,a,n)}var gn=(e,t,r)=>e&t^~e&r,yn=(e,t,r)=>e&t^e&r^t&r,St=class extends At{constructor(t,r,n,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,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){er(this);let{view:r,buffer:n,blockLen:o}=this;t=tr(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=It(t);for(;o<=i-s;s+=o)this.process(c,s);continue}n.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){er(this),pn(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:i}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(n,0),s=0);for(let l=s;l<o;l++)r[l]=0;ki(n,o-8,BigInt(this.length*8),i),this.process(n,0);let a=It(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,d=this.get();if(u>d.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,d[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:i,destroyed:s,pos:a}=this;return t.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%r&&t.buffer.set(n),t}};var Ai=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]),Le=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Be=new Uint32Array(64),rr=class extends St{constructor(){super(64,32,8,!1),this.A=Le[0]|0,this.B=Le[1]|0,this.C=Le[2]|0,this.D=Le[3]|0,this.E=Le[4]|0,this.F=Le[5]|0,this.G=Le[6]|0,this.H=Le[7]|0}get(){let{A:t,B:r,C:n,D:o,E:i,F:s,G:a,H:c}=this;return[t,r,n,o,i,s,a,c]}set(t,r,n,o,i,s,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=c|0}process(t,r){for(let l=0;l<16;l++,r+=4)Be[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let f=Be[l-15],p=Be[l-2],h=fe(f,7)^fe(f,18)^f>>>3,m=fe(p,17)^fe(p,19)^p>>>10;Be[l]=m+Be[l-7]+h+Be[l-16]|0}let{A:n,B:o,C:i,D:s,E:a,F:c,G:u,H:d}=this;for(let l=0;l<64;l++){let f=fe(a,6)^fe(a,11)^fe(a,25),p=d+f+gn(a,c,u)+Ai[l]+Be[l]|0,m=(fe(n,2)^fe(n,13)^fe(n,22))+yn(n,o,i)|0;d=u,u=c,c=a,a=s+p|0,s=i,i=o,o=n,n=p+m|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,d=d+this.H|0,this.set(n,o,i,s,a,c,u,d)}roundClean(){Be.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var hn=mn(()=>new rr);var Hl=Q("Raydium_Util");function Lt({fromPublicKey:e,programId:t=Li}){let r=Si.generate().publicKey.toBase58().slice(0,32);return{publicKey:Bi(e,r,t),seed:r}}function Bi(e,t,r){let n=Buffer.concat([e.toBuffer(),Buffer.from(t),r.toBuffer()]),o=hn(n);return new Ii(o)}import{createInitializeAccountInstruction as Ri,createCloseAccountInstruction as Ki,createTransferInstruction as zl,TOKEN_PROGRAM_ID as tt}from"@solana/spl-token";import{PublicKey as Ci,SystemProgram as Vi}from"@solana/web3.js";import Fi from"bn.js";function Ni(e){let{mint:t,tokenAccount:r,owner:n,programId:o=tt}=e;return Ri(r,t,n,o)}function Ei(e){let{tokenAccount:t,payer:r,multiSigners:n=[],owner:o,programId:i=tt}=e;return Ki(t,r,o,n,i)}async function nr(e){let{connection:t,amount:r,commitment:n,payer:o,owner:i,skipCloseAccount:s}=e,a=await t.getMinimumBalanceForRentExemption(et.span,n),c=F(r).add(new Fi(a)),u=Lt({fromPublicKey:o,programId:tt});return{addresses:{newAccount:u.publicKey},signers:[],instructions:[Vi.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:u.seed,newAccountPubkey:u.publicKey,lamports:c.toNumber(),space:et.span,programId:tt}),Ni({mint:new Ci(se.address),tokenAccount:u.publicKey,owner:i,programId:tt})],instructionTypes:[j.CreateAccount,j.InitAccount],endInstructionTypes:s?[]:[j.CloseAccount],endInstructions:s?[]:[Ei({tokenAccount:u.publicKey,payer:o,owner:i})]}}var or=(...e)=>e.map(t=>{try{return typeof t=="object"?JSON.stringify(t):t}catch{return t}}).join(", "),rt=class{constructor({scope:t,moduleName:r}){this.disabled=!1;this.scope=t,this.logger=Q(r)}createTxBuilder(t){return this.scope.checkOwner(),new xt({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(or(t))}logInfo(...t){this.logger.info(or(t))}logAndCreateError(...t){let r=or(t);throw new Error(r)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};import{PublicKey as xn}from"@solana/web3.js";var ir=Y([$("instruction")]),sr=Y([$("instruction")]),Mi=Y([P("rewardState"),P("rewardOpenTime"),P("rewardEndTime"),P("rewardLastUpdateTime"),P("totalReward"),P("totalRewardEmissioned"),P("rewardClaimed"),P("rewardPerSecond"),xe("accRewardPerShare"),N("rewardVault"),N("rewardMint"),N("rewardSender"),P("rewardType"),X(P(),15,"padding")]),vi=Y([P("state"),P("nonce"),N("lpVault"),N("rewardVault"),N(),N(),P(),P(),P("totalReward"),xe("perShareReward"),P("lastSlot"),P("perSlotReward")]),_i=Y([P("state"),P("nonce"),N("lpVault"),N("rewardVaultA"),P("totalRewardA"),xe("perShareRewardA"),P("perSlotRewardA"),$("option"),N("rewardVaultB"),Ne(7),P("totalRewardB"),xe("perShareRewardB"),P("perSlotRewardB"),P("lastSlot"),N()]),Di=Y([P(),P("state"),P("nonce"),P("validRewardTokenNum"),xe("rewardMultiplier"),P("rewardPeriodMax"),P("rewardPeriodMin"),P("rewardPeriodExtend"),N("lpMint"),N("lpVault"),X(Mi,5,"rewardInfos"),N("creator"),N(),X(P(),32,"padding")]),Oi=new Proxy(vi,{get(e,t,r){return t==="decode"?(...n)=>{let o=e.decode(...n);return ee(H({},o),{version:3,rewardInfos:[{rewardVault:o.rewardVault,totalReward:o.totalReward,perSlotReward:o.perSlotReward,perShareReward:o.perShareReward}]})}:Reflect.get(e,t,r)}}),Wi=new Proxy(_i,{get(e,t,r){return t==="decode"?(...n)=>{let o=e.decode(...n);return ee(H({},o),{version:5,rewardInfos:[{rewardVault:o.rewardVaultA,totalReward:o.totalRewardA,perSlotReward:o.perSlotRewardA,perShareReward:o.perShareRewardA},{rewardVault:o.rewardVaultB,totalReward:o.totalRewardB,perSlotReward:o.perSlotRewardB,perShareReward:o.perShareRewardB}]})}:Reflect.get(e,t,r)}}),Bt=new Proxy(Di,{get(e,t,r){return t==="decode"?(...n)=>{let o=e.decode(...n);return ee(H({},o),{version:6,rewardInfos:o.rewardInfos.map(i=>{var s;return ee(H({},i),{rewardType:((s=Object.entries(Re).find(a=>String(a[1])===i.rewardType.toString()))!=null?s:["Standard SPL"])[0]})})})}:Reflect.get(e,t,r)}}),Ui=Y([P("isSet"),P("rewardPerSecond"),P("rewardOpenTime"),P("rewardEndTime"),P("rewardType")]),ar=Y([$("instruction"),P("nonce"),X(Ui,5,"rewardTimeInfo")]),ur=Y([$("instruction"),P("rewardReopenTime"),P("rewardEndTime"),P("rewardPerSecond")]),cr=Y([$("instruction"),P("isSet"),P("rewardPerSecond"),P("rewardOpenTime"),P("rewardEndTime"),P("rewardType")]),hd=Y([P("state"),N("id"),N("owner"),P("deposited"),X(P(),1,"rewardDebts")]),lr=Y([P("state"),N("id"),N("owner"),P("deposited"),X(xe(),1,"rewardDebts"),P(""),P("voteLockedBalance"),X(P(),15)]),bd=Y([P("state"),N("id"),N("owner"),P("deposited"),X(P(),2,"rewardDebts")]),bn=Y([P("state"),N("id"),N("owner"),P("deposited"),X(xe(),2,"rewardDebts"),X(P(),17)]),wn=Y([P(),P("state"),N("id"),N("owner"),P("deposited"),X(xe(),5,"rewardDebts"),X(P(),16)]),ce=Y([$("instruction"),P("amount")]),qi=Y([N("mint"),N("grantAuthority"),P("baselineVoteWeightScaledFactor"),P("maxExtraLockupVoteWeightScaledFactor"),P("lockupSaturationSecs"),fn("digitShift"),X($(),7,"reserved1"),X(P(),7,"reserved2")]),Gi=Y([Ne(8),N("governanceProgramId"),N("realm"),N("realmGoverningTokenMint"),N("realmAuthority"),X($(),32,"reserved1"),X(qi,4,"votingMints"),Tt("timeOffset"),$("bump"),X($(),7,"reserved2"),X(P(),11,"reserved3")]),Hi=Y([Tt("startTime"),Tt("endTime"),$("kind"),X($(),15,"reserved")]),ji=Y([X(Hi,1,"lockup"),P("amountDeposited_native"),P("amountInitiallyLockedNative"),kt("isUsed"),kt("allowClawback"),$("votingMintConfigIdx"),X($(),29,"reserved")]),Yi=Y([Ne(8),N("voterAuthority"),N("registrar"),X(ji,32,"deposits"),$("voterBump"),$("voterWweightRecordBump"),X($(),94,"reserved")]);var Sd=Q("Raydium_farm_config"),Pn=new xn("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Tn=new xn("FrspKwj8i3pNmKwXreTveC4fu7KL5ZbGeXdZBe2XViu1");var kn={3:lr,5:bn,6:wn},dr=e=>[3,5,6].indexOf(e)!==-1,fr=e=>{var s;let{version:t,rewardInfos:r,rewardTokenAccountsPublicKeys:n}=e,o=`rewardInfo:${JSON.stringify(r)}, rewardAccount:${JSON.stringify(n)}`,i={3:()=>{if(r.length!==1||n.length!==1)return`rewardInfos or rewardTokenAccounts lengths not equal 1: ${o}`},5:()=>{if(r.length!==n.length)return`rewardInfos and rewardTokenAccounts lengths not equal: ${o}`},6:()=>{if(!n.length||r.length!==n.length)return`no rewardTokenAccounts or rewardInfos and rewardTokenAccounts lengths not equal: ${o}`}};return(s=i[t])==null?void 0:s.call(i)},Re={"Standard SPL":0,"Option tokens":1},Pe={[on.toString()]:3,[sn.toString()]:5,[Qe.toString()]:6};import{PublicKey as _,SystemProgram as Sn,SYSVAR_RENT_PUBKEY as Xi,SYSVAR_CLOCK_PUBKEY as Rt,TransactionInstruction as pe}from"@solana/web3.js";import{createAssociatedTokenAccountInstruction as of,TOKEN_PROGRAM_ID as Ke,ASSOCIATED_TOKEN_PROGRAM_ID as sf}from"@solana/spl-token";import Ln from"bn.js";import zi from"bn.js";var Zi=Q("Raydium.farm.util");function nt({programId:e,poolId:t,mint:r,type:n}){let{publicKey:o}=Ve([t.toBuffer(),r.toBuffer(),Buffer.from(n==="lpVault"?"lp_vault_associated_seed":n==="rewardVault"?"reward_vault_associated_seed":"","utf-8")],e);return o}function ge({programId:e,poolId:t,owner:r,version:n}){let{publicKey:o}=Ve([t.toBuffer(),r.toBuffer(),Buffer.from(n===6?"farmer_info_associated_seed":"staker_info_v2_associated_seed","utf-8")],e);return o}var An=({programId:e,poolId:t})=>Ve([t.toBuffer()],e);function In(e){return{isSet:new zi(1),rewardPerSecond:F(e.perSecond),rewardOpenTime:F(e.openTime),rewardEndTime:F(e.endTime),rewardType:F(Re[e.rewardType])}}function pr(e){return F(e.endTime).sub(F(e.openTime)).mul(F(e.perSecond))}function mr(e){let t=kn[e];return t||Zi.logWithError("invalid version",e),t}var Ji=Q("Raydium_farm_instruction"),wf={voterStakeRegistryCreateVoter:Buffer.from([6,24,245,52,243,255,148,25]),voterStakeRegistryCreateDepositEntry:Buffer.from([185,131,167,186,159,125,19,67]),voterStakeRegistryDeposit:Buffer.from([242,35,198,137,82,225,242,182]),voterStakeRegistryWithdraw:Buffer.from([183,18,70,156,148,109,161,34]),voterStakeRegistryUpdateVoterWeightRecord:Buffer.from([45,185,3,36,109,190,115,169])};function Bn(e){let{version:t,id:r,ledger:n,programId:o,owner:i}=e,s={3:9,5:10}[t];s||Ji.logWithError(`invalid farm pool version: ${t}`);let a=Buffer.alloc(ir.span);ir.encode({instruction:s},a);let c=[w({pubkey:r}),w({pubkey:n}),w({pubkey:i,isWritable:!1}),w({pubkey:Sn.programId,isWritable:!1}),w({pubkey:Xi,isWritable:!1})];return{instruction:new pe({programId:o,keys:c,data:a}),instructionType:j.FarmV3CreateLedger}}function Rn(e){var n;let t=Buffer.alloc(ar.span);ar.encode({instruction:0,nonce:new Ln(e.nonce),rewardTimeInfo:e.rewardInfoConfig},t);let r=[..._t,w({pubkey:e.farmId}),w({pubkey:e.farmAuthority,isWritable:!1}),w({pubkey:e.lpVault}),w({pubkey:e.lpMint,isWritable:!1}),w({pubkey:e.lockVault}),w({pubkey:e.lockMint,isWritable:!1}),w({pubkey:(n=e.lockUserAccount)!=null?n:re}),w({pubkey:e.owner,isWritable:!1,isSigner:!0})];for(let o of e.rewardInfo)r.push(w({pubkey:o.rewardMint,isWritable:!1}),w({pubkey:o.rewardVault}),w({pubkey:o.userRewardToken}));return{instruction:new pe({programId:e.programId,keys:r,data:t}),instructionType:j.FarmV6Create}}function Kn(e){let t=Buffer.alloc(sr.span);sr.encode({instruction:5},t);let r=[w({pubkey:Ke,isWritable:!1}),w({pubkey:e.id}),w({pubkey:e.authority,isWritable:!1}),w({pubkey:e.lpVault,isWritable:!1}),w({pubkey:e.rewardVault}),w({pubkey:e.userRewardToken}),w({pubkey:e.owner,isWritable:!1,isSigner:!0})];return{instruction:new pe({programId:e.programId,keys:r,data:t}),instructionType:j.FarmV6CreatorWithdraw}}function gr({payer:e,rewardVault:t,userRewardTokenPub:r,farmKeys:n,rewardInfo:o}){let i=Buffer.alloc(ur.span);ur.encode({instruction:3,rewardReopenTime:F(o.openTime),rewardEndTime:F(o.endTime),rewardPerSecond:F(o.perSecond)},i);let s=[w({pubkey:Ke,isWritable:!1}),w({pubkey:n.id}),w({pubkey:n.lpVault,isWritable:!1}),w({pubkey:t}),w({pubkey:r}),w({pubkey:e,isWritable:!1,isSigner:!0})];return new pe({programId:n.programId,keys:s,data:i})}function yr({payer:e,userRewardTokenPub:t,farmKeys:r,rewardVault:n,rewardInfo:o}){let i=Buffer.alloc(cr.span);cr.encode({instruction:4,isSet:new Ln(1),rewardPerSecond:F(o.perSecond),rewardOpenTime:F(o.openTime),rewardEndTime:F(o.endTime),rewardType:F(Re[o.rewardType])},i);let s=[..._t,w({pubkey:r.id}),w({pubkey:r.authority,isWritable:!1}),w({pubkey:o.mint,isWritable:!1}),w({pubkey:n}),w({pubkey:t}),w({pubkey:e,isWritable:!1,isSigner:!0})];return new pe({programId:r.programId,keys:s,data:i})}function hr(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s}=e,[a,c]=[new _(t.programId),new _(t.id)],u=ge({programId:a,poolId:c,owner:i,version:6}),d=Buffer.alloc(ce.span);ce.encode({instruction:2,amount:F(s)},d);let l=[w({pubkey:Ke,isWritable:!1}),w({pubkey:c}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:new _(r.lpVault)}),w({pubkey:u}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n})];for(let f=0;f<r.rewardInfos.length;f++)l.push(w({pubkey:new _(r.rewardInfos[f].vault)})),l.push(w({pubkey:o[f]}));return new pe({programId:a,keys:l,data:d})}function br(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new _(t.programId),new _(t.id)],d=ge({programId:c,poolId:u,owner:i,version:5}),l=Buffer.alloc(ce.span);ce.encode({instruction:12,amount:F(s)},l);let f=[w({pubkey:u}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:d}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n}),w({pubkey:new _(r.lpVault)}),w({pubkey:o[0]}),w({pubkey:new _(r.rewardInfos[0].vault)}),w({pubkey:Rt,isWritable:!1}),w({pubkey:Ke,isWritable:!1})];for(let p=1;p<r.rewardInfos.length;p++)f.push(w({pubkey:o[p]})),f.push(w({pubkey:new _(r.rewardInfos[p].vault)}));if(a)for(let p of a)f.push(w({pubkey:p}));return new pe({programId:c,keys:f,data:l})}function wr(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new _(t.programId),new _(t.id)],d=ge({programId:c,poolId:u,owner:i,version:3}),l=Buffer.alloc(ce.span);ce.encode({instruction:11,amount:F(s)},l);let f=[w({pubkey:u}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:d}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n}),w({pubkey:new _(r.lpVault)}),w({pubkey:o[0]}),w({pubkey:new _(r.rewardInfos[0].vault)}),w({pubkey:Rt,isWritable:!1}),w({pubkey:Ke,isWritable:!1})];if(a)for(let p of a)f.push(w({pubkey:p}));return new pe({programId:c,keys:f,data:l})}function Cn(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new _(t.programId),new _(t.id)],d=ge({programId:c,poolId:u,owner:i,version:3}),l=Buffer.alloc(ce.span);ce.encode({instruction:10,amount:F(s)},l);let f=[w({pubkey:u}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:d}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n}),w({pubkey:new _(r.lpVault)}),w({pubkey:o[0]}),w({pubkey:new _(r.rewardInfos[0].vault)}),w({pubkey:Rt,isWritable:!1}),w({pubkey:Ke,isWritable:!1})];if(a)for(let p of a)f.push(w({pubkey:p}));return new pe({programId:c,keys:f,data:l})}function Vn(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new _(t.programId),new _(t.id)],d=ge({programId:c,poolId:u,owner:i,version:5}),l=Buffer.alloc(ce.span);ce.encode({instruction:11,amount:F(s)},l);let f=[w({pubkey:u}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:d}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n}),w({pubkey:new _(r.lpVault)}),w({pubkey:o[0]}),w({pubkey:new _(r.rewardInfos[0].vault)}),w({pubkey:Rt,isWritable:!1}),w({pubkey:Ke,isWritable:!1})];for(let p=1;p<r.rewardInfos.length;p++)f.push(w({pubkey:o[p]})),f.push(w({pubkey:new _(r.rewardInfos[p].vault)}));if(a)for(let p of a)f.push(w({pubkey:p}));return new pe({programId:c,keys:f,data:l})}function Fn(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:o,owner:i,amount:s}=e,[a,c]=[new _(t.programId),new _(t.id)],u=ge({programId:a,poolId:c,owner:i,version:6}),d=Buffer.alloc(ce.span);ce.encode({instruction:1,amount:F(s)},d);let l=[w({pubkey:Ke,isWritable:!1}),w({pubkey:Sn.programId,isWritable:!1}),w({pubkey:c}),w({pubkey:new _(r.authority),isWritable:!1}),w({pubkey:new _(r.lpVault)}),w({pubkey:u}),w({pubkey:i,isWritable:!1,isSigner:!0}),w({pubkey:n})];for(let f=0;f<r.rewardInfos.length;f++)l.push(w({pubkey:new _(r.rewardInfos[f].vault)})),l.push(w({pubkey:o[f]}));return new pe({programId:a,keys:l,data:d})}var xr=class extends rt{async _getUserRewardInfo({payer:t,rewardInfo:r}){if(r.mint.equals(re)){let n=await nr({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:t,amount:pr(ee(H({},r),{openTime:r.openTime.toString(),endTime:r.endTime.toString()}))});return{rewardPubKey:n.addresses.newAccount,newInstruction:n}}return{rewardPubKey:await this.scope.account.getCreatedTokenAccount({mint:r.mint,associatedOnly:!1})}}async create({poolInfo:t,rewardInfos:r,payer:n,programId:o=Qe,txVersion:i}){this.checkDisabled(),this.scope.checkOwner();let a={lpMint:new G(t.lpMint.address),lockInfo:{lockMint:Pn,lockVault:Tn},version:6,rewardInfos:r,programId:o},c=this.createTxBuilder(),u=n!=null?n:this.scope.ownerPubKey,d=Lt({fromPublicKey:u,programId:a.programId}),l=await this.scope.connection.getMinimumBalanceForRentExemption(Bt.span);c.addInstruction({instructions:[$i.createAccountWithSeed({fromPubkey:u,basePubkey:u,seed:d.seed,newAccountPubkey:d.publicKey,lamports:l,space:Bt.span,programId:a.programId})]});let{publicKey:f,nonce:p}=An({programId:new G(a.programId),poolId:d.publicKey}),h=nt({programId:a.programId,poolId:d.publicKey,mint:a.lpMint,type:"lpVault"}),m=[],T=[];for(let k of a.rewardInfos){k.openTime>=k.endTime&&this.logAndCreateError("start time error","rewardInfo.rewardOpenTime",k.openTime.toString()),isNaN(Re[k.rewardType])&&this.logAndCreateError("rewardType error",k.rewardType),Number(k.perSecond)<=0&&this.logAndCreateError("rewardPerSecond error",k.perSecond),m.push(In(k));let{rewardPubKey:C,newInstruction:M}=await this._getUserRewardInfo({rewardInfo:k,payer:u});M&&c.addInstruction(M),C||this.logAndCreateError("cannot found target token accounts",this.scope.account.tokenAccounts);let D=k.mint.equals(re)?new G(se.address):k.mint;T.push({rewardMint:D,rewardVault:nt({programId:a.programId,poolId:d.publicKey,mint:D,type:"rewardVault"}),userRewardToken:C})}let{account:g,instructionParams:x}=await this.scope.account.getOrCreateTokenAccount({mint:new G(a.lockInfo.lockMint),owner:this.scope.ownerPubKey,skipCloseAccount:!1,createInfo:{payer:this.scope.ownerPubKey,amount:0},associatedOnly:!1});x&&c.addInstruction(x),g||this.logAndCreateError("cannot found lock vault","tokenAccounts",this.scope.account.tokenAccounts);let{instruction:y,instructionType:A}=Rn({farmId:d.publicKey,owner:this.scope.ownerPubKey,farmAuthority:f,lpVault:h,lpMint:a.lpMint,lockVault:a.lockInfo.lockVault,lockMint:a.lockInfo.lockMint,lockUserAccount:g,programId:a.programId,rewardInfo:T,rewardInfoConfig:m,nonce:p});return c.addInstruction({instructions:[y],instructionTypes:[A]}).versionBuild({txVersion:i,extInfo:{farmId:d.publicKey,farmAuthority:f,lpVault:h,lockUserAccount:g,nonce:p}})}async restartReward({farmInfo:t,payer:r,newRewardInfo:n,txVersion:o}){var T;let i=Pe[t.programId];i!==6&&this.logAndCreateError("invalid farm version ",i);let s=we((await this.scope.api.fetchFarmKeysById({ids:t.id}))[0]),a={id:s.id,rewardInfos:t.rewardInfos,lpVault:s.lpVault,programId:s.programId};n.openTime>=n.endTime&&this.logAndCreateError("start time error","newRewardInfo",n);let c=r||this.scope.ownerPubKey,u=n.mint.equals(re)?new G(se.address):n.mint,d=a.rewardInfos.findIndex(g=>new G(g.mint.address).equals(u)),l=s.rewardInfos[d];l||this.logAndCreateError("configuration does not exist","rewardMint",u);let f=(T=l.vault)!=null?T:re,p=this.createTxBuilder(),{rewardPubKey:h,newInstruction:m}=await this._getUserRewardInfo({rewardInfo:n,payer:c});return m&&p.addInstruction(m),h||this.logAndCreateError("cannot found target token accounts",this.scope.account.tokenAccounts),p.addInstruction({instructions:[gr({payer:this.scope.ownerPubKey,rewardVault:f,userRewardTokenPub:h,farmKeys:a,rewardInfo:n})],instructionTypes:[j.FarmV6Restart]}).versionBuild({txVersion:o})}async restartRewards({farmInfo:t,payer:r,newRewardInfos:n,txVersion:o}){var d;let i=Pe[t.programId];i!==6&&this.logAndCreateError("invalid farm version ",i);let s=we((await this.scope.api.fetchFarmKeysById({ids:t.id}))[0]),a={id:s.id,rewardInfos:t.rewardInfos,lpVault:s.lpVault,programId:s.programId};n.forEach(l=>{l.openTime>=l.endTime&&this.logAndCreateError("start time error","newRewardInfo",l)});let c=r||this.scope.ownerPubKey,u=this.createTxBuilder();for(let l of n){let f=l.mint.equals(re)?new G(se.address):l.mint,p=a.rewardInfos.findIndex(y=>new G(y.mint.address).equals(f)),h=s.rewardInfos[p];h||this.logAndCreateError("configuration does not exist","rewardMint",f);let m=(d=h.vault)!=null?d:re,{rewardPubKey:T,newInstruction:g}=await this._getUserRewardInfo({rewardInfo:l,payer:c});g&&u.addInstruction(g),T||this.logAndCreateError("cannot found target token accounts",this.scope.account.tokenAccounts);let x=gr({payer:this.scope.ownerPubKey,rewardVault:m,userRewardTokenPub:T,farmKeys:a,rewardInfo:l});u.addInstruction({instructions:[x],instructionTypes:[j.FarmV6Restart]})}return u.versionBuild({txVersion:o})}async addNewRewardToken(t){let{txVersion:r,farmInfo:n,newRewardInfo:o,payer:i}=t,s=Pe[n.programId];s!==6&&this.logAndCreateError("invalid farm version ",s);let a=we((await this.scope.api.fetchFarmKeysById({ids:n.id}))[0]),c=i!=null?i:this.scope.ownerPubKey,u=this.createTxBuilder(),d=o.mint.equals(re)?new G(se.address):o.mint,l=nt({programId:new G(n.programId),poolId:new G(n.id),mint:d,type:"rewardVault"}),{rewardPubKey:f,newInstruction:p}=await this._getUserRewardInfo({rewardInfo:o,payer:c});return p&&u.addInstruction(p),f||this.logAndCreateError("annot found target token accounts",this.scope.account.tokenAccounts),o.mint=d,u.addInstruction({instructions:[yr({payer:this.scope.ownerPubKey,userRewardTokenPub:f,farmKeys:a,rewardVault:l,rewardInfo:o})],instructionTypes:[j.FarmV6CreatorAddReward]}).versionBuild({txVersion:r})}async addNewRewardsToken(t){let{txVersion:r,farmInfo:n,newRewardInfos:o,payer:i}=t,s=Pe[n.programId];s!==6&&this.logAndCreateError("invalid farm version ",s);let a=we((await this.scope.api.fetchFarmKeysById({ids:n.id}))[0]),c=i!=null?i:this.scope.ownerPubKey,u=this.createTxBuilder();for(let d of o){let l=d.mint.equals(re)?new G(se.address):d.mint,f=nt({programId:new G(n.programId),poolId:new G(n.id),mint:l,type:"rewardVault"}),{rewardPubKey:p,newInstruction:h}=await this._getUserRewardInfo({rewardInfo:d,payer:c});h&&u.addInstruction(h),p||this.logAndCreateError("cannot found target token accounts",this.scope.account.tokenAccounts);let m=yr({payer:this.scope.ownerPubKey,userRewardTokenPub:p,farmKeys:a,rewardVault:f,rewardInfo:ee(H({},d),{mint:l})});u.addInstruction({instructions:[m],instructionTypes:[j.FarmV6CreatorAddReward]})}return u.versionBuild({txVersion:r})}async deposit(t){let{txVersion:r,farmInfo:n,amount:o,feePayer:i,useSOLBalance:s,associatedOnly:a=!0,checkCreateATAOwner:c=!1,userAuxiliaryLedgers:u,computeBudgetConfig:d}=t;this.scope.availability.addFarm===!1&&this.logAndCreateError("farm deposit feature disabled in your region");let{rewardInfos:l,programId:f}=n,p=Pe[f];dr(p)||this.logAndCreateError("invalid farm program:",n.programId);let[h,m]=[new G(n.programId),new G(n.id)],T=(await this.scope.api.fetchFarmKeysById({ids:n.id}))[0],g=ge({programId:h,poolId:m,owner:this.scope.ownerPubKey,version:p}),x=this.createTxBuilder();x.addCustomComputeBudget(d);let y={};for(let V of this.scope.account.tokenAccounts)if(a){let ne=De(this.scope.ownerPubKey,V.mint,V.programId).publicKey;V.publicKey&&ne.equals(V.publicKey)&&(y[V.mint.toString()]=V.publicKey)}else y[V.mint.toString()]=V.publicKey;let A=T.lpMint,k=y[A.address];k||this.logAndCreateError("you don't have any lp","lp zero",y);let C=[];for(let V of l){let ne=s&&V.mint.address===Se.toString(),J=y[V.mint.address];if(!J){let{account:W,instructionParams:Pr}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:V.mint.programId,mint:new G(V.mint.address),notUseTokenAccount:ne,createInfo:{payer:i||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!ne,associatedOnly:ne?!1:a,checkCreateATAOwner:c});J=W,Pr&&x.addInstruction(Pr)}y[V.mint.address]=J,C.push(J)}let M,D=await this.scope.connection.getAccountInfo(g);if(D&&(M=mr(p).decode(D.data)),n.programId!==Qe.toString()&&!M){let{instruction:V,instructionType:ne}=Bn({id:m,programId:h,version:p,ledger:g,owner:this.scope.ownerPubKey});x.addInstruction({instructions:[V],instructionTypes:[ne]})}let L=fr({version:p,rewardInfos:l,rewardTokenAccountsPublicKeys:C});L&&this.logAndCreateError(L);let E={amount:F(o),owner:this.scope.ownerPubKey,farmInfo:n,farmKeys:T,lpAccount:k,rewardAccounts:C,userAuxiliaryLedgers:u==null?void 0:u.map(V=>new G(V))},O=p===6?Fn(E):p===5?Vn(E):Cn(E),z={3:j.FarmV3Deposit,5:j.FarmV5Deposit,6:j.FarmV6Deposit};return x.addInstruction({instructions:[O],instructionTypes:[z[p]]}).versionBuild({txVersion:r})}async withdraw(t){let{txVersion:r,farmInfo:n,amount:o,deposited:i,useSOLBalance:s,feePayer:a,associatedOnly:c=!0,checkCreateATAOwner:u=!1,userAuxiliaryLedgers:d,computeBudgetConfig:l}=t,{rewardInfos:f}=n;this.scope.availability.removeFarm===!1&&this.logAndCreateError("farm withdraw feature disabled in your region");let p=Pe[n.programId];dr(p)||this.logAndCreateError("invalid farm program:",n.programId);let h=(await this.scope.api.fetchFarmKeysById({ids:n.id}))[0],m=this.createTxBuilder();m.addCustomComputeBudget(l);let T={};for(let L of this.scope.account.tokenAccounts)if(c){let E=De(this.scope.ownerPubKey,L.mint).publicKey;L.publicKey&&E.equals(L.publicKey)&&(T[L.mint.toString()]=L.publicKey)}else T[L.mint.toString()]=L.publicKey;if(i)i.isZero()&&this.logAndCreateError("no deposited lp",{farmId:n.id});else{let L=ge({programId:new G(n.programId),poolId:new G(n.id),owner:this.scope.ownerPubKey,version:p}),E=await this.scope.connection.getAccountInfo(L);E||this.logAndCreateError("no lp data",{farmId:n.id,version:p,ledgerData:E}),mr(p).decode(E.data).deposited.isZero()&&this.logAndCreateError("no deposited lp",{farmId:n.id})}let g=h.lpMint.address,x=s&&g===Se.toString(),y=T[g.toString()];if(!y){let{account:L,instructionParams:E}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:h.lpMint.programId,mint:new G(g),notUseTokenAccount:x,createInfo:{payer:a||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!0,associatedOnly:x?!1:c,checkCreateATAOwner:u});y=L,E&&m.addInstruction(E)}T[g.toString()]=y;let A=[];for(let L of f){let E=s&&L.mint.address===Se.toString(),O=T[L.mint.address];if(!O){let{account:z,instructionParams:V}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:L.mint.programId,mint:new G(L.mint.address),notUseTokenAccount:E,createInfo:{payer:a||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!E,associatedOnly:E?!1:c,checkCreateATAOwner:u});O=z,V&&m.addInstruction(V)}T[L.mint.address]=O,A.push(O)}let k=fr({version:p,rewardInfos:f,rewardTokenAccountsPublicKeys:A});k&&this.logAndCreateError(k);let C={amount:F(o),owner:this.scope.ownerPubKey,farmInfo:n,farmKeys:h,lpAccount:y,rewardAccounts:A,userAuxiliaryLedgers:d==null?void 0:d.map(L=>new G(L))},M=p===6?hr(C):p===5?br(C):wr(C),D={3:j.FarmV3Withdraw,5:j.FarmV5Withdraw,6:j.FarmV6Withdraw};return m.addInstruction({instructions:[M],instructionTypes:[D[p]]}).versionBuild({txVersion:r})}async withdrawFarmReward({farmInfo:t,withdrawMint:r,txVersion:n}){var p;this.scope.checkOwner();let o=we((await this.scope.api.fetchFarmKeysById({ids:t.id}))[0]),i=Pe[t.programId];i!==6&&this.logAndCreateError("invalid farm version",i);let s=t.rewardInfos.findIndex(h=>h.mint.address===re.toString()?new G(se.address):r),a=o.rewardInfos[s];a||this.logAndCreateError("withdraw mint error","rewardInfos",t);let c=(p=a==null?void 0:a.vault)!=null?p:re,u=this.createTxBuilder(),d;if(r.equals(re)){let h=await nr({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:this.scope.ownerPubKey,amount:pr(ee(H({},a),{openTime:a.openTime,endTime:a.endTime,perSecond:new vt(a.perSecond).mul(10**a.mint.decimals).toString()}))});d=h.addresses.newAccount,u.addInstruction(h)}else{let h=await this.scope.account.getCreatedTokenAccount({mint:r});h===null?(d=await this.scope.account.getAssociatedTokenAccount(r),u.addInstruction({instructions:[Qi(this.scope.ownerPubKey,d,this.scope.ownerPubKey,r)],instructionTypes:[j.CreateATA]})):d=h}let{instruction:l,instructionType:f}=Kn({programId:o.programId,id:o.id,authority:o.authority,lpVault:o.lpVault,rewardVault:c,userRewardToken:d,owner:this.scope.ownerPubKey});return u.addInstruction({instructions:[l],instructionTypes:[f]}).versionBuild({txVersion:n})}async harvestAllRewards(t){let{farmInfoList:r,useSOLBalance:n,feePayer:o,associatedOnly:i=!0,checkCreateATAOwner:s=!1,userAuxiliaryLedgers:a,txVersion:c,computeBudgetConfig:u}=t,d=this.createTxBuilder(),l={};for(let h of this.scope.account.tokenAccounts)if(i){let m=De(this.scope.ownerPubKey,h.mint).publicKey;h.publicKey&&m.equals(h.publicKey)&&(l[h.mint.toString()]=h.publicKey)}else l[h.mint.toString()]=h.publicKey;let p=(await this.scope.api.fetchFarmKeysById({ids:Object.values(r).map(h=>h.id).join(",")})).reduce((h,m)=>ee(H({},h),{[m.id]:m}),{});for(let h of Object.values(r)){let{programId:m,lpMint:T,rewardInfos:g,id:x}=h,y=Pe[m],A=T.address,k=n&&A===Se.toString(),C=l[A];if(!C){let{account:z,instructionParams:V}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:T.programId,mint:new G(A),notUseTokenAccount:k,createInfo:{payer:o||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!0,associatedOnly:k?!1:i,checkCreateATAOwner:s});C=z,V&&d.addInstruction(V)}l[A.toString()]=C;let M=[];for(let z of g){let V=n&&z.mint.address===Se.toString(),ne=l[z.mint.address];if(!ne){let{account:J,instructionParams:W}=await this.scope.account.getOrCreateTokenAccount({tokenProgram:z.mint.programId,mint:new G(z.mint.address),notUseTokenAccount:V,createInfo:{payer:o||this.scope.ownerPubKey,amount:0},owner:this.scope.ownerPubKey,skipCloseAccount:!V,associatedOnly:V?!1:i,checkCreateATAOwner:s});ne=J,W&&d.addInstruction(W)}l[z.mint.address]=ne,M.push(ne)}let D=p[x],L={amount:Ht,owner:this.scope.ownerPubKey,farmInfo:h,farmKeys:D,lpAccount:C,rewardAccounts:M,userAuxiliaryLedgers:a==null?void 0:a.map(z=>new G(z))},E=y===6?hr(L):y===5?br(L):wr(L),O={3:j.FarmV3Withdraw,5:j.FarmV5Withdraw,6:j.FarmV6Withdraw};d.addInstruction({instructions:[E],instructionTypes:[O[y]]})}return c===1?d.sizeCheckBuild({computeBudgetConfig:u}):d.sizeCheckBuildV0({computeBudgetConfig:u})}};export{xr as default};
|
|
2
2
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
3
|
//# sourceMappingURL=farm.mjs.map
|