UNPKG

@raydium-io/raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

2 lines 68.5 kB
var yr=Object.defineProperty,hr=Object.defineProperties;var br=Object.getOwnPropertyDescriptors;var Rt=Object.getOwnPropertySymbols;var wr=Object.prototype.hasOwnProperty,Tr=Object.prototype.propertyIsEnumerable;var Ct=(e,t,r)=>t in e?yr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,J=(e,t)=>{for(var r in t||(t={}))wr.call(t,r)&&Ct(e,r,t[r]);if(Rt)for(var r of Rt(t))Tr.call(t,r)&&Ct(e,r,t[r]);return e},Q=(e,t)=>hr(e,br(t));import{PublicKey as P,SystemProgram as ye,SYSVAR_CLOCK_PUBKEY as Le,SYSVAR_RENT_PUBKEY as li,TransactionInstruction as W}from"@solana/web3.js";import Qe from"bn.js";import{ASSOCIATED_TOKEN_PROGRAM_ID as fi,createAssociatedTokenAccountInstruction as di,TOKEN_PROGRAM_ID as Z}from"@solana/spl-token";import{PublicKey as Ii}from"@solana/web3.js";import{get as vt,set as Pr}from"lodash";var et=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let 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}},Nt={},xr={};function U(e){let t=vt(Nt,e);if(!t){let r=vt(xr,e);t=new et({name:e,logLevel:r}),Pr(Nt,e,t)}return t}import{MINT_SIZE as vi,TOKEN_PROGRAM_ID as Ni,getTransferFeeConfig as Ki,unpackMint as Vi}from"@solana/spl-token";var _i=U("Raydium_accountInfo_util");import oe from"bn.js";var Te=9e15,fe=1e9,rt="0123456789abcdef",Fe="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",De="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",nt={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Te,maxE:Te,crypto:!1},Mt,ie,x=!0,Oe="[DecimalError] ",le=Oe+"Invalid argument: ",Et=Oe+"Precision limit exceeded",Ft=Oe+"crypto unavailable",Dt="[object Decimal]",H=Math.floor,D=Math.pow,Sr=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,kr=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Ar=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Wt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ee=1e7,T=7,Lr=9007199254740991,Ir=Fe.length-1,it=De.length-1,m={toStringTag:Dt};m.absoluteValue=m.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),b(e)};m.ceil=function(){return b(new this.constructor(this),this.e+1,2)};m.clampedTo=m.clamp=function(e,t){var r,n=this,i=n.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(le+t);return r=n.cmp(e),r<0?e:n.cmp(t)>0?t:new i(n)};m.comparedTo=m.cmp=function(e){var t,r,n,i,o=this,s=o.d,a=(e=new o.constructor(e)).d,c=o.s,u=e.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(o.e!==e.e)return o.e>e.e^c<0?1:-1;for(n=s.length,i=a.length,t=0,r=n<i?n:i;t<r;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};m.cosine=m.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())+T,n.rounding=1,r=Br(n,Ht(n,r)),n.precision=e,n.rounding=t,b(ie==2||ie==3?r.neg():r,e,t,!0)):new n(1):new n(NaN)};m.cubeRoot=m.cbrt=function(){var e,t,r,n,i,o,s,a,c,u,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(x=!1,o=l.s*D(l.s*l,1/3),!o||Math.abs(o)==1/0?(r=q(l.d),e=l.e,(o=(e-r.length+1)%3)&&(r+=o==1||o==-2?"0":"00"),o=D(r,1/3),e=H((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?r="5e"+e:(r=o.toExponential(),r=r.slice(0,r.indexOf("e")+1)+e),n=new f(r),n.s=l.s):n=new f(o.toString()),s=(e=f.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=N(u.plus(l).times(a),u.plus(c),s+2,1),q(a.d).slice(0,s)===(r=q(n.d)).slice(0,s))if(r=r.slice(s-3,s+1),r=="9999"||!i&&r=="4999"){if(!i&&(b(a,e+1,0),a.times(a).times(a).eq(l))){n=a;break}s+=4,i=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(b(n,e+1,1),t=!n.times(n).times(n).eq(l));break}return x=!0,b(n,e,f.rounding,t)};m.decimalPlaces=m.dp=function(){var e,t=this.d,r=NaN;if(t){if(e=t.length-1,r=(e-H(this.e/T))*T,e=t[e],e)for(;e%10==0;e/=10)r--;r<0&&(r=0)}return r};m.dividedBy=m.div=function(e){return N(this,new this.constructor(e))};m.dividedToIntegerBy=m.divToInt=function(e){var t=this,r=t.constructor;return b(N(t,new r(e),0,1,1),r.precision,r.rounding)};m.equals=m.eq=function(e){return this.cmp(e)===0};m.floor=function(){return b(new this.constructor(this),this.e+1,3)};m.greaterThan=m.gt=function(e){return this.cmp(e)>0};m.greaterThanOrEqualTo=m.gte=function(e){var t=this.cmp(e);return t==1||t===0};m.hyperbolicCosine=m.cosh=function(){var e,t,r,n,i,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;r=s.precision,n=s.rounding,s.precision=r+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(e=Math.ceil(i/3),t=(1/qe(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=Pe(s,1,o.times(t),new s(1),!0);for(var c,u=e,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return b(o,s.precision=r,s.rounding=n,!0)};m.hyperbolicSine=m.sinh=function(){var e,t,r,n,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(t=o.precision,r=o.rounding,o.precision=t+Math.max(i.e,i.sd())+4,o.rounding=1,n=i.d.length,n<3)i=Pe(o,2,i,i,!0);else{e=1.4*Math.sqrt(n),e=e>16?16:e|0,i=i.times(1/qe(5,e)),i=Pe(o,2,i,i,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);e--;)s=i.times(i),i=i.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=t,o.rounding=r,b(i,t,r,!0)};m.hyperbolicTangent=m.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,N(r.sinh(),r.cosh(),n.precision=e,n.rounding=t)):new n(r.s)};m.inverseCosine=m.acos=function(){var e,t=this,r=t.constructor,n=t.abs().cmp(1),i=r.precision,o=r.rounding;return n!==-1?n===0?t.isNeg()?$(r,i,o):new r(0):new r(NaN):t.isZero()?$(r,i+4,o).times(.5):(r.precision=i+6,r.rounding=1,t=t.asin(),e=$(r,i+4,o).times(.5),r.precision=i,r.rounding=o,e.minus(t))};m.inverseHyperbolicCosine=m.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,x=!1,r=r.times(r).minus(1).sqrt().plus(r),x=!0,n.precision=e,n.rounding=t,r.ln()):new n(r)};m.inverseHyperbolicSine=m.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,x=!1,r=r.times(r).plus(1).sqrt().plus(r),x=!0,n.precision=e,n.rounding=t,r.ln())};m.inverseHyperbolicTangent=m.atanh=function(){var e,t,r,n,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=o.precision,t=o.rounding,n=i.sd(),Math.max(n,e)<2*-i.e-1?b(new o(i),e,t,!0):(o.precision=r=n-i.e,i=N(i.plus(1),new o(1).minus(i),r+e,1),o.precision=e+4,o.rounding=1,i=i.ln(),o.precision=e,o.rounding=t,i.times(.5))):new o(NaN)};m.inverseSine=m.asin=function(){var e,t,r,n,i=this,o=i.constructor;return i.isZero()?new o(i):(t=i.abs().cmp(1),r=o.precision,n=o.rounding,t!==-1?t===0?(e=$(o,r+4,n).times(.5),e.s=i.s,e):new o(NaN):(o.precision=r+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=r,o.rounding=n,i.times(2)))};m.inverseTangent=m.atan=function(){var e,t,r,n,i,o,s,a,c,u=this,l=u.constructor,f=l.precision,d=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&f+4<=it)return s=$(l,f+4,d).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(f+4<=it)return s=$(l,f+4,d).times(.5),s.s=u.s,s}for(l.precision=a=f+10,l.rounding=1,r=Math.min(28,a/T+2|0),e=r;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(x=!1,t=Math.ceil(a/T),n=1,c=u.times(u),s=new l(u),i=u;e!==-1;)if(i=i.times(c),o=s.minus(i.div(n+=2)),i=i.times(c),s=o.plus(i.div(n+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===o.d[e]&&e--;);return r&&(s=s.times(2<<r-1)),x=!0,b(s,l.precision=f,l.rounding=d,!0)};m.isFinite=function(){return!!this.d};m.isInteger=m.isInt=function(){return!!this.d&&H(this.e/T)>this.d.length-2};m.isNaN=function(){return!this.s};m.isNegative=m.isNeg=function(){return this.s<0};m.isPositive=m.isPos=function(){return this.s>0};m.isZero=function(){return!!this.d&&this.d[0]===0};m.lessThan=m.lt=function(e){return this.cmp(e)<0};m.lessThanOrEqualTo=m.lte=function(e){return this.cmp(e)<1};m.logarithm=m.log=function(e){var t,r,n,i,o,s,a,c,u=this,l=u.constructor,f=l.precision,d=l.rounding,g=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),r=e.d,e.s<0||!r||!r[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(r=u.d,u.s<0||!r||!r[0]||u.eq(1))return new l(r&&!r[0]?-1/0:u.s!=1?NaN:r?0:1/0);if(t)if(r.length>1)o=!0;else{for(i=r[0];i%10===0;)i/=10;o=i!==1}if(x=!1,a=f+g,s=ce(u,a),n=t?We(l,a+10):ce(e,a),c=N(s,n,a,1),Be(c.d,i=f,d))do if(a+=10,s=ce(u,a),n=t?We(l,a+10):ce(e,a),c=N(s,n,a,1),!o){+q(c.d).slice(i+1,i+15)+1==1e14&&(c=b(c,f+1,0));break}while(Be(c.d,i+=10,d));return x=!0,b(c,f,d)};m.minus=m.sub=function(e){var t,r,n,i,o,s,a,c,u,l,f,d,g=this,w=g.constructor;if(e=new w(e),!g.d||!e.d)return!g.s||!e.s?e=new w(NaN):g.d?e.s=-e.s:e=new w(e.d||g.s!==e.s?g:NaN),e;if(g.s!=e.s)return e.s=-e.s,g.plus(e);if(u=g.d,d=e.d,a=w.precision,c=w.rounding,!u[0]||!d[0]){if(d[0])e.s=-e.s;else if(u[0])e=new w(g);else return new w(c===3?-0:0);return x?b(e,a,c):e}if(r=H(e.e/T),l=H(g.e/T),u=u.slice(),o=l-r,o){for(f=o<0,f?(t=u,o=-o,s=d.length):(t=d,r=l,s=u.length),n=Math.max(Math.ceil(a/T),s)+2,o>n&&(o=n,t.length=1),t.reverse(),n=o;n--;)t.push(0);t.reverse()}else{for(n=u.length,s=d.length,f=n<s,f&&(s=n),n=0;n<s;n++)if(u[n]!=d[n]){f=u[n]<d[n];break}o=0}for(f&&(t=u,u=d,d=t,e.s=-e.s),s=u.length,n=d.length-s;n>0;--n)u[s++]=0;for(n=d.length;n>o;){if(u[--n]<d[n]){for(i=n;i&&u[--i]===0;)u[i]=ee-1;--u[i],u[n]+=ee}u[n]-=d[n]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--r;return u[0]?(e.d=u,e.e=Ue(u,r),x?b(e,a,c):e):new w(c===3?-0:0)};m.modulo=m.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]?b(new n(r),n.precision,n.rounding):(x=!1,n.modulo==9?(t=N(r,e.abs(),0,3,1),t.s*=e.s):t=N(r,e,0,n.modulo,1),t=t.times(e),x=!0,r.minus(t))};m.naturalExponential=m.exp=function(){return ot(this)};m.naturalLogarithm=m.ln=function(){return ce(this)};m.negated=m.neg=function(){var e=new this.constructor(this);return e.s=-e.s,b(e)};m.plus=m.add=function(e){var t,r,n,i,o,s,a,c,u,l,f=this,d=f.constructor;if(e=new d(e),!f.d||!e.d)return!f.s||!e.s?e=new d(NaN):f.d||(e=new d(e.d||f.s===e.s?f:NaN)),e;if(f.s!=e.s)return e.s=-e.s,f.minus(e);if(u=f.d,l=e.d,a=d.precision,c=d.rounding,!u[0]||!l[0])return l[0]||(e=new d(f)),x?b(e,a,c):e;if(o=H(f.e/T),n=H(e.e/T),u=u.slice(),i=o-n,i){for(i<0?(r=u,i=-i,s=l.length):(r=l,n=o,s=u.length),o=Math.ceil(a/T),s=o>s?o+1:s+1,i>s&&(i=s,r.length=1),r.reverse();i--;)r.push(0);r.reverse()}for(s=u.length,i=l.length,s-i<0&&(i=s,r=l,l=u,u=r),t=0;i;)t=(u[--i]=u[i]+l[i]+t)/ee|0,u[i]%=ee;for(t&&(u.unshift(t),++n),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=Ue(u,n),x?b(e,a,c):e};m.precision=m.sd=function(e){var t,r=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(le+e);return r.d?(t=Ot(r.d),e&&r.e+1>t&&(t=r.e+1)):t=NaN,t};m.round=function(){var e=this,t=e.constructor;return b(new t(e),e.e+1,t.rounding)};m.sine=m.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())+T,n.rounding=1,r=Cr(n,Ht(n,r)),n.precision=e,n.rounding=t,b(ie>2?r.neg():r,e,t,!0)):new n(NaN)};m.squareRoot=m.sqrt=function(){var e,t,r,n,i,o,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(x=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=q(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=H((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 l(t)):n=new l(u.toString()),r=(c=l.precision)+3;;)if(o=n,n=o.plus(N(s,o,r+2,1)).times(.5),q(o.d).slice(0,r)===(t=q(n.d)).slice(0,r))if(t=t.slice(r-3,r+1),t=="9999"||!i&&t=="4999"){if(!i&&(b(o,c+1,0),o.times(o).eq(s))){n=o;break}r+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(b(n,c+1,1),e=!n.times(n).eq(s));break}return x=!0,b(n,c,l.rounding,e)};m.tangent=m.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=N(r,new n(1).minus(r.times(r)).sqrt(),e+10,0),n.precision=e,n.rounding=t,b(ie==2||ie==4?r.neg():r,e,t,!0)):new n(NaN)};m.times=m.mul=function(e){var t,r,n,i,o,s,a,c,u,l=this,f=l.constructor,d=l.d,g=(e=new f(e)).d;if(e.s*=l.s,!d||!d[0]||!g||!g[0])return new f(!e.s||d&&!d[0]&&!g||g&&!g[0]&&!d?NaN:!d||!g?e.s/0:e.s*0);for(r=H(l.e/T)+H(e.e/T),c=d.length,u=g.length,c<u&&(o=d,d=g,g=o,s=c,c=u,u=s),o=[],s=c+u,n=s;n--;)o.push(0);for(n=u;--n>=0;){for(t=0,i=c+n;i>n;)a=o[i]+g[n]*d[i-n-1]+t,o[i--]=a%ee|0,t=a/ee|0;o[i]=(o[i]+t)%ee|0}for(;!o[--s];)o.pop();return t?++r:o.shift(),e.d=o,e.e=Ue(o,r),x?b(e,f.precision,f.rounding):e};m.toBinary=function(e,t){return at(this,2,e,t)};m.toDecimalPlaces=m.toDP=function(e,t){var r=this,n=r.constructor;return r=new n(r),e===void 0?r:(Y(e,0,fe),t===void 0?t=n.rounding:Y(t,0,8),b(r,e+r.e+1,t))};m.toExponential=function(e,t){var r,n=this,i=n.constructor;return e===void 0?r=re(n,!0):(Y(e,0,fe),t===void 0?t=i.rounding:Y(t,0,8),n=b(new i(n),e+1,t),r=re(n,!0,e+1)),n.isNeg()&&!n.isZero()?"-"+r:r};m.toFixed=function(e,t){var r,n,i=this,o=i.constructor;return e===void 0?r=re(i):(Y(e,0,fe),t===void 0?t=o.rounding:Y(t,0,8),n=b(new o(i),e+i.e+1,t),r=re(n,!1,e+n.e+1)),i.isNeg()&&!i.isZero()?"-"+r:r};m.toFraction=function(e){var t,r,n,i,o,s,a,c,u,l,f,d,g=this,w=g.d,h=g.constructor;if(!w)return new h(g);if(u=r=new h(1),n=c=new h(0),t=new h(n),o=t.e=Ot(w)-g.e-1,s=o%T,t.d[0]=D(10,s<0?T+s:s),e==null)e=o>0?t:u;else{if(a=new h(e),!a.isInt()||a.lt(u))throw Error(le+a);e=a.gt(t)?o>0?t:u:a}for(x=!1,a=new h(q(w)),l=h.precision,h.precision=o=w.length*T*2;f=N(a,t,0,1,1),i=r.plus(f.times(n)),i.cmp(e)!=1;)r=n,n=i,i=u,u=c.plus(f.times(i)),c=i,i=t,t=a.minus(f.times(i)),a=i;return i=N(e.minus(r),n,0,1,1),c=c.plus(i.times(u)),r=r.plus(i.times(n)),c.s=u.s=g.s,d=N(u,n,o,1).minus(g).abs().cmp(N(c,r,o,1).minus(g).abs())<1?[u,n]:[c,r],h.precision=l,x=!0,d};m.toHexadecimal=m.toHex=function(e,t){return at(this,16,e,t)};m.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:Y(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]?(x=!1,r=N(r,e,0,t,1).times(e),x=!0,b(r)):(e.s=r.s,r=e),r};m.toNumber=function(){return+this};m.toOctal=function(e,t){return at(this,8,e,t)};m.toPower=m.pow=function(e){var t,r,n,i,o,s,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(D(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,o=c.rounding,e.eq(1))return b(a,n,o);if(t=H(e.e/T),t>=e.d.length-1&&(r=u<0?-u:u)<=Lr)return i=Ut(c,a,r,n),e.s<0?new c(1).div(i):b(i,n,o);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return r=D(+a,u),t=r==0||!isFinite(r)?H(u*(Math.log("0."+q(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):(x=!1,c.rounding=a.s=1,r=Math.min(12,(t+"").length),i=ot(e.times(ce(a,n+r)),n),i.d&&(i=b(i,n+5,1),Be(i.d,n,o)&&(t=n+10,i=b(ot(e.times(ce(a,t+r)),t),t+5,1),+q(i.d).slice(n+1,n+15)+1==1e14&&(i=b(i,n+1,0)))),i.s=s,x=!0,c.rounding=o,b(i,n,o))};m.toPrecision=function(e,t){var r,n=this,i=n.constructor;return e===void 0?r=re(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(Y(e,1,fe),t===void 0?t=i.rounding:Y(t,0,8),n=b(new i(n),e,t),r=re(n,e<=n.e||n.e<=i.toExpNeg,e)),n.isNeg()&&!n.isZero()?"-"+r:r};m.toSignificantDigits=m.toSD=function(e,t){var r=this,n=r.constructor;return e===void 0?(e=n.precision,t=n.rounding):(Y(e,1,fe),t===void 0?t=n.rounding:Y(t,0,8)),b(new n(r),e,t)};m.toString=function(){var e=this,t=e.constructor,r=re(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+r:r};m.truncated=m.trunc=function(){return b(new this.constructor(this),this.e+1,1)};m.valueOf=m.toJSON=function(){var e=this,t=e.constructor,r=re(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+r:r};function q(e){var t,r,n,i=e.length-1,o="",s=e[0];if(i>0){for(o+=s,t=1;t<i;t++)n=e[t]+"",r=T-n.length,r&&(o+=ue(r)),o+=n;s=e[t],n=s+"",r=T-n.length,r&&(o+=ue(r))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function Y(e,t,r){if(e!==~~e||e<t||e>r)throw Error(le+e)}function Be(e,t,r,n){var i,o,s,a;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=T,i=0):(i=Math.ceil((t+1)/T),t%=T),o=D(10,T-t),a=e[i]%o|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==o||r>3&&a+1==o/2)&&(e[i+1]/o/100|0)==D(10,t-2)-1||(a==o/2||a==0)&&(e[i+1]/o/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(n||r<4)&&a==9999||!n&&r>3&&a==4999):s=((n||r<4)&&a+1==o||!n&&r>3&&a+1==o/2)&&(e[i+1]/o/1e3|0)==D(10,t-3)-1,s}function Ee(e,t,r){for(var n,i=[0],o,s=0,a=e.length;s<a;){for(o=i.length;o--;)i[o]*=t;for(i[0]+=rt.indexOf(e.charAt(s++)),n=0;n<i.length;n++)i[n]>r-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/r|0,i[n]%=r)}return i.reverse()}function Br(e,t){var r,n,i;if(t.isZero())return t;n=t.d.length,n<32?(r=Math.ceil(n/3),i=(1/qe(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),e.precision+=r,t=Pe(e,1,t.times(i),new e(1));for(var o=r;o--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=r,t}var N=function(){function e(n,i,o){var s,a=0,c=n.length;for(n=n.slice();c--;)s=n[c]*i+a,n[c]=s%o|0,a=s/o|0;return a&&n.unshift(a),n}function t(n,i,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(n[a]!=i[a]){c=n[a]>i[a]?1:-1;break}return c}function r(n,i,o,s){for(var a=0;o--;)n[o]-=a,a=n[o]<i[o]?1:0,n[o]=a*s+n[o]-i[o];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,o,s,a,c){var u,l,f,d,g,w,h,v,C,O,I,F,ae,j,de,Ie,he,be,X,we,Me=n.constructor,$e=n.s==i.s?1:-1,G=n.d,K=i.d;if(!G||!G[0]||!K||!K[0])return new Me(!n.s||!i.s||(G?K&&G[0]==K[0]:!K)?NaN:G&&G[0]==0||!K?$e*0:$e/0);for(c?(g=1,l=n.e-i.e):(c=ee,g=T,l=H(n.e/g)-H(i.e/g)),X=K.length,he=G.length,C=new Me($e),O=C.d=[],f=0;K[f]==(G[f]||0);f++);if(K[f]>(G[f]||0)&&l--,o==null?(j=o=Me.precision,s=Me.rounding):a?j=o+(n.e-i.e)+1:j=o,j<0)O.push(1),w=!0;else{if(j=j/g+2|0,f=0,X==1){for(d=0,K=K[0],j++;(f<he||d)&&j--;f++)de=d*c+(G[f]||0),O[f]=de/K|0,d=de%K|0;w=d||f<he}else{for(d=c/(K[0]+1)|0,d>1&&(K=e(K,d,c),G=e(G,d,c),X=K.length,he=G.length),Ie=X,I=G.slice(0,X),F=I.length;F<X;)I[F++]=0;we=K.slice(),we.unshift(0),be=K[0],K[1]>=c/2&&++be;do d=0,u=t(K,I,X,F),u<0?(ae=I[0],X!=F&&(ae=ae*c+(I[1]||0)),d=ae/be|0,d>1?(d>=c&&(d=c-1),h=e(K,d,c),v=h.length,F=I.length,u=t(h,I,v,F),u==1&&(d--,r(h,X<v?we:K,v,c))):(d==0&&(u=d=1),h=K.slice()),v=h.length,v<F&&h.unshift(0),r(I,h,F,c),u==-1&&(F=I.length,u=t(K,I,X,F),u<1&&(d++,r(I,X<F?we:K,F,c))),F=I.length):u===0&&(d++,I=[0]),O[f++]=d,u&&I[0]?I[F++]=G[Ie]||0:(I=[G[Ie]],F=1);while((Ie++<he||I[0]!==void 0)&&j--);w=I[0]!==void 0}O[0]||O.shift()}if(g==1)C.e=l,Mt=w;else{for(f=1,d=O[0];d>=10;d/=10)f++;C.e=f+l*g-1,b(C,a?o+C.e+1:o,s,w)}return C}}();function b(e,t,r,n){var i,o,s,a,c,u,l,f,d,g=e.constructor;e:if(t!=null){if(f=e.d,!f)return e;for(i=1,a=f[0];a>=10;a/=10)i++;if(o=t-i,o<0)o+=T,s=t,l=f[d=0],c=l/D(10,i-s-1)%10|0;else if(d=Math.ceil((o+1)/T),a=f.length,d>=a)if(n){for(;a++<=d;)f.push(0);l=c=0,i=1,o%=T,s=o-T+1}else break e;else{for(l=a=f[d],i=1;a>=10;a/=10)i++;o%=T,s=o-T+i,c=s<0?0:l/D(10,i-s-1)%10|0}if(n=n||t<0||f[d+1]!==void 0||(s<0?l:l%D(10,i-s-1)),u=r<4?(c||n)&&(r==0||r==(e.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(o>0?s>0?l/D(10,i-s):0:f[d-1])%10&1||r==(e.s<0?8:7)),t<1||!f[0])return f.length=0,u?(t-=e.e+1,f[0]=D(10,(T-t%T)%T),e.e=-t||0):f[0]=e.e=0,e;if(o==0?(f.length=d,a=1,d--):(f.length=d+1,a=D(10,T-o),f[d]=s>0?(l/D(10,i-s)%D(10,s)|0)*a:0),u)for(;;)if(d==0){for(o=1,s=f[0];s>=10;s/=10)o++;for(s=f[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(e.e++,f[0]==ee&&(f[0]=1));break}else{if(f[d]+=a,f[d]!=ee)break;f[d--]=0,a=1}for(o=f.length;f[--o]===0;)f.pop()}return x&&(e.e>g.maxE?(e.d=null,e.e=NaN):e.e<g.minE&&(e.e=0,e.d=[0])),e}function re(e,t,r){if(!e.isFinite())return Gt(e);var n,i=e.e,o=q(e.d),s=o.length;return t?(r&&(n=r-s)>0?o=o.charAt(0)+"."+o.slice(1)+ue(n):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):i<0?(o="0."+ue(-i-1)+o,r&&(n=r-s)>0&&(o+=ue(n))):i>=s?(o+=ue(i+1-s),r&&(n=r-i-1)>0&&(o=o+"."+ue(n))):((n=i+1)<s&&(o=o.slice(0,n)+"."+o.slice(n)),r&&(n=r-s)>0&&(i+1===s&&(o+="."),o+=ue(n))),o}function Ue(e,t){var r=e[0];for(t*=T;r>=10;r/=10)t++;return t}function We(e,t,r){if(t>Ir)throw x=!0,r&&(e.precision=r),Error(Et);return b(new e(Fe),t,1,!0)}function $(e,t,r){if(t>it)throw Error(Et);return b(new e(De),t,r,!0)}function Ot(e){var t=e.length-1,r=t*T+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 ue(e){for(var t="";e--;)t+="0";return t}function Ut(e,t,r,n){var i,o=new e(1),s=Math.ceil(n/T+4);for(x=!1;;){if(r%2&&(o=o.times(t),Vt(o.d,s)&&(i=!0)),r=H(r/2),r===0){r=o.d.length-1,i&&o.d[r]===0&&++o.d[r];break}t=t.times(t),Vt(t.d,s)}return x=!0,o}function Kt(e){return e.d[e.d.length-1]&1}function qt(e,t,r){for(var n,i=new e(t[0]),o=0;++o<t.length;)if(n=new e(t[o]),n.s)i[r](n)&&(i=n);else{i=n;break}return i}function ot(e,t){var r,n,i,o,s,a,c,u=0,l=0,f=0,d=e.constructor,g=d.rounding,w=d.precision;if(!e.d||!e.d[0]||e.e>17)return new d(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(x=!1,c=w):c=t,a=new d(.03125);e.e>-2;)e=e.times(a),f+=5;for(n=Math.log(D(2,f))/Math.LN10*2+5|0,c+=n,r=o=s=new d(1),d.precision=c;;){if(o=b(o.times(e),c,1),r=r.times(++l),a=s.plus(N(o,r,c,1)),q(a.d).slice(0,c)===q(s.d).slice(0,c)){for(i=f;i--;)s=b(s.times(s),c,1);if(t==null)if(u<3&&Be(s.d,c-n,g,u))d.precision=c+=10,r=o=a=new d(1),l=0,u++;else return b(s,d.precision=w,g,x=!0);else return d.precision=w,s}s=a}}function ce(e,t){var r,n,i,o,s,a,c,u,l,f,d,g=1,w=10,h=e,v=h.d,C=h.constructor,O=C.rounding,I=C.precision;if(h.s<0||!v||!v[0]||!h.e&&v[0]==1&&v.length==1)return new C(v&&!v[0]?-1/0:h.s!=1?NaN:v?0:h);if(t==null?(x=!1,l=I):l=t,C.precision=l+=w,r=q(v),n=r.charAt(0),Math.abs(o=h.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)h=h.times(e),r=q(h.d),n=r.charAt(0),g++;o=h.e,n>1?(h=new C("0."+r),o++):h=new C(n+"."+r.slice(1))}else return u=We(C,l+2,I).times(o+""),h=ce(new C(n+"."+r.slice(1)),l-w).plus(u),C.precision=I,t==null?b(h,I,O,x=!0):h;for(f=h,c=s=h=N(h.minus(1),h.plus(1),l,1),d=b(h.times(h),l,1),i=3;;){if(s=b(s.times(d),l,1),u=c.plus(N(s,new C(i),l,1)),q(u.d).slice(0,l)===q(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(We(C,l+2,I).times(o+""))),c=N(c,new C(g),l,1),t==null)if(Be(c.d,l-w,O,a))C.precision=l+=w,u=s=h=N(f.minus(1),f.plus(1),l,1),d=b(h.times(h),l,1),i=a=1;else return b(c,C.precision=I,O,x=!0);else return C.precision=I,c;c=u,i+=2}}function Gt(e){return String(e.s*e.s/0)}function st(e,t){var r,n,i;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(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(n,i),t){if(i-=n,e.e=r=r-n-1,e.d=[],n=(r+1)%T,r<0&&(n+=T),n<i){for(n&&e.d.push(+t.slice(0,n)),i-=T;n<i;)e.d.push(+t.slice(n,n+=T));t=t.slice(n),n=T-t.length}else n-=i;for(;n--;)t+="0";e.d.push(+t),x&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Rr(e,t){var r,n,i,o,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Wt.test(t))return st(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(kr.test(t))r=16,t=t.toLowerCase();else if(Sr.test(t))r=2;else if(Ar.test(t))r=8;else throw Error(le+t);for(o=t.search(/p/i),o>0?(c=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),s=o>=0,n=e.constructor,s&&(t=t.replace(".",""),a=t.length,o=a-o,i=Ut(n,new n(r),o,o*2)),u=Ee(t,r,ee),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new n(e.s*0):(e.e=Ue(u,l),e.d=u,x=!1,s&&(e=N(e,i,a*4)),c&&(e=e.times(Math.abs(c)<54?D(2,c):Ge.pow(2,c))),x=!0,e)}function Cr(e,t){var r,n=t.d.length;if(n<3)return t.isZero()?t:Pe(e,2,t,t);r=1.4*Math.sqrt(n),r=r>16?16:r|0,t=t.times(1/qe(5,r)),t=Pe(e,2,t,t);for(var i,o=new e(5),s=new e(16),a=new e(20);r--;)i=t.times(t),t=t.times(o.plus(i.times(s.times(i).minus(a))));return t}function Pe(e,t,r,n,i){var o,s,a,c,u=1,l=e.precision,f=Math.ceil(l/T);for(x=!1,c=r.times(r),a=new e(n);;){if(s=N(a.times(c),new e(t++*t++),l,1),a=i?n.plus(s):n.minus(s),n=N(s.times(c),new e(t++*t++),l,1),s=a.plus(n),s.d[f]!==void 0){for(o=f;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=n,n=s,s=o,u++}return x=!0,s.d.length=f+1,s}function qe(e,t){for(var r=e;--t;)r*=e;return r}function Ht(e,t){var r,n=t.s<0,i=$(e,e.precision,1),o=i.times(.5);if(t=t.abs(),t.lte(o))return ie=n?4:1,t;if(r=t.divToInt(i),r.isZero())ie=n?3:2;else{if(t=t.minus(r.times(i)),t.lte(o))return ie=Kt(r)?n?2:3:n?4:1,t;ie=Kt(r)?n?1:4:n?3:2}return t.minus(i).abs()}function at(e,t,r,n){var i,o,s,a,c,u,l,f,d,g=e.constructor,w=r!==void 0;if(w?(Y(r,1,fe),n===void 0?n=g.rounding:Y(n,0,8)):(r=g.precision,n=g.rounding),!e.isFinite())l=Gt(e);else{for(l=re(e),s=l.indexOf("."),w?(i=2,t==16?r=r*4-3:t==8&&(r=r*3-2)):i=t,s>=0&&(l=l.replace(".",""),d=new g(1),d.e=l.length-s,d.d=Ee(re(d),10,i),d.e=d.d.length),f=Ee(l,10,i),o=c=f.length;f[--c]==0;)f.pop();if(!f[0])l=w?"0p+0":"0";else{if(s<0?o--:(e=new g(e),e.d=f,e.e=o,e=N(e,d,r,n,0,i),f=e.d,o=e.e,u=Mt),s=f[r],a=i/2,u=u||f[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&&f[r-1]&1||n===(e.s<0?8:7)),f.length=r,u)for(;++f[--r]>i-1;)f[r]=0,r||(++o,f.unshift(1));for(c=f.length;!f[c-1];--c);for(s=0,l="";s<c;s++)l+=rt.charAt(f[s]);if(w){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(f=Ee(l,i,t),c=f.length;!f[c-1];--c);for(s=1,l="1.";s<c;s++)l+=rt.charAt(f[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function Vt(e,t){if(e.length>t)return e.length=t,!0}function vr(e){return new this(e).abs()}function Nr(e){return new this(e).acos()}function Kr(e){return new this(e).acosh()}function Vr(e,t){return new this(e).plus(t)}function _r(e){return new this(e).asin()}function Mr(e){return new this(e).asinh()}function Er(e){return new this(e).atan()}function Fr(e){return new this(e).atanh()}function Dr(e,t){e=new this(e),t=new this(t);var r,n=this.precision,i=this.rounding,o=n+4;return!e.s||!t.s?r=new this(NaN):!e.d&&!t.d?(r=$(this,o,1).times(t.s>0?.25:.75),r.s=e.s):!t.d||e.isZero()?(r=t.s<0?$(this,n,i):new this(0),r.s=e.s):!e.d||t.isZero()?(r=$(this,o,1).times(.5),r.s=e.s):t.s<0?(this.precision=o,this.rounding=1,r=this.atan(N(e,t,o,1)),t=$(this,o,1),this.precision=n,this.rounding=i,r=e.s<0?r.minus(t):r.plus(t)):r=this.atan(N(e,t,o,1)),r}function Wr(e){return new this(e).cbrt()}function Or(e){return b(e=new this(e),e.e+1,2)}function Ur(e,t,r){return new this(e).clamp(t,r)}function qr(e){if(!e||typeof e!="object")throw Error(Oe+"Object expected");var t,r,n,i=e.defaults===!0,o=["precision",1,fe,"rounding",0,8,"toExpNeg",-Te,0,"toExpPos",0,Te,"maxE",0,Te,"minE",-Te,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(r=o[t],i&&(this[r]=nt[r]),(n=e[r])!==void 0)if(H(n)===n&&n>=o[t+1]&&n<=o[t+2])this[r]=n;else throw Error(le+r+": "+n);if(r="crypto",i&&(this[r]=nt[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(Ft);else this[r]=!1;else throw Error(le+r+": "+n);return this}function Gr(e){return new this(e).cos()}function Hr(e){return new this(e).cosh()}function jt(e){var t,r,n;function i(o){var s,a,c,u=this;if(!(u instanceof i))return new i(o);if(u.constructor=i,_t(o)){u.s=o.s,x?!o.d||o.e>i.maxE?(u.e=NaN,u.d=null):o.e<i.minE?(u.e=0,u.d=[0]):(u.e=o.e,u.d=o.d.slice()):(u.e=o.e,u.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){u.s=1/o<0?-1:1,u.e=0,u.d=[0];return}if(o<0?(o=-o,u.s=-1):u.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;x?s>i.maxE?(u.e=NaN,u.d=null):s<i.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[o]):(u.e=s,u.d=[o]);return}else if(o*0!==0){o||(u.s=NaN),u.e=NaN,u.d=null;return}return st(u,o.toString())}else if(c!=="string")throw Error(le+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),Wt.test(o)?st(u,o):Rr(u,o)}if(i.prototype=m,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=qr,i.clone=jt,i.isDecimal=_t,i.abs=vr,i.acos=Nr,i.acosh=Kr,i.add=Vr,i.asin=_r,i.asinh=Mr,i.atan=Er,i.atanh=Fr,i.atan2=Dr,i.cbrt=Wr,i.ceil=Or,i.clamp=Ur,i.cos=Gr,i.cosh=Hr,i.div=jr,i.exp=zr,i.floor=Yr,i.hypot=Zr,i.ln=Xr,i.log=Jr,i.log10=$r,i.log2=Qr,i.max=en,i.min=tn,i.mod=rn,i.mul=nn,i.pow=on,i.random=sn,i.round=an,i.sign=un,i.sin=cn,i.sinh=ln,i.sqrt=fn,i.sub=dn,i.sum=pn,i.tan=mn,i.tanh=gn,i.trunc=yn,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 i.config(e),i}function jr(e,t){return new this(e).div(t)}function zr(e){return new this(e).exp()}function Yr(e){return b(e=new this(e),e.e+1,3)}function Zr(){var e,t,r=new this(0);for(x=!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 x=!0,new this(1/0);r=t}return x=!0,r.sqrt()}function _t(e){return e instanceof Ge||e&&e.toStringTag===Dt||!1}function Xr(e){return new this(e).ln()}function Jr(e,t){return new this(e).log(t)}function Qr(e){return new this(e).log(2)}function $r(e){return new this(e).log(10)}function en(){return qt(this,arguments,"lt")}function tn(){return qt(this,arguments,"gt")}function rn(e,t){return new this(e).mod(t)}function nn(e,t){return new this(e).mul(t)}function on(e,t){return new this(e).pow(t)}function sn(e){var t,r,n,i,o=0,s=new this(1),a=[];if(e===void 0?e=this.precision:Y(e,1,fe),n=Math.ceil(e/T),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));o<n;)i=t[o],i>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(n*=4);o<n;)i=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,o):(a.push(i%1e7),o+=4);o=n/4}else throw Error(Ft);else for(;o<n;)a[o++]=Math.random()*1e7|0;for(n=a[--o],e%=T,n&&e&&(i=D(10,T-e),a[o]=(n/i|0)*i);a[o]===0;o--)a.pop();if(o<0)r=0,a=[0];else{for(r=-1;a[0]===0;r-=T)a.shift();for(n=1,i=a[0];i>=10;i/=10)n++;n<T&&(r-=T-n)}return s.e=r,s.d=a,s}function an(e){return b(e=new this(e),e.e+1,this.rounding)}function un(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function cn(e){return new this(e).sin()}function ln(e){return new this(e).sinh()}function fn(e){return new this(e).sqrt()}function dn(e,t){return new this(e).sub(t)}function pn(){var e=0,t=arguments,r=new this(t[e]);for(x=!1;r.s&&++e<t.length;)r=r.plus(t[e]);return x=!0,b(r,this.precision,this.rounding)}function mn(e){return new this(e).tan()}function gn(e){return new this(e).tanh()}function yn(e){return b(e=new this(e),e.e+1,1)}m[Symbol.for("nodejs.util.inspect.custom")]=m.toString;m[Symbol.toStringTag]="Decimal";var Ge=m.constructor=jt(nt);Fe=new Ge(Fe);De=new Ge(De);import kn from"big.js";import to from"bn.js";import hn from"toformat";var bn=hn,Re=bn;import je from"big.js";import Tn from"bn.js";import Pn from"decimal.js-light";import Ce from"bn.js";var zt=9007199254740991;function _(e){let t=U("Raydium_parseBigNumberish");if(e instanceof Ce)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new Ce(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=zt||e<=-zt)&&t.logWithError(`BigNumberish number overflow: ${e}`),new Ce(String(e))):typeof e=="bigint"?new Ce(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new Ce(0))}var He=U("module/fraction"),ut=Re(je),ve=Re(Pn),xn={[0]:ve.ROUND_DOWN,[1]:ve.ROUND_HALF_UP,[2]:ve.ROUND_UP},Sn={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},V=class{constructor(t,r=new Tn(1)){this.numerator=_(t),this.denominator=_(r)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new V(this.denominator,this.numerator)}add(t){let r=t instanceof V?t:new V(_(t));return this.denominator.eq(r.denominator)?new V(this.numerator.add(r.numerator),this.denominator):new V(this.numerator.mul(r.denominator).add(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}sub(t){let r=t instanceof V?t:new V(_(t));return this.denominator.eq(r.denominator)?new V(this.numerator.sub(r.numerator),this.denominator):new V(this.numerator.mul(r.denominator).sub(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}mul(t){let r=t instanceof V?t:new V(_(t));return new V(this.numerator.mul(r.numerator),this.denominator.mul(r.denominator))}div(t){let r=t instanceof V?t:new V(_(t));return new V(this.numerator.mul(r.denominator),this.denominator.mul(r.numerator))}toSignificant(t,r={groupSeparator:""},n=1){Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<=0&&He.logWithError(`${t} is not positive.`),ve.set({precision:t+1,rounding:xn[n]});let i=new ve(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return i.toFormat(i.decimalPlaces(),r)}toFixed(t,r={groupSeparator:""},n=1){return Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<0&&He.logWithError(`${t} is negative.`),ut.DP=t,ut.RM=Sn[n]||1,new ut(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)}isZero(){return this.numerator.isZero()}};var lo=U("Raydium_amount"),fo=Re(kn);import{PublicKey as Ln}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Yt}from"@solana/spl-token";var Zt={chainId:101,address:Ln.default.toBase58(),programId:Yt.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},pe={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Yt.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};import{PublicKey as ft}from"@solana/web3.js";import{PublicKey as M,SystemProgram as Xt,SYSVAR_RENT_PUBKEY as In}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Bn}from"@solana/spl-token";function p({pubkey:e,isSigner:t=!1,isWritable:r=!0}){return{pubkey:e,isWritable:r,isSigner:t}}var ct=[p({pubkey:Bn,isWritable:!1}),p({pubkey:Xt.programId,isWritable:!1}),p({pubkey:In,isWritable:!1})];function Jt({publicKey:e,transformSol:t}){let r=Qt(e.toString());if(r instanceof M)return t&&r.equals(me)?tt:r;if(t&&r.toString()===me.toBase58())return tt;if(typeof r=="string"){if(r===M.default.toBase58())return M.default;try{return new M(r)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Qt(e){try{return new M(e)}catch{return e}}var To=new M("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Po=new M("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),lt=new M("SysvarRent111111111111111111111111111111111"),xo=new M("SysvarC1ock11111111111111111111111111111111"),So=new M("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),ze=new M("Sysvar1nstructions1111111111111111111111111"),ko=Xt.programId,Ao=new M("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Lo=new M("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Io=new M("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Bo=new M("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Ro=new M("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Co=new M("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),vo=new M("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),No=new M("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ko=new M("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Vo=new M("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),_o=new M("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),tt=new M("So11111111111111111111111111111111111111112"),me=M.default;var dt=class{constructor({mint:t,decimals:r,symbol:n,name:i,skipMint:o=!1,isToken2022:s=!1}){if(t===me.toBase58()||t instanceof ft&&me.equals(t)){this.decimals=pe.decimals,this.symbol=pe.symbol,this.name=pe.name,this.mint=new ft(pe.address),this.isToken2022=!1;return}this.decimals=r,this.symbol=n||t.toString().substring(0,6),this.name=i||t.toString().substring(0,6),this.mint=o?ft.default:Jt({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},xe=dt;xe.WSOL=new dt(Q(J({},pe),{mint:pe.address}));var pt=class{constructor({decimals:t,symbol:r="UNKNOWN",name:n="UNKNOWN"}){this.decimals=t,this.symbol=r,this.name=n}equals(t){return this===t}},Ye=pt;Ye.SOL=new pt(Zt);import Rn from"bn.js";var zo=new V(new Rn(100));var $o=U("Raydium_price");import{PublicKey as ys}from"@solana/web3.js";import bs from"bn.js";var Cn=new oe(0),Es=new oe(1),Fs=new oe(2),Ds=new oe(3),Ws=new oe(5),An=new oe(10),Os=new oe(100),Us=new oe(1e3),qs=new oe(1e4);import{PublicKey as Nn}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Kn}from"@solana/spl-token";import{ComputeBudgetProgram as Js,Keypair as ea,PublicKey as vn,Transaction as ra,TransactionMessage as ia,VersionedTransaction as oa}from"@solana/web3.js";var Se={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",ClmmLockPosition:"ClmmLockPosition",ClmmHarvestLockPosition:"ClmmHarvestLockPosition",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV4Withdraw:"FarmV4Withdraw",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut",CpmmLockLp:"CpmmLockLp",CpmmCollectLockFee:"CpmmCollectLockFee",TransferTip:"TransferTip"};import{TOKEN_PROGRAM_ID as ca}from"@solana/spl-token";var la=U("Raydium_txUtil");function te(e,t){let[r,n]=vn.findProgramAddressSync(e,t);return{publicKey:r,nonce:n}}function Ne(e,t,r){return te([e.toBuffer(),(r!=null?r:Kn).toBuffer(),t.toBuffer()],new Nn("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as S}from"@solana/web3.js";var rr=new S("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),nr=new S("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),ir=new S("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),or=new S("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),ha=new S("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ba=new S("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),wa=new S("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Ta=new S("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Pa=new S("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),xa=new S("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Sa=new S("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),ka=new S("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Aa=new S("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),La=new S("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ia=new S("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Ba=new S("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Ra=new S("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Ca=new S("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),va=new S("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Na=new S("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Ka=new S("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Va=new S("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),Vn=new S("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),_n=new S("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),Mn=new S("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),_a=new S("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),En=new S("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Ma=new S("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),Fn=new S("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var Ea={SERUM_MARKET:S.default,OPENBOOK_MARKET:new S("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:S.default,FarmV3:new S("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new S("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new S("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new S("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new S("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new S("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new S("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new S("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new S("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:Vn,CREATE_CPMM_POOL_AUTH:_n,CREATE_CPMM_POOL_FEE_ACC:Mn,FEE_DESTINATION_ID:new S("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:En,LCOK_CPMM_AUTH:Fn};import Wa from"bn.js";import{PublicKey as Dn,AddressLookupTableAccount as sr}from"@solana/web3.js";var Wn={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new sr({key:new Dn("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:sr.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"))})};import{PublicKey as ou,sendAndConfirmTransaction as su,SystemProgram as cu,Transaction as lu,TransactionMessage as du,VersionedTransaction as pu}from"@solana/web3.js";import gu from"axios";import{PublicKey as zn}from"@solana/web3.js";import lr,{isBN as fr}from"bn.js";import{bits as Wu,BitStructure as Ou,blob as On,Blob as Uu,cstr as qu,f32 as Gu,f32be as Hu,f64 as ju,f64be as zu,greedy as Yu,Layout as Un,ns64 as Zu,ns64be as Xu,nu64 as Ju,nu64be as Qu,offset as $u,s16 as ec,s16be as tc,s24 as rc,s24be as nc,s32 as ic,s32be as oc,s40 as sc,s40be as ac,s48 as uc,s48be as cc,s8 as lc,seq as qn,struct as fc,Structure as Gn,u16 as dc,u16be as pc,u24 as mc,u24be as gc,u32 as yc,u32be as hc,u40 as bc,u40be as wc,u48 as Tc,u48be as Pc,u8 as Hn,UInt as jn,union as xc,Union as Sc,unionLayoutDiscriminator as kc,utf8 as Ac}from"@solana/buffer-layout";var mt=Un,ar=Gn;var gt=jn;var ur=Hn;var cr=qn;var ge=On;var ke=class extends mt{constructor(r,n,i){super(r,i);this.blob=ge(r),this.signed=n}decode(r,n=0){let i=new lr(this.blob.decode(r,n),10,"le");return this.signed?i.fromTwos(this.span*8).clone():i}encode(r,n,i=0){return typeof r=="number"&&(r=new lr(r)),this.signed&&(r=r.toTwos(this.span*8)),this.blob.encode(r.toArrayLike(Buffer,"le",this.span),n,i)}};function R(e){return new gt(1,e)}function Ae(e){return new gt(4,e)}function y(e){return new ke(8,!1,e)}function se(e){return new ke(16,!1,e)}function dr(e){return new ke(1,!0,e)}function Xe(e){return new ke(8,!0,e)}var Ze=class extends mt{constructor(r,n,i,o){super(r.span,o);this.layout=r,this.decoder=n,this.encoder=i}decode(r,n){return this.decoder(this.layout.decode(r,n))}encode(r,n,i){return this.layout.encode(this.encoder(r),n,i)}getSpan(r,n){return this.layout.getSpan(r,n)}};function k(e){return new Ze(ge(32),t=>new zn(t),t=>t.toBuffer(),e)}function Ke(e){return new Ze(ur(),Yn,Zn,e)}function Yn(e){if(e===0)return!1;if(e===1)return!0;throw new Error("Invalid bool: "+e)}function Zn(e){return e?1:0}var yt=class extends ar{decode(t,r){return super.decode(t,r)}};function B(e,t,r){return new yt(e,t,r)}function E(e,t,r){let n,i=typeof t=="number"?t:fr(t)?t.toNumber():new Proxy(t,{get(o,s){if(!n){let a=Reflect.get(o,"count");n=fr(a)?a.toNumber():a,Reflect.set(o,"count",n)}return Reflect.get(o,s)},set(o,s,a){return s==="count"&&(n=a),Reflect.set(o,s,a)}});return cr(e,i,r)}import{PublicKey as gr}from"@solana/web3.js";var ht=B([R("instruction")]),bt=B([R("instruction")]),Xn=B([y("rewardState"),y("rewardOpenTime"),y("rewardEndTime"),y("rewardLastUpdateTime"),y("totalReward"),y("totalRewardEmissioned"),y("rewardClaimed"),y("rewardPerSecond"),se("accRewardPerShare"),k("rewardVault"),k("rewardMint"),k("rewardSender"),y("rewardType"),E(y(),15,"padding")]),Jn=B([y("state"),y("nonce"),k("lpVault"),k("rewardVault"),k(),k(),y(),y(),y("totalReward"),se("perShareReward"),y("lastSlot"),y("perSlotReward")]),Qn=B([y("state"),y("nonce"),k("lpVault"),k("rewardVaultA"),y("totalRewardA"),se("perShareRewardA"),y("perSlotRewardA"),R("option"),k("rewardVaultB"),ge(7),y("totalRewardB"),se("perShareRewardB"),y("perSlotRewardB"),y("lastSlot"),k()]),$n=B([y(),y("state"),y("nonce"),y("validRewardTokenNum"),se("rewardMultiplier"),y("rewardPeriodMax"),y("rewardPeriodMin"),y("rewardPeriodExtend"),k("lpMint"),k("lpVault"),E(Xn,5,"rewardInfos"),k("creator"),k(),E(y(),32,"padding")]),ei=new Proxy(Jn,{get(e,t,r){return t==="decode"?(...n)=>{let i=e.decode(...n);return Q(J({},i),{version:3,rewardInfos:[{rewardVault:i.rewardVault,totalReward:i.totalReward,perSlotReward:i.perSlotReward,perShareReward:i.perShareReward}]})}:Reflect.get(e,t,r)}}),ti=new Proxy(Qn,{get(e,t,r){return t==="decode"?(...n)=>{let i=e.decode(...n);return Q(J({},i),{version:5,rewardInfos:[{rewardVault:i.rewardVaultA,totalReward:i.totalRewardA,perSlotReward:i.perSlotRewardA,perShareReward:i.perShareRewardA},{rewardVault:i.rewardVaultB,totalReward:i.totalRewardB,perSlotReward:i.perSlotRewardB,perShareReward:i.perShareRewardB}]})}:Reflect.get(e,t,r)}}),ri=new Proxy($n,{get(e,t,r){return t==="decode"?(...n)=>{let i=e.decode(...n);return Q(J({},i),{version:6,rewardInfos:i.rewardInfos.map(o=>{var s;return Q(J({},o),{rewardType:((s=Object.entries(Ve).find(a=>String(a[1])===o.rewardType.toString()))!=null?s:["Standard SPL"])[0]})})})}:Reflect.get(e,t,r)}}),ni=B([y("isSet"),y("rewardPerSecond"),y("rewardOpenTime"),y("rewardEndTime"),y("rewardType")]),wt=B([R("instruction"),y("nonce"),E(ni,5,"rewardTimeInfo")]),Tt=B([R("instruction"),y("rewardReopenTime"),y("rewardEndTime"),y("rewardPerSecond")]),Pt=B([R("instruction"),y("isSet"),y("rewardPerSecond"),y("rewardOpenTime"),y("rewardEndTime"),y("rewardType")]),qc=B([y("state"),k("id"),k("owner"),y("deposited"),E(y(),1,"rewardDebts")]),Je=B([y("state"),k("id"),k("owner"),y("deposited"),E(se(),1,"rewardDebts"),y(""),y("voteLockedBalance"),E(y(),15)]),Gc=B([y("state"),k("id"),k("owner"),y("deposited"),E(y(),2,"rewardDebts")]),ii=B([y("state"),k("id"),k("owner"),y("deposited"),E(se(),2,"rewardDebts"),E(y(),17)]),oi=B([y(),y("state"),k("id"),k("owner"),y("deposited"),E(se(),5,"rewardDebts"),E(y(),16)]),z=B([R("instruction"),y("amount")]),si=B([k("mint"),k("grantAuthority"),y("baselineVoteWeightScaledFactor"),y("maxExtraLockupVoteWeightScaledFactor"),y("lockupSaturationSecs"),dr("digitShift"),E(R(),7,"reserved1"),E(y(),7,"reserved2")]),pr=B([ge(8),k("governanceProgramId"),k("realm"),k("realmGoverningTokenMint"),k("realmAuthority"),E(R(),32,"reserved1"),E(si,4,"votingMints"),Xe("timeOffset"),R("bump"),E(R(),7,"reserved2"),E(y(),11,"reserved3")]),ai=B([Xe("startTime"),Xe("endTime"),R("kind"),E(R(),15,"reserved")]),ui=B([E(ai,1,"lockup"),y("amountDeposited_native"),y("amountInitiallyLockedNative"),Ke("isUsed"),Ke("allowClawback"),R("votingMintConfigIdx"),E(R(),29,"reserved")]),mr=B([ge(8),k("voterAuthority"),k("registrar"),E(ui,32,"deposits"),R("voterBump"),R("voterWweightRecordBump"),E(R(),94,"reserved")]);var Qc=U("Raydium_farm_config"),$c=new gr("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),el=new gr("FrspKwj8i3pNmKwXreTveC4fu7KL5ZbGeXdZBe2XViu1");var Ve={"Standard SPL":0,"Option tokens":1},tl={[rr.toString()]:3,[nr.toString()]:4,[ir.toString()]:5,[or.toString()]:6};function xt(e,t,r){return te([t.toBuffer(),Buffer.from("registrar","utf8"),r.toBuffer()],e)}function St(e,t){return te([t.toBuffer(),Buffer.from("voting_mint_seed","utf8")],e)}function kt(e,t){return te([t.toBuffer()],e)}function At(e,t,r){return te([t.toBuffer(),Buffer.from("voter","utf8"),r.toBuffer()],e)}function Lt(e,t,r){return te([t.toBuffer(),Buffer.from("voter-weight-record","utf8"),r.toBuffer()],e)}function It(e,t,r,n){return te([Buffer.from("governance","utf8"),t.toBuffer(),r.toBuffer(),n.toBuffer()],e)}import ml from"bn.js";var ci=B([k("mint"),k("owner"),y("amount"),Ae("delegateOption"),k("delegate"),R("state"),Ae("isNativeOption"),y("isNative"),y("delegatedAmount"),Ae("closeAuthorityOption"),k("closeAuthority")]);var Il=U("Raydium.farm.util");function ne({programId:e,poolId:t,owner:r,version:n}){let{publicKey:i}=te([t.toBuffer(),r.toBuffer(),Buffer.from(n===6?"farmer_info_associated_seed":"staker_info_v2_associated_seed","utf-8")],e);return i}async function Bt(e,t,r,n){let i=await e.getAccountInfo(t);if(i===null)throw Error("registrar info check error");let s=pr.decode(i.data).votingMints.findIndex(l=>l.mint.equals(n));if(s===-1)throw Error("find voter mint error");let a=await e.getAccountInfo(r);if(a===null)return{index:s,isInit:!1};let u=mr.decode(a.data).deposits.findIndex(l=>l.isUsed&&l.votingMintConfigIdx===s);return u===-1?{index:s,isInit:!1}:{index:u,isInit:!0}}var pi=U("Raydium_farm_instruction"),_e={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 ql(e){let{version:t,id:r,ledger:n,programId:i,owner:o}=e,s={3:9,5:10}[t];s||pi.logWithError(`invalid farm pool version: ${t}`);let a=Buffer.alloc(ht.span);ht.encode({instruction:s},a);let c=[p({pubkey:r}),p({pubkey:n}),p({pubkey:o,isWritable:!1}),p({pubkey:ye.programId,isWritable:!1}),p({pubkey:li,isWritable:!1})];return{instruction:new W({programId:i,keys:c,data:a}),instructionType:Se.FarmV3CreateLedger}}function Gl(e){var n;let t=Buffer.alloc(wt.span);wt.encode({instruction:0,nonce:new Qe(e.nonce),rewardTimeInfo:e.rewardInfoConfig},t);let r=[...ct,p({pubkey:e.farmId}),p({pubkey:e.farmAuthority,isWritable:!1}),p({pubkey:e.lpVault}),p({pubkey:e.lpMint,isWritable:!1}),p({pubkey:e.lockVault}),p({pubkey:e.lockMint,isWritable:!1}),p({pubkey:(n=e.lockUserAccount)!=null?n:me}),p({pubkey:e.owner,isWritable:!1,isSigner:!0})];for(let i of e.rewardInfo)r.push(p({pubkey:i.rewardMint,isWritable:!1}),p({pubkey:i.rewardVault}),p({pubkey:i.userRewardToken}));return{instruction:new W({programId:e.programId,keys:r,data:t}),instructionType:Se.FarmV6Create}}function Hl(e){let t=Buffer.alloc(bt.span);bt.encode({instruction:5},t);let r=[p({pubkey:Z,isWritable:!1}),p({pubkey:e.id}),p({pubkey:e.authority,isWritable:!1}),p({pubkey:e.lpVault,isWritable:!1}),p({pubkey:e.rewardVault}),p({pubkey:e.userRewardToken}),p({pubkey:e.owner,isWritable:!1,isSigner:!0})];return{instruction:new W({programId:e.programId,keys:r,data:t}),instructionType:Se.FarmV6CreatorWithdraw}}function mi(e,t,r,n,i,o,s,a,c,u,l,f,d){let g=B([R("depositEntryIndex"),y("amount")]),w=[{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:i,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:Z,isSigner:!1,isWritable:!1},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!1},{pubkey:ze,isSigner:!1,isWritable:!1}],h=Buffer.alloc(g.span);g.encode({depositEntryIndex:f,amount:d},h);let v=Buffer.from([..._e.voterStakeRegistryDeposit,...h]);return new W({keys:w,programId:e,data:v})}function gi(e,t,r,n){let i=B([]),o=[{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:ye.programId,isSigner:!1,isWritable:!1}],s=Buffer.alloc(i.span);i.encode({},s);let a=Buffer.from([..._e.voterStakeRegistryUpdateVoterWeightRecord,...s]);return new W({keys:o,programId:e,data:a})}function yi(e,t,r,n,i,o,s,a,c,u,l,f,d,g,w){let h=B([R("depositEntryIndex"),y("amount")]),v=[{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!0},{pubkey:a,isSigner:!1,isWritable:!0},{pubkey:Z,isSigner:!1,isWritable:!1},{pubkey:c,isSigner:!1,isWritable:!0},{pubkey:u,isSigner:!1,isWritable:!1},{pubkey:l,isSigner:!1,isWritable:!0},{pubkey:f,isSigner:!1,isWritable:!1},{pubkey:d,isSigner:!1,isWritable:!1},{pubkey:ze,isSigner:!1,isWritable:!1}],C=Buffer.alloc(h.span);h.encode({depositEntryIndex:g,amount:w},C);let O=Buffer.from([..._e.voterStakeRegistryWithdraw,...C]);return new W({keys:v,programId:e,data:O})}function hi(e,t,r,n,i,o){let s=B([R("ins")]),a=[{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!0,isWritable:!0},{pubkey:ye.programId,isSigner:!1,isWritable:!1}],c=Buffer.alloc(s.span);return s.encode({ins:23},c),new W({keys:a,programId:e,data:c})}function bi(e,t,r,n,i,o,s,a){let c=B([R("voterBump"),R("voterWeightRecordBump")]),u=[{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:i,isSigner:!0,isWritable:!1},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:o,isSigner:!0,isWritable:!0},{pubkey:ye.programId,isSigner:!1,isWritable:!1},{pubkey:lt,isSigner:!1,isWritable:!1},{pubkey:ze,isSigner:!1,isWritable:!1}],l=Buffer.alloc(c.span);c.encode({voterBump:s,voterWeightRecordBump:a},l);let f=Buffer.from([..._e.voterStakeRegistryCreateVoter,...l]);return new W({keys:u,programId:e,data:f})}function wi(e,t,r,n,i,o,s,a,c,u,l,f){let d=B([R("depositEntryIndex"),R("kind"),R("option"),y("startTs"),Ae("periods"),Ke("allowClawback")]),g=[{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:r,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!0},{pubkey:i,isSigner:!0,isWritable:!1},{pubkey:o,isSigner:!0,isWritable:!0},{pubkey:s,isSigner:!1,isWritable:!1},{pubkey:ye.programId,isSigner:!1,isWritable:!1},{pubkey:Z,isSigner:!1,isWritable:!1},{pubkey:fi,isSigner:!1,isWritable:!1},{pubkey:lt,isSigner:!1,isWritable:!1}],w=Buffer.alloc(d.span);d.encode({depositEntryIndex:a,kind:c,option:u===void 0?0:1,startTs:u,periods:l,allowClawback:f},w);let h=Buffer.from([..._e.voterStakeRegistryCreateDepositEntry,...w]);return new W({keys:g,programId:e,data:h})}async function jl({connection:e,programId:t,governanceProgramId:r,voteWeightAddinProgramId:n,realm:i,communityTokenMint:o,owner:s,poolId:a,tokenProgram:c}){let u=xt(n,i,o).publicKey,l=ne({programId:t,poolId:a,owner:s,version:3}),f=await e.getAccountInfo(l);if(f===null)throw Error("user is not staker");let d=Je.decode(f.data),g=d.deposited.sub(d.voteLockedBalance);if(console.log("amount",g.toString()),g.eq(new Qe(0)))throw Error("user do not has new stake amount");let w=St(t,a).publicKey,h=kt(t,a).publicKey,{publicKey:v,nonce:C}=At(n,u,s),O=Ne(v,w,c).publicKey,{publicKey:I,nonce:F}=Lt(n,u,s),ae=It(r,i,o,s).publicKey,j=[],de=Ne(s,w,c).publicKey;if(await e.getAccountInfo(de)===null&&j.push(di(s,de,s,w)),await e.getAccountInfo(v)===null){let we=hi(r,i,s,o,s,ae);j.push(we,bi(n,u,v,I,s,s,C,F))}let{index:be,isInit:X}=await Bt(e,u,v,w);return X||j.push(wi(n,u,v,O,s,s,w,be,0,void 0,0,!1)),j.push(mi(n,u,v,O,de,s,l,a,w,h,t,be,g),gi(n,u,v,I)),j}async function zl({connection:e,programId:t,governanceProgramId:r,voteWeightAddinProgramId:n,realm:i,communityTokenMint:o,owner:s,poolId:a,tokenProgram:c}){let u=xt(n,i,o).publicKey,l=ne({programId:t,poolId:a,owner:s,version:3}),f=await e.getAccountInfo(l);if(f===null)throw Error("user is not staker");let d=Je.decode(f.data);if(d.voteLockedBalance.eq(new Qe(0)))throw Error("user has vote locked balance = 0");let g=St(t,a).publicKey,w=kt(t,a).publicKey,{publicKey:h}=At(n,u,s),v=Ne(h,g,c).publicKey,{publicKey:C}=Lt(n,u,s),O=It(r,i,o,s).publicKey,I=[],{index:F,isInit:ae}=await Bt(e,u,h,g);if(!ae)throw Error("deposit entry index check error");return I.push(yi(n,u,h,s,O,C,v,Ne(s,g,c).publicKey,l,a,g,w,t,F,d.voteLockedBalance)),I}function Yl({payer:e,rewardVault:t,userRewardTokenPub:r,farmKeys:n,rewardInfo:i}){let o=Buffer.alloc(Tt.span);Tt.encode({instruction:3,rewardReopenTime:_(i.openTime),rewardEndTime:_(i.endTime),rewardPerSecond:_(i.perSecond)},o);let s=[p({pubkey:Z,isWritable:!1}),p({pubkey:n.id}),p({pubkey:n.lpVault,isWritable:!1}),p({pubkey:t}),p({pubkey:r}),p({pubkey:e,isWritable:!1,isSigner:!0})];return new W({programId:n.programId,keys:s,data:o})}function Zl({payer:e,userRewardTokenPub:t,farmKeys:r,rewardVault:n,rewardInfo:i}){let o=Buffer.alloc(Pt.span);Pt.encode({instruction:4,isSet:new Qe(1),rewardPerSecond:_(i.perSecond),rewardOpenTime:_(i.openTime),rewardEndTime:_(i.endTime),rewardType:_(Ve[i.rewardType])},o);let s=[...ct,p({pubkey:r.id}),p({pubkey:r.authority,isWritable:!1}),p({pubkey:i.mint,isWritable:!1}),p({pubkey:n}),p({pubkey:t}),p({pubkey:e,isWritable:!1,isSigner:!0})];return new W({programId:r.programId,keys:s,data:o})}function Xl(e){let{farmInfo:t,farmKeys:r,version:n,lpAccount:i,rewardAccounts:o,owner:s,instruction:a,amount:c,deposit:u}=e,[l,f]=[new P(t.programId),new P(t.id)],d=ne({programId:l,poolId:f,owner:s,version:n}),g=Buffer.alloc(z.span);z.encode({instruction:a,amount:c},g);let w=n===6?[p({pubkey:Z,isWritable:!1}),...u?[p({pubkey:ye.programId,isWritable:!1})]:[],p({pubkey:f}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:new P(r.lpVault)}),p({pubkey:d}),p({pubkey:s,isWritable:!1,isSigner:!0}),p({pubkey:i})]:[p({pubkey:f}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:d}),p({pubkey:s,isWritable:!1,isSigner:!0}),p({pubkey:i}),p({pubkey:new P(r.lpVault)}),p({pubkey:o[0]}),p({pubkey:new P(r.rewardInfos[0].vault)}),p({pubkey:Le,isWritable:!1}),p({pubkey:Z,isWritable:!1})];if(n===5)for(let h=1;h<r.rewardInfos.length;h++)w.push(p({pubkey:o[h]})),w.push(p({pubkey:new P(r.rewardInfos[h].vault)}));if(n===6)for(let h=0;h<r.rewardInfos.length;h++)w.push(p({pubkey:new P(r.rewardInfos[h].vault)})),w.push(p({pubkey:o[h]}));return new W({programId:l,keys:w,data:g})}function Jl(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:i,owner:o,amount:s}=e,[a,c]=[new P(t.programId),new P(t.id)],u=ne({programId:a,poolId:c,owner:o,version:6}),l=Buffer.alloc(z.span);z.encode({instruction:2,amount:_(s)},l);let f=[p({pubkey:Z,isWritable:!1}),p({pubkey:c}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:new P(r.lpVault)}),p({pubkey:u}),p({pubkey:o,isWritable:!1,isSigner:!0}),p({pubkey:n})];for(let d=0;d<r.rewardInfos.length;d++)f.push(p({pubkey:new P(r.rewardInfos[d].vault)})),f.push(p({pubkey:i[d]}));return new W({programId:a,keys:f,data:l})}function Ql(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:i,owner:o,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new P(t.programId),new P(t.id)],l=ne({programId:c,poolId:u,owner:o,version:5}),f=Buffer.alloc(z.span);z.encode({instruction:12,amount:_(s)},f);let d=[p({pubkey:u}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:l}),p({pubkey:o,isWritable:!1,isSigner:!0}),p({pubkey:n}),p({pubkey:new P(r.lpVault)}),p({pubkey:i[0]}),p({pubkey:new P(r.rewardInfos[0].vault)}),p({pubkey:Le,isWritable:!1}),p({pubkey:Z,isWritable:!1})];for(let g=1;g<r.rewardInfos.length;g++)d.push(p({pubkey:i[g]})),d.push(p({pubkey:new P(r.rewardInfos[g].vault)}));if(a)for(let g of a)d.push(p({pubkey:g}));return new W({programId:c,keys:d,data:f})}function $l(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:i,owner:o,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new P(t.programId),new P(t.id)],l=B([R("instruction"),y("amount")]),f=[p({pubkey:u}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:a[0]}),p({pubkey:o,isSigner:!0,isWritable:!1}),p({pubkey:n}),p({pubkey:new P(r.lpVault)}),p({pubkey:i[0]}),p({pubkey:new P(r.rewardInfos[0].vault)}),p({pubkey:Le,isWritable:!1}),p({pubkey:Z,isWritable:!1}),p({pubkey:i[1]}),p({pubkey:new P(r.rewardInfos[1].vault)})],d=Buffer.alloc(l.span);return l.encode({instruction:2,amount:s},d),new W({keys:f,programId:c,data:d})}function ef(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:i,owner:o,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new P(t.programId),new P(t.id)],l=ne({programId:c,poolId:u,owner:o,version:3}),f=Buffer.alloc(z.span);z.encode({instruction:11,amount:_(s)},f);let d=[p({pubkey:u}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:l}),p({pubkey:o,isWritable:!1,isSigner:!0}),p({pubkey:n}),p({pubkey:new P(r.lpVault)}),p({pubkey:i[0]}),p({pubkey:new P(r.rewardInfos[0].vault)}),p({pubkey:Le,isWritable:!1}),p({pubkey:Z,isWritable:!1})];if(a)for(let g of a)d.push(p({pubkey:g}));return new W({programId:c,keys:d,data:f})}function tf(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:i,owner:o,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new P(t.programId),new P(t.id)],l=ne({programId:c,poolId:u,owner:o,version:3}),f=Buffer.alloc(z.span);z.encode({instruction:10,amount:_(s)},f);let d=[p({pubkey:u}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:l}),p({pubkey:o,isWritable:!1,isSigner:!0}),p({pubkey:n}),p({pubkey:new P(r.lpVault)}),p({pubkey:i[0]}),p({pubkey:new P(r.rewardInfos[0].vault)}),p({pubkey:Le,isWritable:!1}),p({pubkey:Z,isWritable:!1})];if(a)for(let g of a)d.push(p({pubkey:g}));return new W({programId:c,keys:d,data:f})}function rf(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:i,owner:o,amount:s,userAuxiliaryLedgers:a}=e,[c,u]=[new P(t.programId),new P(t.id)],l=ne({programId:c,poolId:u,owner:o,version:5}),f=Buffer.alloc(z.span);z.encode({instruction:11,amount:_(s)},f);let d=[p({pubkey:u}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:l}),p({pubkey:o,isWritable:!1,isSigner:!0}),p({pubkey:n}),p({pubkey:new P(r.lpVault)}),p({pubkey:i[0]}),p({pubkey:new P(r.rewardInfos[0].vault)}),p({pubkey:Le,isWritable:!1}),p({pubkey:Z,isWritable:!1})];for(let g=1;g<r.rewardInfos.length;g++)d.push(p({pubkey:i[g]})),d.push(p({pubkey:new P(r.rewardInfos[g].vault)}));if(a)for(let g of a)d.push(p({pubkey:g}));return new W({programId:c,keys:d,data:f})}function nf(e){let{farmInfo:t,farmKeys:r,lpAccount:n,rewardAccounts:i,owner:o,amount:s}=e,[a,c]=[new P(t.programId),new P(t.id)],u=ne({programId:a,poolId:c,owner:o,version:6}),l=Buffer.alloc(z.span);z.encode({instruction:1,amount:_(s)},l);let f=[p({pubkey:Z,isWritable:!1}),p({pubkey:ye.programId,isWritable:!1}),p({pubkey:c}),p({pubkey:new P(r.authority),isWritable:!1}),p({pubkey:new P(r.lpVault)}),p({pubkey:u}),p({pubkey:o,isWritable:!1,isSigner:!0}),p({pubkey:n})];for(let d=0;d<r.rewardInfos.length;d++)f.push(p({pubkey:new P(r.rewardInfos[d].vault)})),f.push(p({pubkey:i[d]}));return new W({programId:a,keys:f,data:l})}export{ql as createAssociatedLedgerAccountInstruction,hi as governanceCreateTokenOwnerRecord,Zl as makeAddNewRewardInstruction,Gl as makeCreateFarmInstruction,Hl as makeCreatorWithdrawFarmRewardInstruction,tf as makeDepositInstructionV3,rf as makeDepositInstructionV5,nf as makeDepositInstructionV6,jl as makeDepositTokenInstruction,Xl as makeDepositWithdrawInstruction,Yl as makeRestartRewardInstruction,ef as makeWithdrawInstructionV3,$l as makeWithdrawInstructionV4,Ql as makeWithdrawInstructionV5,Jl as makeWithdrawInstructionV6,zl as makeWithdrawTokenInstruction,wi as voterStakeRegistryCreateDepositEntry,bi as voterStakeRegistryCreateVoter,mi as voterStakeRegistryDeposit,gi as voterStakeRegistryUpdateVoterWeightRecord,yi as voterStakeRegistryWithdraw};
//# sourceMappingURL=instruction.mjs.map