@raydium-io/raydium-sdk-v2 0.1.95-alpha → 0.1.96-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/api/api.d.ts +1 -1
- package/lib/api/index.d.ts +1 -1
- package/lib/api/type.d.ts +1 -1
- package/lib/{api-0eb57ba2.d.ts → api-153bc957.d.ts} +8 -8
- package/lib/common/accountInfo.d.ts +1 -1
- package/lib/common/bignumber.d.ts +1 -1
- package/lib/common/constant.d.ts +1 -1
- package/lib/common/fractionUtil.d.ts +1 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/transfer.d.ts +1 -1
- package/lib/common/txTool/txTool.d.ts +1 -1
- package/lib/common/txTool/txUtils.d.ts +1 -1
- package/lib/common/utility.d.ts +1 -1
- package/lib/index.d.ts +3 -3
- 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/module/amount.d.ts +1 -1
- package/lib/module/fraction.d.ts +1 -1
- package/lib/module/index.d.ts +1 -1
- package/lib/module/percent.d.ts +1 -1
- package/lib/module/price.d.ts +1 -1
- package/lib/raydium/account/account.d.ts +3 -3
- package/lib/raydium/account/account.js +1 -1
- package/lib/raydium/account/account.js.map +1 -1
- package/lib/raydium/account/account.mjs +1 -1
- package/lib/raydium/account/account.mjs.map +1 -1
- package/lib/raydium/account/index.d.ts +1 -1
- package/lib/raydium/account/instruction.d.ts +1 -1
- package/lib/raydium/account/types.d.ts +1 -1
- package/lib/raydium/account/util.d.ts +1 -1
- package/lib/raydium/clmm/clmm.d.ts +3 -3
- package/lib/raydium/clmm/index.d.ts +3 -3
- package/lib/raydium/clmm/instrument.d.ts +2 -2
- package/lib/raydium/clmm/layout.d.ts +5 -5
- package/lib/raydium/clmm/type.d.ts +2 -2
- package/lib/raydium/clmm/utils/math.d.ts +2 -2
- package/lib/raydium/clmm/utils/pool.d.ts +2 -2
- package/lib/raydium/clmm/utils/position.d.ts +2 -2
- package/lib/raydium/clmm/utils/tick.d.ts +2 -2
- package/lib/raydium/clmm/utils/tickQuery.d.ts +2 -2
- package/lib/raydium/clmm/utils/tickarrayBitmap.d.ts +2 -2
- package/lib/raydium/cpmm/cpmm.d.ts +3 -3
- package/lib/raydium/cpmm/curve/calculator.d.ts +1 -1
- package/lib/raydium/cpmm/curve/constantProduct.d.ts +1 -1
- package/lib/raydium/cpmm/index.d.ts +1 -1
- package/lib/raydium/cpmm/instruction.d.ts +1 -1
- package/lib/raydium/cpmm/type.d.ts +1 -1
- package/lib/raydium/farm/config.d.ts +1 -1
- package/lib/raydium/farm/farm.d.ts +3 -3
- package/lib/raydium/farm/index.d.ts +1 -1
- package/lib/raydium/farm/instruction.d.ts +1 -1
- package/lib/raydium/farm/layout.d.ts +1 -1
- package/lib/raydium/farm/type.d.ts +1 -1
- package/lib/raydium/farm/util.d.ts +1 -1
- package/lib/raydium/ido/ido.d.ts +3 -3
- package/lib/raydium/ido/index.d.ts +3 -3
- package/lib/raydium/ido/instruction.d.ts +1 -1
- package/lib/raydium/ido/type.d.ts +1 -1
- package/lib/raydium/index.d.ts +3 -3
- 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/liquidity/index.d.ts +1 -1
- package/lib/raydium/liquidity/instruction.d.ts +1 -1
- package/lib/raydium/liquidity/layout.d.ts +4 -4
- package/lib/raydium/liquidity/liquidity.d.ts +3 -3
- package/lib/raydium/liquidity/type.d.ts +1 -1
- package/lib/raydium/liquidity/utils.d.ts +1 -1
- package/lib/raydium/marketV2/createMarket.d.ts +3 -3
- package/lib/raydium/marketV2/index.d.ts +3 -3
- package/lib/raydium/moduleBase.d.ts +3 -3
- package/lib/raydium/raydium.d.ts +3 -3
- 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/lib/raydium/token/constant.d.ts +1 -1
- package/lib/raydium/token/index.d.ts +1 -1
- package/lib/raydium/token/token.d.ts +3 -3
- package/lib/raydium/token/type.d.ts +1 -1
- package/lib/raydium/token/utils.d.ts +1 -1
- package/lib/raydium/tradeV2/index.d.ts +2 -2
- package/lib/raydium/tradeV2/instrument.d.ts +2 -2
- package/lib/raydium/tradeV2/trade.d.ts +3 -3
- package/lib/raydium/tradeV2/type.d.ts +2 -2
- package/lib/raydium/type.d.ts +1 -1
- package/lib/raydium/utils1216/index.d.ts +3 -3
- package/lib/raydium/utils1216/utils1216.d.ts +3 -3
- package/lib/{raydium-2dba5baa.d.ts → raydium-77fc4407.d.ts} +2 -2
- package/lib/{type-28a58c39.d.ts → type-953d8113.d.ts} +1 -1
- package/package.json +1 -1
- package/src/raydium/.DS_Store +0 -0
- package/src/raydium/account/account.ts +3 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var Kn=Object.defineProperty,vn=Object.defineProperties;var Fn=Object.getOwnPropertyDescriptors;var Oe=Object.getOwnPropertySymbols;var Wt=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var Vt=(e,t,n)=>t in e?Kn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,V=(e,t)=>{for(var n in t||(t={}))Wt.call(t,n)&&Vt(e,n,t[n]);if(Oe)for(var n of Oe(t))Ut.call(t,n)&&Vt(e,n,t[n]);return e},oe=(e,t)=>vn(e,Fn(t));var me=(e,t)=>{var n={};for(var r in e)Wt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Oe)for(var r of Oe(e))t.indexOf(r)<0&&Ut.call(e,r)&&(n[r]=e[r]);return n};import{PublicKey as st,SystemProgram as No}from"@solana/web3.js";import{PublicKey as Un}from"@solana/web3.js";import{get as qt,set as Vn}from"lodash";var at=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 n=t.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},Gt={},Wn={};function j(e){let t=qt(Gt,e);if(!t){let n=qt(Wn,e);t=new at({name:e,logLevel:n}),Vn(Gt,e,t)}return t}import{MINT_SIZE as Uo,TOKEN_PROGRAM_ID as qo,getTransferFeeConfig as Go,unpackMint as Ho}from"@solana/spl-token";var ct=j("Raydium_accountInfo_util");async function Ht(e,t,n){let{batchRequest:r,commitment:o="confirmed",chunkCount:i=100}=V({batchRequest:!1},n),s=ut(t,i),a=new Array(s.length).fill([]);if(r){let u=s.map(f=>{let p=e._buildArgs([f.map(m=>m.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:p}}),c=ut(u,10);a=(await(await Promise.all(c.map(async f=>await e._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&ct.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${f.error.message}`),f.result.value.map(p=>{if(p){let{data:m,executable:h,lamports:g,owner:w,rentEpoch:x}=p;return m.length!==2&&m[1]!=="base64"&&ct.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(m[0],"base64"),executable:h,lamports:g,owner:new Un(w),rentEpoch:x}}return null})))}else try{a=await Promise.all(s.map(u=>e.getMultipleAccountsInfo(u,o)))}catch(u){u instanceof Error&&ct.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${u.message}`)}return a.flat()}import re from"bn.js";var he=9e15,ue=1e9,lt="0123456789abcdef",ve="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Fe="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ft={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-he,maxE:he,crypto:!1},Yt,te,B=!0,We="[DecimalError] ",ce=We+"Invalid argument: ",Xt=We+"Precision limit exceeded",Qt=We+"crypto unavailable",Jt="[object Decimal]",z=Math.floor,U=Math.pow,qn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Gn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Hn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,$t=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Q=1e7,C=7,jn=9007199254740991,zn=ve.length-1,pt=Fe.length-1,d={toStringTag:Jt};d.absoluteValue=d.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),A(e)};d.ceil=function(){return A(new this.constructor(this),this.e+1,2)};d.clampedTo=d.clamp=function(e,t){var n,r=this,o=r.constructor;if(e=new o(e),t=new o(t),!e.s||!t.s)return new o(NaN);if(e.gt(t))throw Error(ce+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new o(r)};d.comparedTo=d.cmp=function(e){var t,n,r,o,i=this,s=i.d,a=(e=new i.constructor(e)).d,u=i.s,c=e.s;if(!s||!a)return!u||!c?NaN:u!==c?u:s===a?0:!s^u<0?1:-1;if(!s[0]||!a[0])return s[0]?u:a[0]?-c:0;if(u!==c)return u;if(i.e!==e.e)return i.e>e.e^u<0?1:-1;for(r=s.length,o=a.length,t=0,n=r<o?r:o;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^u<0?1:-1;return r===o?0:r>o^u<0?1:-1};d.cosine=d.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+C,r.rounding=1,n=Zn(r,on(r,n)),r.precision=e,r.rounding=t,A(te==2||te==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};d.cubeRoot=d.cbrt=function(){var e,t,n,r,o,i,s,a,u,c,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(B=!1,i=l.s*U(l.s*l,1/3),!i||Math.abs(i)==1/0?(n=H(l.d),e=l.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=U(n,1/3),e=z((e+1)/3)-(e%3==(e<0?-1:2)),i==1/0?n="5e"+e:(n=i.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new f(n),r.s=l.s):r=new f(i.toString()),s=(e=f.precision)+3;;)if(a=r,u=a.times(a).times(a),c=u.plus(l),r=R(c.plus(l).times(a),c.plus(u),s+2,1),H(a.d).slice(0,s)===(n=H(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(A(a,e+1,0),a.times(a).times(a).eq(l))){r=a;break}s+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(A(r,e+1,1),t=!r.times(r).times(r).eq(l));break}return B=!0,A(r,e,f.rounding,t)};d.decimalPlaces=d.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-z(this.e/C))*C,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};d.dividedBy=d.div=function(e){return R(this,new this.constructor(e))};d.dividedToIntegerBy=d.divToInt=function(e){var t=this,n=t.constructor;return A(R(t,new n(e),0,1,1),n.precision,n.rounding)};d.equals=d.eq=function(e){return this.cmp(e)===0};d.floor=function(){return A(new this.constructor(this),this.e+1,3)};d.greaterThan=d.gt=function(e){return this.cmp(e)>0};d.greaterThanOrEqualTo=d.gte=function(e){var t=this.cmp(e);return t==1||t===0};d.hyperbolicCosine=d.cosh=function(){var e,t,n,r,o,i=this,s=i.constructor,a=new s(1);if(!i.isFinite())return new s(i.s?1/0:NaN);if(i.isZero())return a;n=s.precision,r=s.rounding,s.precision=n+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(e=Math.ceil(o/3),t=(1/qe(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=ge(s,1,i.times(t),new s(1),!0);for(var u,c=e,l=new s(8);c--;)u=i.times(i),i=a.minus(u.times(l.minus(u.times(l))));return A(i,s.precision=n,s.rounding=r,!0)};d.hyperbolicSine=d.sinh=function(){var e,t,n,r,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(t=i.precision,n=i.rounding,i.precision=t+Math.max(o.e,o.sd())+4,i.rounding=1,r=o.d.length,r<3)o=ge(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/qe(5,e)),o=ge(i,2,o,o,!0);for(var s,a=new i(5),u=new i(16),c=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(u.times(s).plus(c))))}return i.precision=t,i.rounding=n,A(o,t,n,!0)};d.hyperbolicTangent=d.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,R(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};d.inverseCosine=d.acos=function(){var e,t=this,n=t.constructor,r=t.abs().cmp(1),o=n.precision,i=n.rounding;return r!==-1?r===0?t.isNeg()?X(n,o,i):new n(0):new n(NaN):t.isZero()?X(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=X(n,o+4,i).times(.5),n.precision=o,n.rounding=i,e.minus(t))};d.inverseHyperbolicCosine=d.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,B=!1,n=n.times(n).minus(1).sqrt().plus(n),B=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};d.inverseHyperbolicSine=d.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,B=!1,n=n.times(n).plus(1).sqrt().plus(n),B=!0,r.precision=e,r.rounding=t,n.ln())};d.inverseHyperbolicTangent=d.atanh=function(){var e,t,n,r,o=this,i=o.constructor;return o.isFinite()?o.e>=0?new i(o.abs().eq(1)?o.s/0:o.isZero()?o:NaN):(e=i.precision,t=i.rounding,r=o.sd(),Math.max(r,e)<2*-o.e-1?A(new i(o),e,t,!0):(i.precision=n=r-o.e,o=R(o.plus(1),new i(1).minus(o),n+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};d.inverseSine=d.asin=function(){var e,t,n,r,o=this,i=o.constructor;return o.isZero()?new i(o):(t=o.abs().cmp(1),n=i.precision,r=i.rounding,t!==-1?t===0?(e=X(i,n+4,r).times(.5),e.s=o.s,e):new i(NaN):(i.precision=n+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=n,i.rounding=r,o.times(2)))};d.inverseTangent=d.atan=function(){var e,t,n,r,o,i,s,a,u,c=this,l=c.constructor,f=l.precision,p=l.rounding;if(c.isFinite()){if(c.isZero())return new l(c);if(c.abs().eq(1)&&f+4<=pt)return s=X(l,f+4,p).times(.25),s.s=c.s,s}else{if(!c.s)return new l(NaN);if(f+4<=pt)return s=X(l,f+4,p).times(.5),s.s=c.s,s}for(l.precision=a=f+10,l.rounding=1,n=Math.min(28,a/C+2|0),e=n;e;--e)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(B=!1,t=Math.ceil(a/C),r=1,u=c.times(c),s=new l(c),o=c;e!==-1;)if(o=o.times(u),i=s.minus(o.div(r+=2)),o=o.times(u),s=i.plus(o.div(r+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===i.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),B=!0,A(s,l.precision=f,l.rounding=p,!0)};d.isFinite=function(){return!!this.d};d.isInteger=d.isInt=function(){return!!this.d&&z(this.e/C)>this.d.length-2};d.isNaN=function(){return!this.s};d.isNegative=d.isNeg=function(){return this.s<0};d.isPositive=d.isPos=function(){return this.s>0};d.isZero=function(){return!!this.d&&this.d[0]===0};d.lessThan=d.lt=function(e){return this.cmp(e)<0};d.lessThanOrEqualTo=d.lte=function(e){return this.cmp(e)<1};d.logarithm=d.log=function(e){var t,n,r,o,i,s,a,u,c=this,l=c.constructor,f=l.precision,p=l.rounding,m=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(n=c.d,c.s<0||!n||!n[0]||c.eq(1))return new l(n&&!n[0]?-1/0:c.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)i=!0;else{for(o=n[0];o%10===0;)o/=10;i=o!==1}if(B=!1,a=f+m,s=ae(c,a),r=t?Ve(l,a+10):ae(e,a),u=R(s,r,a,1),Te(u.d,o=f,p))do if(a+=10,s=ae(c,a),r=t?Ve(l,a+10):ae(e,a),u=R(s,r,a,1),!i){+H(u.d).slice(o+1,o+15)+1==1e14&&(u=A(u,f+1,0));break}while(Te(u.d,o+=10,p));return B=!0,A(u,f,p)};d.minus=d.sub=function(e){var t,n,r,o,i,s,a,u,c,l,f,p,m=this,h=m.constructor;if(e=new h(e),!m.d||!e.d)return!m.s||!e.s?e=new h(NaN):m.d?e.s=-e.s:e=new h(e.d||m.s!==e.s?m:NaN),e;if(m.s!=e.s)return e.s=-e.s,m.plus(e);if(c=m.d,p=e.d,a=h.precision,u=h.rounding,!c[0]||!p[0]){if(p[0])e.s=-e.s;else if(c[0])e=new h(m);else return new h(u===3?-0:0);return B?A(e,a,u):e}if(n=z(e.e/C),l=z(m.e/C),c=c.slice(),i=l-n,i){for(f=i<0,f?(t=c,i=-i,s=p.length):(t=p,n=l,s=c.length),r=Math.max(Math.ceil(a/C),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=c.length,s=p.length,f=r<s,f&&(s=r),r=0;r<s;r++)if(c[r]!=p[r]){f=c[r]<p[r];break}i=0}for(f&&(t=c,c=p,p=t,e.s=-e.s),s=c.length,r=p.length-s;r>0;--r)c[s++]=0;for(r=p.length;r>i;){if(c[--r]<p[r]){for(o=r;o&&c[--o]===0;)c[o]=Q-1;--c[o],c[r]+=Q}c[r]-=p[r]}for(;c[--s]===0;)c.pop();for(;c[0]===0;c.shift())--n;return c[0]?(e.d=c,e.e=Ue(c,n),B?A(e,a,u):e):new h(u===3?-0:0)};d.modulo=d.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?A(new r(n),r.precision,r.rounding):(B=!1,r.modulo==9?(t=R(n,e.abs(),0,3,1),t.s*=e.s):t=R(n,e,0,r.modulo,1),t=t.times(e),B=!0,n.minus(t))};d.naturalExponential=d.exp=function(){return mt(this)};d.naturalLogarithm=d.ln=function(){return ae(this)};d.negated=d.neg=function(){var e=new this.constructor(this);return e.s=-e.s,A(e)};d.plus=d.add=function(e){var t,n,r,o,i,s,a,u,c,l,f=this,p=f.constructor;if(e=new p(e),!f.d||!e.d)return!f.s||!e.s?e=new p(NaN):f.d||(e=new p(e.d||f.s===e.s?f:NaN)),e;if(f.s!=e.s)return e.s=-e.s,f.minus(e);if(c=f.d,l=e.d,a=p.precision,u=p.rounding,!c[0]||!l[0])return l[0]||(e=new p(f)),B?A(e,a,u):e;if(i=z(f.e/C),r=z(e.e/C),c=c.slice(),o=i-r,o){for(o<0?(n=c,o=-o,s=l.length):(n=l,r=i,s=c.length),i=Math.ceil(a/C),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=c.length,o=l.length,s-o<0&&(o=s,n=l,l=c,c=n),t=0;o;)t=(c[--o]=c[o]+l[o]+t)/Q|0,c[o]%=Q;for(t&&(c.unshift(t),++r),s=c.length;c[--s]==0;)c.pop();return e.d=c,e.e=Ue(c,r),B?A(e,a,u):e};d.precision=d.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ce+e);return n.d?(t=en(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};d.round=function(){var e=this,t=e.constructor;return A(new t(e),e.e+1,t.rounding)};d.sine=d.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+C,r.rounding=1,n=Xn(r,on(r,n)),r.precision=e,r.rounding=t,A(te>2?n.neg():n,e,t,!0)):new r(NaN)};d.squareRoot=d.sqrt=function(){var e,t,n,r,o,i,s=this,a=s.d,u=s.e,c=s.s,l=s.constructor;if(c!==1||!a||!a[0])return new l(!c||c<0&&(!a||a[0])?NaN:a?s:1/0);for(B=!1,c=Math.sqrt(+s),c==0||c==1/0?(t=H(a),(t.length+u)%2==0&&(t+="0"),c=Math.sqrt(t),u=z((u+1)/2)-(u<0||u%2),c==1/0?t="5e"+u:(t=c.toExponential(),t=t.slice(0,t.indexOf("e")+1)+u),r=new l(t)):r=new l(c.toString()),n=(u=l.precision)+3;;)if(i=r,r=i.plus(R(s,i,n+2,1)).times(.5),H(i.d).slice(0,n)===(t=H(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(A(i,u+1,0),i.times(i).eq(s))){r=i;break}n+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(A(r,u+1,1),e=!r.times(r).eq(s));break}return B=!0,A(r,u,l.rounding,e)};d.tangent=d.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=R(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,A(te==2||te==4?n.neg():n,e,t,!0)):new r(NaN)};d.times=d.mul=function(e){var t,n,r,o,i,s,a,u,c,l=this,f=l.constructor,p=l.d,m=(e=new f(e)).d;if(e.s*=l.s,!p||!p[0]||!m||!m[0])return new f(!e.s||p&&!p[0]&&!m||m&&!m[0]&&!p?NaN:!p||!m?e.s/0:e.s*0);for(n=z(l.e/C)+z(e.e/C),u=p.length,c=m.length,u<c&&(i=p,p=m,m=i,s=u,u=c,c=s),i=[],s=u+c,r=s;r--;)i.push(0);for(r=c;--r>=0;){for(t=0,o=u+r;o>r;)a=i[o]+m[r]*p[o-r-1]+t,i[o--]=a%Q|0,t=a/Q|0;i[o]=(i[o]+t)%Q|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=Ue(i,n),B?A(e,f.precision,f.rounding):e};d.toBinary=function(e,t){return ht(this,2,e,t)};d.toDecimalPlaces=d.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(Y(e,0,ue),t===void 0?t=r.rounding:Y(t,0,8),A(n,e+n.e+1,t))};d.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=ee(r,!0):(Y(e,0,ue),t===void 0?t=o.rounding:Y(t,0,8),r=A(new o(r),e+1,t),n=ee(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};d.toFixed=function(e,t){var n,r,o=this,i=o.constructor;return e===void 0?n=ee(o):(Y(e,0,ue),t===void 0?t=i.rounding:Y(t,0,8),r=A(new i(o),e+o.e+1,t),n=ee(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};d.toFraction=function(e){var t,n,r,o,i,s,a,u,c,l,f,p,m=this,h=m.d,g=m.constructor;if(!h)return new g(m);if(c=n=new g(1),r=u=new g(0),t=new g(r),i=t.e=en(h)-m.e-1,s=i%C,t.d[0]=U(10,s<0?C+s:s),e==null)e=i>0?t:c;else{if(a=new g(e),!a.isInt()||a.lt(c))throw Error(ce+a);e=a.gt(t)?i>0?t:c:a}for(B=!1,a=new g(H(h)),l=g.precision,g.precision=i=h.length*C*2;f=R(a,t,0,1,1),o=n.plus(f.times(r)),o.cmp(e)!=1;)n=r,r=o,o=c,c=u.plus(f.times(o)),u=o,o=t,t=a.minus(f.times(o)),a=o;return o=R(e.minus(n),r,0,1,1),u=u.plus(o.times(c)),n=n.plus(o.times(r)),u.s=c.s=m.s,p=R(c,r,i,1).minus(m).abs().cmp(R(u,n,i,1).minus(m).abs())<1?[c,r]:[u,n],g.precision=l,B=!0,p};d.toHexadecimal=d.toHex=function(e,t){return ht(this,16,e,t)};d.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Y(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(B=!1,n=R(n,e,0,t,1).times(e),B=!0,A(n)):(e.s=n.s,n=e),n};d.toNumber=function(){return+this};d.toOctal=function(e,t){return ht(this,8,e,t)};d.toPower=d.pow=function(e){var t,n,r,o,i,s,a=this,u=a.constructor,c=+(e=new u(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new u(U(+a,c));if(a=new u(a),a.eq(1))return a;if(r=u.precision,i=u.rounding,e.eq(1))return A(a,r,i);if(t=z(e.e/C),t>=e.d.length-1&&(n=c<0?-c:c)<=jn)return o=tn(u,a,n,r),e.s<0?new u(1).div(o):A(o,r,i);if(s=a.s,s<0){if(t<e.d.length-1)return new u(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=U(+a,c),t=n==0||!isFinite(n)?z(c*(Math.log("0."+H(a.d))/Math.LN10+a.e+1)):new u(n+"").e,t>u.maxE+1||t<u.minE-1?new u(t>0?s/0:0):(B=!1,u.rounding=a.s=1,n=Math.min(12,(t+"").length),o=mt(e.times(ae(a,r+n)),r),o.d&&(o=A(o,r+5,1),Te(o.d,r,i)&&(t=r+10,o=A(mt(e.times(ae(a,t+n)),t),t+5,1),+H(o.d).slice(r+1,r+15)+1==1e14&&(o=A(o,r+1,0)))),o.s=s,B=!0,u.rounding=i,A(o,r,i))};d.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=ee(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(Y(e,1,ue),t===void 0?t=o.rounding:Y(t,0,8),r=A(new o(r),e,t),n=ee(r,e<=r.e||r.e<=o.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};d.toSignificantDigits=d.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Y(e,1,ue),t===void 0?t=r.rounding:Y(t,0,8)),A(new r(n),e,t)};d.toString=function(){var e=this,t=e.constructor,n=ee(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};d.truncated=d.trunc=function(){return A(new this.constructor(this),this.e+1,1)};d.valueOf=d.toJSON=function(){var e=this,t=e.constructor,n=ee(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function H(e){var t,n,r,o=e.length-1,i="",s=e[0];if(o>0){for(i+=s,t=1;t<o;t++)r=e[t]+"",n=C-r.length,n&&(i+=se(n)),i+=r;s=e[t],r=s+"",n=C-r.length,n&&(i+=se(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function Y(e,t,n){if(e!==~~e||e<t||e>n)throw Error(ce+e)}function Te(e,t,n,r){var o,i,s,a;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=C,o=0):(o=Math.ceil((t+1)/C),t%=C),i=U(10,C-t),a=e[o]%i|0,r==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==i||n>3&&a+1==i/2)&&(e[o+1]/i/100|0)==U(10,t-2)-1||(a==i/2||a==0)&&(e[o+1]/i/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(r||n<4)&&a==9999||!r&&n>3&&a==4999):s=((r||n<4)&&a+1==i||!r&&n>3&&a+1==i/2)&&(e[o+1]/i/1e3|0)==U(10,t-3)-1,s}function Ke(e,t,n){for(var r,o=[0],i,s=0,a=e.length;s<a;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=lt.indexOf(e.charAt(s++)),r=0;r<o.length;r++)o[r]>n-1&&(o[r+1]===void 0&&(o[r+1]=0),o[r+1]+=o[r]/n|0,o[r]%=n)}return o.reverse()}function Zn(e,t){var n,r,o;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),o=(1/qe(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=ge(e,1,t.times(o),new e(1));for(var i=n;i--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}var R=function(){function e(r,o,i){var s,a=0,u=r.length;for(r=r.slice();u--;)s=r[u]*o+a,r[u]=s%i|0,a=s/i|0;return a&&r.unshift(a),r}function t(r,o,i,s){var a,u;if(i!=s)u=i>s?1:-1;else for(a=u=0;a<i;a++)if(r[a]!=o[a]){u=r[a]>o[a]?1:-1;break}return u}function n(r,o,i,s){for(var a=0;i--;)r[i]-=a,a=r[i]<o[i]?1:0,r[i]=a*s+r[i]-o[i];for(;!r[0]&&r.length>1;)r.shift()}return function(r,o,i,s,a,u){var c,l,f,p,m,h,g,w,x,P,y,b,k,T,_,S,M,Z,D,v,W=r.constructor,q=r.s==o.s?1:-1,F=r.d,E=o.d;if(!F||!F[0]||!E||!E[0])return new W(!r.s||!o.s||(F?E&&F[0]==E[0]:!E)?NaN:F&&F[0]==0||!E?q*0:q/0);for(u?(m=1,l=r.e-o.e):(u=Q,m=C,l=z(r.e/m)-z(o.e/m)),D=E.length,M=F.length,x=new W(q),P=x.d=[],f=0;E[f]==(F[f]||0);f++);if(E[f]>(F[f]||0)&&l--,i==null?(T=i=W.precision,s=W.rounding):a?T=i+(r.e-o.e)+1:T=i,T<0)P.push(1),h=!0;else{if(T=T/m+2|0,f=0,D==1){for(p=0,E=E[0],T++;(f<M||p)&&T--;f++)_=p*u+(F[f]||0),P[f]=_/E|0,p=_%E|0;h=p||f<M}else{for(p=u/(E[0]+1)|0,p>1&&(E=e(E,p,u),F=e(F,p,u),D=E.length,M=F.length),S=D,y=F.slice(0,D),b=y.length;b<D;)y[b++]=0;v=E.slice(),v.unshift(0),Z=E[0],E[1]>=u/2&&++Z;do p=0,c=t(E,y,D,b),c<0?(k=y[0],D!=b&&(k=k*u+(y[1]||0)),p=k/Z|0,p>1?(p>=u&&(p=u-1),g=e(E,p,u),w=g.length,b=y.length,c=t(g,y,w,b),c==1&&(p--,n(g,D<w?v:E,w,u))):(p==0&&(c=p=1),g=E.slice()),w=g.length,w<b&&g.unshift(0),n(y,g,b,u),c==-1&&(b=y.length,c=t(E,y,D,b),c<1&&(p++,n(y,D<b?v:E,b,u))),b=y.length):c===0&&(p++,y=[0]),P[f++]=p,c&&y[0]?y[b++]=F[S]||0:(y=[F[S]],b=1);while((S++<M||y[0]!==void 0)&&T--);h=y[0]!==void 0}P[0]||P.shift()}if(m==1)x.e=l,Yt=h;else{for(f=1,p=P[0];p>=10;p/=10)f++;x.e=f+l*m-1,A(x,a?i+x.e+1:i,s,h)}return x}}();function A(e,t,n,r){var o,i,s,a,u,c,l,f,p,m=e.constructor;e:if(t!=null){if(f=e.d,!f)return e;for(o=1,a=f[0];a>=10;a/=10)o++;if(i=t-o,i<0)i+=C,s=t,l=f[p=0],u=l/U(10,o-s-1)%10|0;else if(p=Math.ceil((i+1)/C),a=f.length,p>=a)if(r){for(;a++<=p;)f.push(0);l=u=0,o=1,i%=C,s=i-C+1}else break e;else{for(l=a=f[p],o=1;a>=10;a/=10)o++;i%=C,s=i-C+o,u=s<0?0:l/U(10,o-s-1)%10|0}if(r=r||t<0||f[p+1]!==void 0||(s<0?l:l%U(10,o-s-1)),c=n<4?(u||r)&&(n==0||n==(e.s<0?3:2)):u>5||u==5&&(n==4||r||n==6&&(i>0?s>0?l/U(10,o-s):0:f[p-1])%10&1||n==(e.s<0?8:7)),t<1||!f[0])return f.length=0,c?(t-=e.e+1,f[0]=U(10,(C-t%C)%C),e.e=-t||0):f[0]=e.e=0,e;if(i==0?(f.length=p,a=1,p--):(f.length=p+1,a=U(10,C-i),f[p]=s>0?(l/U(10,o-s)%U(10,s)|0)*a:0),c)for(;;)if(p==0){for(i=1,s=f[0];s>=10;s/=10)i++;for(s=f[0]+=a,a=1;s>=10;s/=10)a++;i!=a&&(e.e++,f[0]==Q&&(f[0]=1));break}else{if(f[p]+=a,f[p]!=Q)break;f[p--]=0,a=1}for(i=f.length;f[--i]===0;)f.pop()}return B&&(e.e>m.maxE?(e.d=null,e.e=NaN):e.e<m.minE&&(e.e=0,e.d=[0])),e}function ee(e,t,n){if(!e.isFinite())return rn(e);var r,o=e.e,i=H(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+se(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+se(-o-1)+i,n&&(r=n-s)>0&&(i+=se(r))):o>=s?(i+=se(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+se(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=se(r))),i}function Ue(e,t){var n=e[0];for(t*=C;n>=10;n/=10)t++;return t}function Ve(e,t,n){if(t>zn)throw B=!0,n&&(e.precision=n),Error(Xt);return A(new e(ve),t,1,!0)}function X(e,t,n){if(t>pt)throw Error(Xt);return A(new e(Fe),t,n,!0)}function en(e){var t=e.length-1,n=t*C+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function se(e){for(var t="";e--;)t+="0";return t}function tn(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/C+4);for(B=!1;;){if(n%2&&(i=i.times(t),zt(i.d,s)&&(o=!0)),n=z(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),zt(t.d,s)}return B=!0,i}function jt(e){return e.d[e.d.length-1]&1}function nn(e,t,n){for(var r,o=new e(t[0]),i=0;++i<t.length;)if(r=new e(t[i]),r.s)o[n](r)&&(o=r);else{o=r;break}return o}function mt(e,t){var n,r,o,i,s,a,u,c=0,l=0,f=0,p=e.constructor,m=p.rounding,h=p.precision;if(!e.d||!e.d[0]||e.e>17)return new p(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(B=!1,u=h):u=t,a=new p(.03125);e.e>-2;)e=e.times(a),f+=5;for(r=Math.log(U(2,f))/Math.LN10*2+5|0,u+=r,n=i=s=new p(1),p.precision=u;;){if(i=A(i.times(e),u,1),n=n.times(++l),a=s.plus(R(i,n,u,1)),H(a.d).slice(0,u)===H(s.d).slice(0,u)){for(o=f;o--;)s=A(s.times(s),u,1);if(t==null)if(c<3&&Te(s.d,u-r,m,c))p.precision=u+=10,n=i=a=new p(1),l=0,c++;else return A(s,p.precision=h,m,B=!0);else return p.precision=h,s}s=a}}function ae(e,t){var n,r,o,i,s,a,u,c,l,f,p,m=1,h=10,g=e,w=g.d,x=g.constructor,P=x.rounding,y=x.precision;if(g.s<0||!w||!w[0]||!g.e&&w[0]==1&&w.length==1)return new x(w&&!w[0]?-1/0:g.s!=1?NaN:w?0:g);if(t==null?(B=!1,l=y):l=t,x.precision=l+=h,n=H(w),r=n.charAt(0),Math.abs(i=g.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)g=g.times(e),n=H(g.d),r=n.charAt(0),m++;i=g.e,r>1?(g=new x("0."+n),i++):g=new x(r+"."+n.slice(1))}else return c=Ve(x,l+2,y).times(i+""),g=ae(new x(r+"."+n.slice(1)),l-h).plus(c),x.precision=y,t==null?A(g,y,P,B=!0):g;for(f=g,u=s=g=R(g.minus(1),g.plus(1),l,1),p=A(g.times(g),l,1),o=3;;){if(s=A(s.times(p),l,1),c=u.plus(R(s,new x(o),l,1)),H(c.d).slice(0,l)===H(u.d).slice(0,l))if(u=u.times(2),i!==0&&(u=u.plus(Ve(x,l+2,y).times(i+""))),u=R(u,new x(m),l,1),t==null)if(Te(u.d,l-h,P,a))x.precision=l+=h,c=s=g=R(f.minus(1),f.plus(1),l,1),p=A(g.times(g),l,1),o=a=1;else return A(u,x.precision=y,P,B=!0);else return x.precision=y,u;u=c,o+=2}}function rn(e){return String(e.s*e.s/0)}function dt(e,t){var n,r,o;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(o=t.length;t.charCodeAt(o-1)===48;--o);if(t=t.slice(r,o),t){if(o-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%C,n<0&&(r+=C),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=C;r<o;)e.d.push(+t.slice(r,r+=C));t=t.slice(r),r=C-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),B&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Yn(e,t){var n,r,o,i,s,a,u,c,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),$t.test(t))return dt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Gn.test(t))n=16,t=t.toLowerCase();else if(qn.test(t))n=2;else if(Hn.test(t))n=8;else throw Error(ce+t);for(i=t.search(/p/i),i>0?(u=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=tn(r,new r(n),i,i*2)),c=Ke(t,n,Q),l=c.length-1,i=l;c[i]===0;--i)c.pop();return i<0?new r(e.s*0):(e.e=Ue(c,l),e.d=c,B=!1,s&&(e=R(e,o,a*4)),u&&(e=e.times(Math.abs(u)<54?U(2,u):Ge.pow(2,u))),B=!0,e)}function Xn(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:ge(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/qe(5,n)),t=ge(e,2,t,t);for(var o,i=new e(5),s=new e(16),a=new e(20);n--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(a))));return t}function ge(e,t,n,r,o){var i,s,a,u,c=1,l=e.precision,f=Math.ceil(l/C);for(B=!1,u=n.times(n),a=new e(r);;){if(s=R(a.times(u),new e(t++*t++),l,1),a=o?r.plus(s):r.minus(s),r=R(s.times(u),new e(t++*t++),l,1),s=a.plus(r),s.d[f]!==void 0){for(i=f;s.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=r,r=s,s=i,c++}return B=!0,s.d.length=f+1,s}function qe(e,t){for(var n=e;--t;)n*=e;return n}function on(e,t){var n,r=t.s<0,o=X(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return te=r?4:1,t;if(n=t.divToInt(o),n.isZero())te=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return te=jt(n)?r?2:3:r?4:1,t;te=jt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function ht(e,t,n,r){var o,i,s,a,u,c,l,f,p,m=e.constructor,h=n!==void 0;if(h?(Y(n,1,ue),r===void 0?r=m.rounding:Y(r,0,8)):(n=m.precision,r=m.rounding),!e.isFinite())l=rn(e);else{for(l=ee(e),s=l.indexOf("."),h?(o=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):o=t,s>=0&&(l=l.replace(".",""),p=new m(1),p.e=l.length-s,p.d=Ke(ee(p),10,o),p.e=p.d.length),f=Ke(l,10,o),i=u=f.length;f[--u]==0;)f.pop();if(!f[0])l=h?"0p+0":"0";else{if(s<0?i--:(e=new m(e),e.d=f,e.e=i,e=R(e,p,n,r,0,o),f=e.d,i=e.e,c=Yt),s=f[n],a=o/2,c=c||f[n+1]!==void 0,c=r<4?(s!==void 0||c)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||c||r===6&&f[n-1]&1||r===(e.s<0?8:7)),f.length=n,c)for(;++f[--n]>o-1;)f[n]=0,n||(++i,f.unshift(1));for(u=f.length;!f[u-1];--u);for(s=0,l="";s<u;s++)l+=lt.charAt(f[s]);if(h){if(u>1)if(t==16||t==8){for(s=t==16?4:3,--u;u%s;u++)l+="0";for(f=Ke(l,o,t),u=f.length;!f[u-1];--u);for(s=1,l="1.";s<u;s++)l+=lt.charAt(f[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)l="0"+l;l="0."+l}else if(++i>u)for(i-=u;i--;)l+="0";else i<u&&(l=l.slice(0,i)+"."+l.slice(i))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function zt(e,t){if(e.length>t)return e.length=t,!0}function Qn(e){return new this(e).abs()}function Jn(e){return new this(e).acos()}function $n(e){return new this(e).acosh()}function er(e,t){return new this(e).plus(t)}function tr(e){return new this(e).asin()}function nr(e){return new this(e).asinh()}function rr(e){return new this(e).atan()}function or(e){return new this(e).atanh()}function ir(e,t){e=new this(e),t=new this(t);var n,r=this.precision,o=this.rounding,i=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=X(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?X(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=X(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(R(e,t,i,1)),t=X(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(R(e,t,i,1)),n}function sr(e){return new this(e).cbrt()}function ar(e){return A(e=new this(e),e.e+1,2)}function cr(e,t,n){return new this(e).clamp(t,n)}function ur(e){if(!e||typeof e!="object")throw Error(We+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,ue,"rounding",0,8,"toExpNeg",-he,0,"toExpPos",0,he,"maxE",0,he,"minE",-he,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=ft[n]),(r=e[n])!==void 0)if(z(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(ce+n+": "+r);if(n="crypto",o&&(this[n]=ft[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Qt);else this[n]=!1;else throw Error(ce+n+": "+r);return this}function lr(e){return new this(e).cos()}function fr(e){return new this(e).cosh()}function sn(e){var t,n,r;function o(i){var s,a,u,c=this;if(!(c instanceof o))return new o(i);if(c.constructor=o,Zt(i)){c.s=i.s,B?!i.d||i.e>o.maxE?(c.e=NaN,c.d=null):i.e<o.minE?(c.e=0,c.d=[0]):(c.e=i.e,c.d=i.d.slice()):(c.e=i.e,c.d=i.d?i.d.slice():i.d);return}if(u=typeof i,u==="number"){if(i===0){c.s=1/i<0?-1:1,c.e=0,c.d=[0];return}if(i<0?(i=-i,c.s=-1):c.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;B?s>o.maxE?(c.e=NaN,c.d=null):s<o.minE?(c.e=0,c.d=[0]):(c.e=s,c.d=[i]):(c.e=s,c.d=[i]);return}else if(i*0!==0){i||(c.s=NaN),c.e=NaN,c.d=null;return}return dt(c,i.toString())}else if(u!=="string")throw Error(ce+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),c.s=-1):(a===43&&(i=i.slice(1)),c.s=1),$t.test(i)?dt(c,i):Yn(c,i)}if(o.prototype=d,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=ur,o.clone=sn,o.isDecimal=Zt,o.abs=Qn,o.acos=Jn,o.acosh=$n,o.add=er,o.asin=tr,o.asinh=nr,o.atan=rr,o.atanh=or,o.atan2=ir,o.cbrt=sr,o.ceil=ar,o.clamp=cr,o.cos=lr,o.cosh=fr,o.div=pr,o.exp=mr,o.floor=dr,o.hypot=hr,o.ln=gr,o.log=br,o.log10=wr,o.log2=yr,o.max=xr,o.min=Tr,o.mod=Pr,o.mul=Ar,o.pow=kr,o.random=Cr,o.round=Br,o.sign=Lr,o.sin=Sr,o.sinh=Ir,o.sqrt=Nr,o.sub=_r,o.sum=Er,o.tan=Rr,o.tanh=Mr,o.trunc=Dr,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return o.config(e),o}function pr(e,t){return new this(e).div(t)}function mr(e){return new this(e).exp()}function dr(e){return A(e=new this(e),e.e+1,3)}function hr(){var e,t,n=new this(0);for(B=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return B=!0,new this(1/0);n=t}return B=!0,n.sqrt()}function Zt(e){return e instanceof Ge||e&&e.toStringTag===Jt||!1}function gr(e){return new this(e).ln()}function br(e,t){return new this(e).log(t)}function yr(e){return new this(e).log(2)}function wr(e){return new this(e).log(10)}function xr(){return nn(this,arguments,"lt")}function Tr(){return nn(this,arguments,"gt")}function Pr(e,t){return new this(e).mod(t)}function Ar(e,t){return new this(e).mul(t)}function kr(e,t){return new this(e).pow(t)}function Cr(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:Y(e,1,ue),r=Math.ceil(e/C),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));i<r;)o=t[i],o>=429e7?t[i]=crypto.getRandomValues(new Uint32Array(1))[0]:a[i++]=o%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);i<r;)o=t[i]+(t[i+1]<<8)+(t[i+2]<<16)+((t[i+3]&127)<<24),o>=214e7?crypto.randomBytes(4).copy(t,i):(a.push(o%1e7),i+=4);i=r/4}else throw Error(Qt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=C,r&&e&&(o=U(10,C-e),a[i]=(r/o|0)*o);a[i]===0;i--)a.pop();if(i<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=C)a.shift();for(r=1,o=a[0];o>=10;o/=10)r++;r<C&&(n-=C-r)}return s.e=n,s.d=a,s}function Br(e){return A(e=new this(e),e.e+1,this.rounding)}function Lr(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Sr(e){return new this(e).sin()}function Ir(e){return new this(e).sinh()}function Nr(e){return new this(e).sqrt()}function _r(e,t){return new this(e).sub(t)}function Er(){var e=0,t=arguments,n=new this(t[e]);for(B=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return B=!0,A(n,this.precision,this.rounding)}function Rr(e){return new this(e).tan()}function Mr(e){return new this(e).tanh()}function Dr(e){return A(e=new this(e),e.e+1,1)}d[Symbol.for("nodejs.util.inspect.custom")]=d.toString;d[Symbol.toStringTag]="Decimal";var Ge=d.constructor=sn(ft);ve=new Ge(ve);Fe=new Ge(Fe);import qr from"big.js";import li from"bn.js";import Or from"toformat";var Kr=Or,Pe=Kr;import je from"big.js";import Fr from"bn.js";import Vr from"decimal.js-light";import Ae from"bn.js";var an=9007199254740991;function J(e){let t=j("Raydium_parseBigNumberish");if(e instanceof Ae)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new Ae(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=an||e<=-an)&&t.logWithError(`BigNumberish number overflow: ${e}`),new Ae(String(e))):typeof e=="bigint"?new Ae(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new Ae(0))}var He=j("module/fraction"),gt=Pe(je),ke=Pe(Vr),Wr={[0]:ke.ROUND_DOWN,[1]:ke.ROUND_HALF_UP,[2]:ke.ROUND_UP},Ur={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},O=class{constructor(t,n=new Fr(1)){this.numerator=J(t),this.denominator=J(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new O(this.denominator,this.numerator)}add(t){let n=t instanceof O?t:new O(J(t));return this.denominator.eq(n.denominator)?new O(this.numerator.add(n.numerator),this.denominator):new O(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof O?t:new O(J(t));return this.denominator.eq(n.denominator)?new O(this.numerator.sub(n.numerator),this.denominator):new O(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof O?t:new O(J(t));return new O(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof O?t:new O(J(t));return new O(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},r=1){Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<=0&&He.logWithError(`${t} is not positive.`),ke.set({precision:t+1,rounding:Wr[r]});let o=new ke(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},r=1){return Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<0&&He.logWithError(`${t} is negative.`),gt.DP=t,gt.RM=Ur[r]||1,new gt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var wi=j("Raydium_amount"),xi=Pe(qr);import{PublicKey as Hr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as cn}from"@solana/spl-token";var un={chainId:101,address:Hr.default.toBase58(),programId:cn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ne={chainId:101,address:"So11111111111111111111111111111111111111112",programId:cn.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 yt}from"@solana/web3.js";import{PublicKey as K,SystemProgram as ln,SYSVAR_RENT_PUBKEY as jr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as zr}from"@solana/spl-token";function bt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var Si=[bt({pubkey:zr,isWritable:!1}),bt({pubkey:ln.programId,isWritable:!1}),bt({pubkey:jr,isWritable:!1})];function fn({publicKey:e,transformSol:t}){let n=pn(e.toString());if(n instanceof K)return t&&n.equals(Ce)?ie:n;if(t&&n.toString()===Ce.toBase58())return ie;if(typeof n=="string"){if(n===K.default.toBase58())return K.default;try{return new K(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function pn(e){try{return new K(e)}catch{return e}}var Ii=new K("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ni=new K("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),_i=new K("SysvarRent111111111111111111111111111111111"),Ei=new K("SysvarC1ock11111111111111111111111111111111"),Ri=new K("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Mi=new K("Sysvar1nstructions1111111111111111111111111"),Di=ln.programId,Oi=new K("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Ki=new K("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),vi=new K("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Fi=new K("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Vi=new K("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Wi=new K("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ui=new K("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),qi=new K("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Gi=new K("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Hi=new K("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),ji=new K("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),ie=new K("So11111111111111111111111111111111111111112"),Ce=K.default;var wt=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Ce.toBase58()||t instanceof yt&&Ce.equals(t)){this.decimals=ne.decimals,this.symbol=ne.symbol,this.name=ne.name,this.mint=new yt(ne.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||t.toString().substring(0,6),this.name=o||t.toString().substring(0,6),this.mint=i?yt.default:fn({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},be=wt;be.WSOL=new wt(oe(V({},ne),{mint:ne.address}));var xt=class{constructor({decimals:t,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=r}equals(t){return this===t}},ze=xt;ze.SOL=new xt(un);import Zr from"bn.js";var os=new O(new Zr(100));var ls=j("Raydium_price");import{PublicKey as Ls}from"@solana/web3.js";import Is from"bn.js";var Yr=new re(0),Zs=new re(1),Ys=new re(2),Xs=new re(3),Qs=new re(5),Gr=new re(10),Js=new re(100),$s=new re(1e3),ea=new re(1e4);function ut(e,t=1,n=[]){let r=[...e];if(t<=0)return n;for(;r.length;)n.push(r.splice(0,t));return n}import{PublicKey as no}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ro}from"@solana/spl-token";import{ComputeBudgetProgram as gn,Keypair as yn,PublicKey as Xr,Transaction as wn,TransactionMessage as Qr,VersionedTransaction as xn}from"@solana/web3.js";var G={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"};import{TOKEN_PROGRAM_ID as Jr}from"@solana/spl-token";var bn=j("Raydium_txUtil"),Tn=1644;function Ze(e){let t=[],n=[];return e.microLamports&&(t.push(gn.setComputeUnitPrice({microLamports:e.microLamports})),n.push(G.SetComputeUnitPrice)),e.units&&(t.push(gn.setComputeUnitLimit({units:e.units})),n.push(G.SetComputeUnitLimit)),{instructions:t,instructionTypes:n}}async function ye(e,t){var r,o;let n=t!=null?t:"confirmed";return(o=await((r=e.getLatestBlockhash)==null?void 0:r.call(e,{commitment:n})))==null?void 0:o.blockhash}async function Ye(e,t){return e.getSignatureStatuses([t]),new Promise((n,r)=>{let o=setTimeout(r,6e4);e.onSignature(t,i=>{if(clearTimeout(o),!i.err){n("");return}r(i.err.toString())},"confirmed")})}function $r(e,t){e.length<1&&bn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&bn.logWithError(`no signers provided:, ${t.toString()}`);let n=new wn;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<Tn}catch{return!1}}function Pn(e,t){let[n,r]=Xr.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Be({instructions:e,payer:t,signers:n}){return $r(e,[t,...n])}function Le({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=yn.generate().publicKey.toString()}){let i=new Qr({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new xn(i).serialize()).toString("base64").length<Tn}catch{return!1}}var eo=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e),to=e=>{let t=e.serialize({requireAllSignatures:!1,verifySignatures:!1});e instanceof xn&&(t=eo(t));try{return t instanceof Buffer?t.toString("base64"):Buffer.from(t).toString("base64")}catch{return t.toString("base64")}};function de(e){let t=[];return e.forEach(n=>{n instanceof wn&&(n.recentBlockhash||(n.recentBlockhash=Jr.toBase58()),n.feePayer||(n.feePayer=yn.generate().publicKey)),t.push(to(n))}),console.log("simulate tx string:",t),t}function Xe(e,t,n){return Pn([e.toBuffer(),(n!=null?n:ro).toBuffer(),t.toBuffer()],new no("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as L}from"@solana/web3.js";var Ta=new L("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Pa=new L("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Aa=new L("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),ka=new L("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Ca=new L("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Ba=new L("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),La=new L("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Sa=new L("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ia=new L("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Na=new L("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),_a=new L("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Ea=new L("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Ra=new L("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Ma=new L("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Da=new L("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Oa=new L("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Ka=new L("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),va=new L("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Fa=new L("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Va=new L("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Wa=new L("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Ua=new L("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),oo=new L("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),io=new L("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),so=new L("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),qa=new L("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),ao=new L("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Ga=new L("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),co=new L("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var Ha={SERUM_MARKET:L.default,OPENBOOK_MARKET:new L("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:L.default,FarmV3:new L("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new L("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new L("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new L("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new L("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new L("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new L("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new L("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new L("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:oo,CREATE_CPMM_POOL_AUTH:io,CREATE_CPMM_POOL_FEE_ACC:so,FEE_DESTINATION_ID:new L("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:ao,LCOK_CPMM_AUTH:co};import Za from"bn.js";import{PublicKey as An,AddressLookupTableAccount as Qe}from"@solana/web3.js";async function Tt({connection:e,address:t}){let n=await Ht(e,[...new Set(t.map(o=>o.toString()))].map(o=>new An(o))),r={};for(let o=0;o<t.length;o++){let i=n[o],s=t[o];if(!i)continue;let a=new Qe({key:s,state:Qe.deserialize(i.data)});r[s.toString()]=a,Je[s.toString()]=a}return r}var Je={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new Qe({key:new An("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:Qe.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 Se,sendAndConfirmTransaction as Pt,Transaction as Ie,TransactionMessage as Ne,VersionedTransaction as _e}from"@solana/web3.js";import uo from"axios";var $e=class{constructor(t){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=t.connection,this.feePayer=t.feePayer,this.signAllTransactions=t.signAllTransactions,this.owner=t.owner,this.cluster=t.cluster,this.blockhashCommitment=t.blockhashCommitment,this.api=t.api}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}async getComputeBudgetConfig(){var r;let t=(await uo.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:n}=(r=t==null?void 0:t[15])!=null?r:{};if(!!n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}}addCustomComputeBudget(t){if(t){let{instructions:n,instructionTypes:r}=Ze(t);return this.instructions.unshift(...n),this.instructionTypes.unshift(...r),!0}return!1}async calComputeBudget({config:t,defaultIns:n}){try{let r=t||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(r))return;n&&this.instructions.unshift(...n)}catch{n&&this.instructions.unshift(...n)}}addInstruction({instructions:t=[],endInstructions:n=[],signers:r=[],instructionTypes:o=[],endInstructionTypes:i=[],lookupTableAddress:s=[]}){return this.instructions.push(...t),this.endInstructions.push(...n),this.signers.push(...r),this.instructionTypes.push(...o),this.endInstructionTypes.push(...i),this.lookupTableAddress.push(...s.filter(a=>a!==Se.default.toString())),this}async versionBuild({txVersion:t,extInfo:n}){return t===0?await this.buildV0(V({},n||{})):this.build(n)}build(t){var r;let n=new Ie;return this.allInstructions.length&&n.add(...this.allInstructions),n.feePayer=this.feePayer,((r=this.owner)==null?void 0:r.signer)&&!this.signers.some(o=>o.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer),{builder:this,transaction:n,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async o=>{var c;let{recentBlockHash:i,skipPreflight:s=!0,sendAndConfirm:a}=o||{},u=i!=null?i:await ye(this.connection,this.blockhashCommitment);if(n.recentBlockhash=u,this.signers.length&&n.sign(...this.signers),de([n]),(c=this.owner)!=null&&c.isKeyPair)return{txId:a?await Pt(this.connection,n,this.signers.find(f=>f.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:s}):await this.connection.sendRawTransaction(n.serialize(),{skipPreflight:s}),signedTx:n};if(this.signAllTransactions){let l=await this.signAllTransactions([n]);return{txId:await this.connection.sendRawTransaction(l[0].serialize(),{skipPreflight:s}),signedTx:l[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:t||{}}}buildMultiTx(t){var c;let{extraPreBuildData:n=[],extInfo:r}=t,{transaction:o}=this.build(r),i=n.filter(l=>l.transaction.instructions.length>0),s=[o,...i.map(l=>l.transaction)],a=[this.signers,...i.map(l=>l.signers)],u=[...this.instructionTypes,...i.map(l=>l.instructionTypes).flat()];return(c=this.owner)!=null&&c.signer&&a.forEach(l=>{l.some(f=>f.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),{builder:this,transactions:s,signers:a,instructionTypes:u,execute:async l=>{var x;let{sequentially:f,onTxUpdate:p,skipTxCount:m=0,recentBlockHash:h,skipPreflight:g=!0}=l||{},w=h!=null?h:await ye(this.connection,this.blockhashCommitment);if((x=this.owner)!=null&&x.isKeyPair){if(f){let P=[],y=0;for(let b of s){if(++y,y<=m)continue;let k=await Pt(this.connection,b,this.signers.find(T=>T.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:g});P.push(k)}return{txIds:P,signedTxs:s}}return{txIds:await await Promise.all(s.map(async P=>(P.recentBlockhash=w,await this.connection.sendRawTransaction(P.serialize(),{skipPreflight:g})))),signedTxs:s}}if(this.signAllTransactions){let P=s.map((b,k)=>(b.recentBlockhash=w,a[k].length&&b.sign(...a[k]),b));de(P);let y=await this.signAllTransactions(P);if(f){let b=0,k=[],T=async()=>{if(!y[b])return;let _=await this.connection.sendRawTransaction(y[b].serialize(),{skipPreflight:g});k.push({txId:_,status:"sent",signedTx:y[b]}),p==null||p([...k]),b++,this.connection.onSignature(_,S=>{let M=k.findIndex(Z=>Z.txId===_);M>-1&&(k[M].status=S.err?"error":"success"),p==null||p([...k]),S.err||T()},"processed"),this.connection.getSignatureStatus(_)};return await T(),{txIds:k.map(_=>_.txId),signedTxs:y}}else{let b=[];for(let k=0;k<y.length;k+=1){let T=await this.connection.sendRawTransaction(y[k].serialize(),{skipPreflight:g});b.push(T)}return{txIds:b,signedTxs:y}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async versionMultiBuild({extraPreBuildData:t,txVersion:n,extInfo:r}){return n===0?await this.buildV0MultiTx({extraPreBuildData:t,buildProps:r||{}}):this.buildMultiTx({extraPreBuildData:t,extInfo:r})}async buildV0(t){var g;let h=t||{},{lookupTableCache:n={},lookupTableAddress:r=[],forerunCreate:o,recentBlockhash:i}=h,s=me(h,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),a=V(V({},this.cluster==="devnet"?{}:Je),n),u=Array.from(new Set([...r,...this.lookupTableAddress])),c=[];for(let w of u)a[w]===void 0&&c.push(new Se(w));let l=await Tt({connection:this.connection,address:c});for(let[w,x]of Object.entries(l))a[w]=x;let f=o?Se.default.toBase58():i!=null?i:await ye(this.connection,this.blockhashCommitment),p=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...this.allInstructions]}).compileToV0Message(Object.values(a));((g=this.owner)==null?void 0:g.signer)&&!this.signers.some(w=>w.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer);let m=new _e(p);return m.sign(this.signers),{builder:this,transaction:m,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async w=>{var y;let{skipPreflight:x=!0,sendAndConfirm:P}=w||{};if(de([m]),(y=this.owner)!=null&&y.isKeyPair){let b=await this.connection.sendTransaction(m,{skipPreflight:x});return P&&await Ye(this.connection,b),{txId:b,signedTx:m}}if(this.signAllTransactions){let b=await this.signAllTransactions([m]);return{txId:await this.connection.sendTransaction(b[0],{skipPreflight:x}),signedTx:b[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}async buildV0MultiTx(t){var c;let{extraPreBuildData:n=[],buildProps:r}=t,{transaction:o}=await this.buildV0(r),i=n.filter(l=>l.builder.instructions.length>0),s=[o,...i.map(l=>l.transaction)],a=[this.signers,...i.map(l=>l.signers)],u=[...this.instructionTypes,...i.map(l=>l.instructionTypes).flat()];return(c=this.owner)!=null&&c.signer&&a.forEach(l=>{l.some(f=>f.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),s.forEach(async(l,f)=>{l.sign(a[f])}),{builder:this,transactions:s,signers:a,instructionTypes:u,buildProps:r,execute:async l=>{var g;let{sequentially:f,onTxUpdate:p,recentBlockHash:m,skipPreflight:h=!0}=l||{};if(m&&s.forEach(w=>w.message.recentBlockhash=m),de(s),(g=this.owner)!=null&&g.isKeyPair){if(f){let w=[];for(let x of s){let P=await this.connection.sendTransaction(x,{skipPreflight:h});await Ye(this.connection,P),w.push(P)}return{txIds:w,signedTxs:s}}return{txIds:await Promise.all(s.map(async w=>await this.connection.sendTransaction(w,{skipPreflight:h}))),signedTxs:s}}if(this.signAllTransactions){let w=await this.signAllTransactions(s);if(f){let x=0,P=[],y=async()=>{if(!w[x])return;let b=await this.connection.sendTransaction(w[x],{skipPreflight:h});P.push({txId:b,status:"sent",signedTx:w[x]}),p==null||p([...P]),x++,this.connection.onSignature(b,k=>{let T=P.findIndex(_=>_.txId===b);T>-1&&(P[T].status=k.err?"error":"success"),p==null||p([...P]),k.err||y()},"processed"),this.connection.getSignatureStatus(b)};return y(),{txIds:[],signedTxs:w}}else{let x=[];for(let P=0;P<w.length;P+=1){let y=await this.connection.sendTransaction(w[P],{skipPreflight:h});x.push(y)}return{txIds:x,signedTxs:w}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuild(t){var p;let f=t||{},{splitIns:n=[],computeBudgetConfig:r}=f,o=me(f,["splitIns","computeBudgetConfig"]),i=r?Ze(r):{instructions:[],instructionTypes:[]},s=this.signers.reduce((m,h)=>oe(V({},m),{[h.publicKey.toBase58()]:h}),{}),a=[],u=[],c=[],l=0;if(this.allInstructions.forEach(m=>{let h=[...c,m],g=r?[...i.instructions,...h]:h,x=[...new Set(h.map(P=>P.keys.filter(y=>y.isSigner).map(y=>y.pubkey.toString())).flat()).values()].map(P=>new Se(P));if(m!==n[l]&&c.length<12&&(Be({instructions:g,payer:this.feePayer,signers:x})||Be({instructions:h,payer:this.feePayer,signers:x})))c.push(m);else{if(c.length===0)throw Error("item ins too big");l+=m===n[l]?1:0,Be({instructions:r?[...i.instructions,...c]:[...c],payer:this.feePayer,signers:x})?a.push(new Ie().add(...i.instructions,...c)):a.push(new Ie().add(...c)),u.push(Array.from(new Set(c.map(P=>P.keys.filter(y=>y.isSigner).map(y=>y.pubkey.toString())).flat())).map(P=>s[P]).filter(P=>P!==void 0)),c=[m]}}),c.length>0){let h=[...new Set(c.map(g=>g.keys.filter(w=>w.isSigner).map(w=>w.pubkey.toString())).flat()).values()].map(g=>s[g]).filter(g=>g!==void 0);Be({instructions:r?[...i.instructions,...c]:[...c],payer:this.feePayer,signers:h.map(g=>g.publicKey)})?a.push(new Ie().add(...i.instructions,...c)):a.push(new Ie().add(...c)),u.push(h)}return a.forEach(m=>m.feePayer=this.feePayer),(p=this.owner)!=null&&p.signer&&u.forEach(m=>{m.some(h=>h.publicKey.equals(this.owner.publicKey))||m.push(this.owner.signer)}),{builder:this,transactions:a,signers:u,instructionTypes:this.instructionTypes,execute:async m=>{var b;let{sequentially:h,onTxUpdate:g,skipTxCount:w=0,recentBlockHash:x,skipPreflight:P=!0}=m||{},y=x!=null?x:await ye(this.connection,this.blockhashCommitment);if(a.forEach(async(k,T)=>{k.recentBlockhash=y,u[T].length&&k.sign(...u[T])}),de(a),(b=this.owner)!=null&&b.isKeyPair){if(h){let k=0,T=[];for(let _ of a){if(++k,k<=w){T.push("tx skipped");continue}let S=await Pt(this.connection,_,this.signers.find(M=>M.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:P});T.push(S)}return{txIds:T,signedTxs:a}}return{txIds:await Promise.all(a.map(async k=>await this.connection.sendRawTransaction(k.serialize(),{skipPreflight:P}))),signedTxs:a}}if(this.signAllTransactions){let k=await this.signAllTransactions(a.slice(w,a.length)),T=[...a.slice(0,w),...k];if(h){let _=0,S=[],M=async()=>{if(!T[_])return;_<w&&(S.push({txId:"",status:"success",signedTx:T[_]}),g==null||g([...S]),_++,M());let Z=await this.connection.sendRawTransaction(T[_].serialize(),{skipPreflight:P});S.push({txId:Z,status:"sent",signedTx:T[_]}),g==null||g([...S]),_++,this.connection.onSignature(Z,D=>{let v=S.findIndex(W=>W.txId===Z);v>-1&&(S[v].status=D.err?"error":"success"),g==null||g([...S]),D.err||M()},"processed"),this.connection.getSignatureStatus(Z)};return await M(),{txIds:S.map(Z=>Z.txId),signedTxs:T}}else{let _=[];for(let S=0;S<T.length;S+=1){let M=await this.connection.sendRawTransaction(T[S].serialize(),{skipPreflight:P});_.push(M)}return{txIds:_,signedTxs:T}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:o||{}}}async sizeCheckBuildV0(t){var y;let P=t||{},{computeBudgetConfig:n,splitIns:r=[],lookupTableCache:o={},lookupTableAddress:i=[]}=P,s=me(P,["computeBudgetConfig","splitIns","lookupTableCache","lookupTableAddress"]),a=V(V({},this.cluster==="devnet"?{}:Je),o),u=Array.from(new Set([...this.lookupTableAddress,...i])),c=[];for(let b of u)a[b]===void 0&&c.push(new Se(b));let l=await Tt({connection:this.connection,address:c});for(let[b,k]of Object.entries(l))a[b]=k;let f=n?Ze(n):{instructions:[],instructionTypes:[]},p=await ye(this.connection,this.blockhashCommitment),m=this.signers.reduce((b,k)=>oe(V({},b),{[k.publicKey.toBase58()]:k}),{}),h=[],g=[],w=[],x=0;if(this.allInstructions.forEach(b=>{let k=[...w,b],T=n?[...f.instructions,...k]:k;if(b!==r[x]&&w.length<12&&(Le({instructions:T,payer:this.feePayer,lookupTableAddressAccount:a})||Le({instructions:k,payer:this.feePayer,lookupTableAddressAccount:a})))w.push(b);else{if(w.length===0)throw Error("item ins too big");x+=b===r[x]?1:0;let _={};for(let S of[...new Set(u)])a[S]!==void 0&&(_[S]=a[S]);if(n&&Le({instructions:[...f.instructions,...w],payer:this.feePayer,lookupTableAddressAccount:a,recentBlockhash:p})){let S=new Ne({payerKey:this.feePayer,recentBlockhash:p,instructions:[...f.instructions,...w]}).compileToV0Message(Object.values(a));h.push(new _e(S))}else{let S=new Ne({payerKey:this.feePayer,recentBlockhash:p,instructions:[...w]}).compileToV0Message(Object.values(a));h.push(new _e(S))}g.push(Array.from(new Set(w.map(S=>S.keys.filter(M=>M.isSigner).map(M=>M.pubkey.toString())).flat())).map(S=>m[S]).filter(S=>S!==void 0)),w=[b]}}),w.length>0){let k=[...new Set(w.map(T=>T.keys.filter(_=>_.isSigner).map(_=>_.pubkey.toString())).flat()).values()].map(T=>m[T]).filter(T=>T!==void 0);if(n&&Le({instructions:[...f.instructions,...w],payer:this.feePayer,lookupTableAddressAccount:a,recentBlockhash:p})){let T=new Ne({payerKey:this.feePayer,recentBlockhash:p,instructions:[...f.instructions,...w]}).compileToV0Message(Object.values(a));h.push(new _e(T))}else{let T=new Ne({payerKey:this.feePayer,recentBlockhash:p,instructions:[...w]}).compileToV0Message(Object.values(a));h.push(new _e(T))}g.push(k)}return(y=this.owner)!=null&&y.signer&&g.forEach(b=>{b.some(k=>k.publicKey.equals(this.owner.publicKey))||b.push(this.owner.signer)}),{builder:this,transactions:h,buildProps:t,signers:g,instructionTypes:this.instructionTypes,execute:async b=>{var Z;let{sequentially:k,onTxUpdate:T,skipTxCount:_=0,recentBlockHash:S,skipPreflight:M=!0}=b||{};if(h.map(async(D,v)=>{g[v].length&&D.sign(g[v]),S&&(D.message.recentBlockhash=S)}),de(h),(Z=this.owner)!=null&&Z.isKeyPair){if(k){let D=0,v=[];for(let W of h){if(++D,D<=_){console.log("skip tx: ",D),v.push("tx skipped");continue}let q=await this.connection.sendTransaction(W,{skipPreflight:M});await Ye(this.connection,q),v.push(q)}return{txIds:v,signedTxs:h}}return{txIds:await Promise.all(h.map(async D=>await this.connection.sendTransaction(D,{skipPreflight:M}))),signedTxs:h}}if(this.signAllTransactions){let D=await this.signAllTransactions(h.slice(_,h.length)),v=[...h.slice(0,_),...D];if(k){let W=0,q=[],F=async()=>{if(!v[W])return;if(W<_){q.push({txId:"",status:"success",signedTx:v[W]}),T==null||T([...q]),W++,F();return}let E=await this.connection.sendTransaction(v[W],{skipPreflight:M});q.push({txId:E,status:"sent",signedTx:v[W]}),T==null||T([...q]),W++,this.connection.onSignature(E,vt=>{let Ft=q.findIndex(On=>On.txId===E);Ft>-1&&(q[Ft].status=vt.err?"error":"success"),T==null||T([...q]),vt.err||F()},"processed"),this.connection.getSignatureStatus(E)};return F(),{txIds:[],signedTxs:v}}else{let W=[];for(let q=0;q<v.length;q+=1){let F=await this.connection.sendTransaction(v[q],{skipPreflight:M});W.push(F)}return{txIds:W,signedTxs:v}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}};import{AccountLayout as xe,createAssociatedTokenAccountInstruction as Ot,TOKEN_PROGRAM_ID as pe,TOKEN_2022_PROGRAM_ID as _o}from"@solana/spl-token";var At=(...e)=>e.map(t=>{try{return typeof t=="object"?JSON.stringify(t):t}catch{return t}}).join(", "),Ee=class{constructor({scope:t,moduleName:n}){this.disabled=!1;this.scope=t,this.logger=j(n)}createTxBuilder(t){return this.scope.checkOwner(),new $e({connection:this.scope.connection,feePayer:t||this.scope.ownerPubKey,cluster:this.scope.cluster,owner:this.scope.owner,blockhashCommitment:this.scope.blockhashCommitment,api:this.scope.api,signAllTransactions:this.scope.signAllTransactions})}logDebug(...t){this.logger.debug(At(t))}logInfo(...t){this.logger.info(At(t))}logAndCreateError(...t){let n=At(t);throw new Error(n)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};import{PublicKey as ko,SystemProgram as Co}from"@solana/web3.js";import Bo from"bn.js";import{createCloseAccountInstruction as Lo,createInitializeAccountInstruction as So,createTransferInstruction as Io,TOKEN_PROGRAM_ID as we}from"@solana/spl-token";import{Keypair as xo,PublicKey as Rn}from"@solana/web3.js";import To from"bn.js";import{TOKEN_PROGRAM_ID as Po}from"@solana/spl-token";function lo(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function kt(e,...t){if(!lo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ct(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function kn(e,t){kt(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var tt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),$=(e,t)=>e<<32-t|e>>>t;var Oc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function fo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Bt(e){return typeof e=="string"&&(e=fo(e)),kt(e),e}var et=class{clone(){return this._cloneInto()}},Kc={}.toString;function Cn(e){let t=r=>e().update(Bt(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function po(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);let o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),a=Number(n&i),u=r?4:0,c=r?0:4;e.setUint32(t+u,s,r),e.setUint32(t+c,a,r)}var Bn=(e,t,n)=>e&t^~e&n,Ln=(e,t,n)=>e&t^e&n^t&n,nt=class extends et{constructor(t,n,r,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=tt(this.buffer)}update(t){Ct(this);let{view:n,buffer:r,blockLen:o}=this;t=Bt(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let u=tt(t);for(;o<=i-s;s+=o)this.process(u,s);continue}r.set(t.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ct(this),kn(t,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(r,0),s=0);for(let f=s;f<o;f++)n[f]=0;po(r,o-8,BigInt(this.length*8),i),this.process(r,0);let a=tt(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let c=u/4,l=this.get();if(c>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<c;f++)a.setUint32(4*f,l[f],i)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:a}=this;return t.length=o,t.pos=a,t.finished=i,t.destroyed=s,o%n&&t.buffer.set(r),t}};var mo=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]),fe=new Uint32Array(64),Lt=class extends nt{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:n,C:r,D:o,E:i,F:s,G:a,H:u}=this;return[t,n,r,o,i,s,a,u]}set(t,n,r,o,i,s,a,u){this.A=t|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=a|0,this.H=u|0}process(t,n){for(let f=0;f<16;f++,n+=4)fe[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){let p=fe[f-15],m=fe[f-2],h=$(p,7)^$(p,18)^p>>>3,g=$(m,17)^$(m,19)^m>>>10;fe[f]=g+fe[f-7]+h+fe[f-16]|0}let{A:r,B:o,C:i,D:s,E:a,F:u,G:c,H:l}=this;for(let f=0;f<64;f++){let p=$(a,6)^$(a,11)^$(a,25),m=l+p+Bn(a,u,c)+mo[f]+fe[f]|0,g=($(r,2)^$(r,13)^$(r,22))+Ln(r,o,i)|0;l=c,c=u,u=a,a=s+m|0,s=i,i=o,o=r,r=m+g|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,a=a+this.E|0,u=u+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(r,o,i,s,a,u,c,l)}roundClean(){fe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Sn=Cn(()=>new Lt);import{PublicKey as wo}from"@solana/web3.js";import Nn,{isBN as Hu}from"bn.js";import{bits as jc,BitStructure as zc,blob as ho,Blob as Zc,cstr as Yc,f32 as Xc,f32be as Qc,f64 as Jc,f64be as $c,greedy as eu,Layout as go,ns64 as tu,ns64be as nu,nu64 as ru,nu64be as ou,offset as iu,s16 as su,s16be as au,s24 as cu,s24be as uu,s32 as lu,s32be as fu,s40 as pu,s40be as mu,s48 as du,s48be as hu,s8 as gu,seq as bu,struct as yu,Structure as bo,u16 as wu,u16be as xu,u24 as Tu,u24be as Pu,u32 as Au,u32be as ku,u40 as Cu,u40be as Bu,u48 as Lu,u48be as Su,u8 as Iu,UInt as yo,union as Nu,Union as _u,unionLayoutDiscriminator as Eu,utf8 as Ru}from"@solana/buffer-layout";var St=go,In=bo;var It=yo;var Nt=ho;var _t=class extends St{constructor(n,r,o){super(n,o);this.blob=Nt(n),this.signed=r}decode(n,r=0){let o=new Nn(this.blob.decode(n,r),10,"le");return this.signed?o.fromTwos(this.span*8).clone():o}encode(n,r,o=0){return typeof n=="number"&&(n=new Nn(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function _n(e){return new It(1,e)}function rt(e){return new It(4,e)}function ot(e){return new _t(8,!1,e)}var Et=class extends St{constructor(n,r,o,i){super(n.span,i);this.layout=n,this.decoder=r,this.encoder=o}decode(n,r){return this.decoder(this.layout.decode(n,r))}encode(n,r,o){return this.layout.encode(this.encoder(n),r,o)}getSpan(n,r){return this.layout.getSpan(n,r)}};function Re(e){return new Et(Nt(32),t=>new wo(t),t=>t.toBuffer(),e)}var Rt=class extends In{decode(t,n){return super.decode(t,n)}};function En(e,t,n){return new Rt(e,t,n)}var Me=En([Re("mint"),Re("owner"),ot("amount"),rt("delegateOption"),Re("delegate"),_n("state"),rt("isNativeOption"),ot("isNative"),ot("delegatedAmount"),rt("closeAuthorityOption"),Re("closeAuthority")]);var sl=j("Raydium_Util");function Mn({owner:e,solAccountResp:t,tokenAccountResp:n}){let r=[],o=[];for(let{pubkey:i,account:s}of n.value){let a=Me.decode(s.data),{mint:u,amount:c}=a;r.push({publicKey:i,mint:u,amount:c,isAssociated:Xe(e,u,s.owner).publicKey.equals(i),isNative:!1,programId:s.owner}),o.push({pubkey:i,accountInfo:a,programId:s.owner})}return t&&r.push({mint:Rn.default,amount:new To(String(t.lamports)),isNative:!0,programId:t.owner}),{tokenAccounts:r,tokenAccountRawInfos:o}}function it({fromPublicKey:e,programId:t=Po,assignSeed:n}){let r=n?btoa(n).slice(0,32):xo.generate().publicKey.toBase58().slice(0,32);return{publicKey:Ao(e,r,t),seed:r}}function Ao(e,t,n){let r=Buffer.concat([e.toBuffer(),Buffer.from(t),n.toBuffer()]),o=Sn(r);return new Rn(o)}function Mt(e){let{mint:t,tokenAccount:n,owner:r,programId:o=we}=e;return So(n,t,r,o)}function De(e){let{tokenAccount:t,payer:n,multiSigners:r=[],owner:o,programId:i=we}=e;return Lo(t,n,o,r,i)}async function Dt(e){let{connection:t,amount:n,commitment:r,payer:o,owner:i,skipCloseAccount:s}=e,a=await t.getMinimumBalanceForRentExemption(Me.span,r),u=J(n).add(new Bo(a)),c=it({fromPublicKey:o,programId:we});return{addresses:{newAccount:c.publicKey},signers:[],instructions:[Co.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:c.seed,newAccountPubkey:c.publicKey,lamports:u.toNumber(),space:Me.span,programId:we}),Mt({mint:new ko(ne.address),tokenAccount:c.publicKey,owner:i,programId:we})],instructionTypes:[G.CreateAccount,G.InitAccount],endInstructionTypes:s?[]:[G.CloseAccount],endInstructions:s?[]:[De({tokenAccount:c.publicKey,payer:o,owner:i})]}}function Dn({source:e,destination:t,owner:n,amount:r,multiSigners:o=[],tokenProgram:i=we}){return Io(e,t,n,BigInt(String(r)),o,i)}var Kt=class extends Ee{constructor(n){super(n);this._tokenAccounts=[];this._tokenAccountRawInfos=[];this._accountListener=[];this._clientOwnedToken=!1;this._notSubscribeAccountChange=!1;this._accountFetchTime=0;let{tokenAccounts:r,tokenAccountRawInfos:o,notSubscribeAccountChange:i}=n;this._tokenAccounts=r||[],this._tokenAccountRawInfos=o||[],this._notSubscribeAccountChange=i!=null?i:!0,this._clientOwnedToken=!!(r||o)}get tokenAccounts(){return this._tokenAccounts}get tokenAccountRawInfos(){return this._tokenAccountRawInfos}set notSubscribeAccountChange(n){this._notSubscribeAccountChange=n}updateTokenAccount({tokenAccounts:n,tokenAccountRawInfos:r}){return n&&(this._tokenAccounts=n),r&&(this._tokenAccountRawInfos=r),this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=void 0,this._clientOwnedToken=!0,this}addAccountChangeListener(n){return this._accountListener.push(n),this}removeAccountChangeListener(n){return this._accountListener=this._accountListener.filter(r=>r!==n),this}getAssociatedTokenAccount(n,r){return Xe(this.scope.ownerPubKey,n,r).publicKey}resetTokenAccounts(){this._clientOwnedToken||(this._tokenAccounts=[],this._tokenAccountRawInfos=[])}async fetchWalletTokenAccounts(n){if(this._clientOwnedToken||!(n!=null&&n.forceUpdate)&&this._tokenAccounts.length&&Date.now()-this._accountFetchTime<(this._notSubscribeAccountChange?1e3*5:1e3*60*3))return{tokenAccounts:this._tokenAccounts,tokenAccountRawInfos:this._tokenAccountRawInfos};this.scope.checkOwner();let o=V(V({},{}),n),[i,s,a]=await Promise.all([this.scope.connection.getAccountInfo(this.scope.ownerPubKey,o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:pe},o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:_o},o.commitment)]),{tokenAccounts:u,tokenAccountRawInfos:c}=Mn({owner:this.scope.ownerPubKey,solAccountResp:i,tokenAccountResp:{context:s.context,value:[...s.value,...a.value]}});return this._tokenAccounts=u,this._tokenAccountRawInfos=c,this._accountFetchTime=Date.now(),this._notSubscribeAccountChange||(this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=this.scope.connection.onAccountChange(this.scope.ownerPubKey,()=>{this.fetchWalletTokenAccounts({forceUpdate:!0}),this._accountListener.forEach(l=>l({tokenAccounts:this._tokenAccounts,tokenAccountRawInfos:this._tokenAccountRawInfos}))},{commitment:n==null?void 0:n.commitment})),{tokenAccounts:u,tokenAccountRawInfos:c}}clearAccountChangeCkb(){this._accountChangeListenerId!==void 0&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId)}async getCreatedTokenAccount({mint:n,programId:r=pe,associatedOnly:o=!0}){await this.fetchWalletTokenAccounts();let i=this._tokenAccounts.filter(({mint:a})=>a==null?void 0:a.equals(n)).sort((a,u)=>a.amount.lt(u.amount)?1:-1),s=this.getAssociatedTokenAccount(n,r);for(let a of i){let{publicKey:u}=a;if(u&&(!o||o&&s.equals(u)))return u}}async getOrCreateTokenAccount(n){var g,w,x,P;await this.fetchWalletTokenAccounts();let{mint:r,createInfo:o,associatedOnly:i,owner:s,notUseTokenAccount:a=!1,skipCloseAccount:u=!1,checkCreateATAOwner:c=!1,assignSeed:l}=n,f=new st(n.tokenProgram||pe),p=this.getAssociatedTokenAccount(r,new st(f)),m=(a?[]:this.tokenAccountRawInfos).filter(y=>y.accountInfo.mint.equals(r)&&(!i||y.pubkey.equals(p))).sort((y,b)=>y.accountInfo.amount.lt(b.accountInfo.amount)?1:-1);if(o===void 0||m.length>0)return m.length>0?{account:m[0].pubkey}:{};let h={instructions:[],endInstructions:[],signers:[],instructionTypes:[],endInstructionTypes:[]};if(i){let y=Ot(s,p,s,r,f);if(c){let b=await this.scope.connection.getAccountInfo(p);if(b===null)(g=h.instructions)==null||g.push(y),h.instructionTypes.push(G.CreateATA);else if(!(b.owner.equals(f)&&xe.decode(b.data).mint.equals(r)&&xe.decode(b.data).owner.equals(s)))throw Error(`create ata check error -> mint: ${r.toString()}, ata: ${p.toString()}`)}else h.instructions.push(y),h.instructionTypes.push(G.CreateATA);if(r.equals(ie)&&o.amount){let b=await Dt({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:o.payer||this.scope.ownerPubKey,amount:(w=o.amount)!=null?w:0,skipCloseAccount:u});h.instructions.push(...b.instructions||[]),h.endInstructions.push(...b.endInstructions||[]),h.instructionTypes.push(...b.instructionTypes||[]),h.endInstructionTypes.push(...b.endInstructionTypes||[]),o.amount&&(h.instructions.push(Dn({source:b.addresses.newAccount,destination:p,owner:this.scope.ownerPubKey,amount:o.amount,tokenProgram:pe})),h.instructionTypes.push(G.TransferAmount))}return u||(h.endInstructions.push(De({owner:s,payer:o.payer||s,tokenAccount:p,programId:f})),h.endInstructionTypes.push(G.CloseAccount)),{account:p,instructionParams:h}}else{let y=it({fromPublicKey:s,programId:f,assignSeed:l}),b=await this.scope.connection.getMinimumBalanceForRentExemption(xe.span),k=No.createAccountWithSeed({fromPubkey:s,basePubkey:s,seed:y.seed,newAccountPubkey:y.publicKey,lamports:b+Number((P=(x=o.amount)==null?void 0:x.toString())!=null?P:0),space:xe.span,programId:f});return h.instructions.push(k,Mt({mint:r,tokenAccount:y.publicKey,owner:this.scope.ownerPubKey,programId:f})),h.instructionTypes.push(G.CreateAccount),h.instructionTypes.push(G.InitAccount),u||(h.endInstructions.push(De({owner:s,payer:o.payer||s,tokenAccount:y.publicKey,programId:f})),h.endInstructionTypes.push(G.CloseAccount)),{account:y.publicKey,instructionParams:h}}}async checkOrCreateAta({mint:n,programId:r=pe,autoUnwrapWSOLToSOL:o}){var u;await this.fetchWalletTokenAccounts();let i=(u=this.scope.account.tokenAccounts.find(({mint:c})=>(c==null?void 0:c.toBase58())===n.toBase58()))==null?void 0:u.publicKey,s=this.scope.ownerPubKey,a={};if(!i){let c=this.getAssociatedTokenAccount(n,r),l=await Ot(s,c,s,n,r);a.instructions=[l],a.instructionTypes=[G.CreateATA],i=c}return o&&ie.toBase58()===n.toBase58()&&(a.endInstructions=[De({owner:s,payer:s,tokenAccount:i,programId:r})],a.endInstructionTypes=[G.CloseAccount]),{pubKey:i,newInstructions:a}}async handleTokenAccount(n){let{side:r,amount:o,mint:i,programId:s=pe,tokenAccount:a,payer:u=this.scope.ownerPubKey,bypassAssociatedCheck:c,skipCloseAccount:l,checkCreateATAOwner:f}=n,p=this.getAssociatedTokenAccount(i,s);if(new st(ie).equals(i)){let m=await Dt({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:u,amount:o,skipCloseAccount:l});return V({tokenAccount:m.addresses.newAccount},m)}else if(!a||r==="out"&&!p.equals(a)&&!c){let m=[],h=Ot(this.scope.ownerPubKey,p,this.scope.ownerPubKey,i,s);if(f){let g=await this.scope.connection.getAccountInfo(p);if(g===null)m.push(h);else if(!(g.owner.equals(pe)&&xe.decode(g.data).mint.equals(i)&&xe.decode(g.data).owner.equals(this.scope.ownerPubKey)))throw Error(`create ata check error -> mint: ${i.toString()}, ata: ${p.toString()}`)}else m.push(h);return{tokenAccount:p,instructions:m,instructionTypes:[G.CreateATA]}}return{tokenAccount:a}}async processTokenAccount(n){let{mint:r,programId:o=pe,amount:i,useSOLBalance:s,handleTokenAccount:a}=n,u,c=this.createTxBuilder();if(r.equals(new st(ie))&&s){let l=await this.handleTokenAccount({side:"in",amount:i||0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=l,m=me(l,["tokenAccount"]);u=p,c.addInstruction(m)}else if(u=await this.getCreatedTokenAccount({mint:r,associatedOnly:!1,programId:o}),!u&&a){let f=await this.scope.account.handleTokenAccount({side:"in",amount:0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=f,m=me(f,["tokenAccount"]);u=p,c.addInstruction(m)}return V({tokenAccount:u},c.AllTxData)}};export{Kt as default};
|
|
1
|
+
var Kn=Object.defineProperty,vn=Object.defineProperties;var Fn=Object.getOwnPropertyDescriptors;var Oe=Object.getOwnPropertySymbols;var Wt=Object.prototype.hasOwnProperty,Ut=Object.prototype.propertyIsEnumerable;var Vt=(e,t,n)=>t in e?Kn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,V=(e,t)=>{for(var n in t||(t={}))Wt.call(t,n)&&Vt(e,n,t[n]);if(Oe)for(var n of Oe(t))Ut.call(t,n)&&Vt(e,n,t[n]);return e},oe=(e,t)=>vn(e,Fn(t));var me=(e,t)=>{var n={};for(var r in e)Wt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&Oe)for(var r of Oe(e))t.indexOf(r)<0&&Ut.call(e,r)&&(n[r]=e[r]);return n};import{PublicKey as st,SystemProgram as No}from"@solana/web3.js";import{PublicKey as Un}from"@solana/web3.js";import{get as qt,set as Vn}from"lodash";var ct=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 n=t.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},Gt={},Wn={};function j(e){let t=qt(Gt,e);if(!t){let n=qt(Wn,e);t=new ct({name:e,logLevel:n}),Vn(Gt,e,t)}return t}import{MINT_SIZE as Uo,TOKEN_PROGRAM_ID as qo,getTransferFeeConfig as Go,unpackMint as Ho}from"@solana/spl-token";var at=j("Raydium_accountInfo_util");async function Ht(e,t,n){let{batchRequest:r,commitment:o="confirmed",chunkCount:i=100}=V({batchRequest:!1},n),s=ut(t,i),c=new Array(s.length).fill([]);if(r){let u=s.map(f=>{let p=e._buildArgs([f.map(m=>m.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:p}}),a=ut(u,10);c=(await(await Promise.all(a.map(async f=>await e._rpcBatchRequest(f)))).flat()).map(f=>(f.error&&at.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${f.error.message}`),f.result.value.map(p=>{if(p){let{data:m,executable:h,lamports:g,owner:y,rentEpoch:T}=p;return m.length!==2&&m[1]!=="base64"&&at.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(m[0],"base64"),executable:h,lamports:g,owner:new Un(y),rentEpoch:T}}return null})))}else try{c=await Promise.all(s.map(u=>e.getMultipleAccountsInfo(u,o)))}catch(u){u instanceof Error&&at.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${u.message}`)}return c.flat()}import re from"bn.js";var he=9e15,ue=1e9,lt="0123456789abcdef",ve="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Fe="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ft={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-he,maxE:he,crypto:!1},Yt,te,B=!0,We="[DecimalError] ",ae=We+"Invalid argument: ",Xt=We+"Precision limit exceeded",Qt=We+"crypto unavailable",Jt="[object Decimal]",z=Math.floor,U=Math.pow,qn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Gn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Hn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,$t=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Q=1e7,C=7,jn=9007199254740991,zn=ve.length-1,pt=Fe.length-1,d={toStringTag:Jt};d.absoluteValue=d.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),k(e)};d.ceil=function(){return k(new this.constructor(this),this.e+1,2)};d.clampedTo=d.clamp=function(e,t){var n,r=this,o=r.constructor;if(e=new o(e),t=new o(t),!e.s||!t.s)return new o(NaN);if(e.gt(t))throw Error(ae+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new o(r)};d.comparedTo=d.cmp=function(e){var t,n,r,o,i=this,s=i.d,c=(e=new i.constructor(e)).d,u=i.s,a=e.s;if(!s||!c)return!u||!a?NaN:u!==a?u:s===c?0:!s^u<0?1:-1;if(!s[0]||!c[0])return s[0]?u:c[0]?-a:0;if(u!==a)return u;if(i.e!==e.e)return i.e>e.e^u<0?1:-1;for(r=s.length,o=c.length,t=0,n=r<o?r:o;t<n;++t)if(s[t]!==c[t])return s[t]>c[t]^u<0?1:-1;return r===o?0:r>o^u<0?1:-1};d.cosine=d.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+C,r.rounding=1,n=Zn(r,on(r,n)),r.precision=e,r.rounding=t,k(te==2||te==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};d.cubeRoot=d.cbrt=function(){var e,t,n,r,o,i,s,c,u,a,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(B=!1,i=l.s*U(l.s*l,1/3),!i||Math.abs(i)==1/0?(n=H(l.d),e=l.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=U(n,1/3),e=z((e+1)/3)-(e%3==(e<0?-1:2)),i==1/0?n="5e"+e:(n=i.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new f(n),r.s=l.s):r=new f(i.toString()),s=(e=f.precision)+3;;)if(c=r,u=c.times(c).times(c),a=u.plus(l),r=R(a.plus(l).times(c),a.plus(u),s+2,1),H(c.d).slice(0,s)===(n=H(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(k(c,e+1,0),c.times(c).times(c).eq(l))){r=c;break}s+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(k(r,e+1,1),t=!r.times(r).times(r).eq(l));break}return B=!0,k(r,e,f.rounding,t)};d.decimalPlaces=d.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-z(this.e/C))*C,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};d.dividedBy=d.div=function(e){return R(this,new this.constructor(e))};d.dividedToIntegerBy=d.divToInt=function(e){var t=this,n=t.constructor;return k(R(t,new n(e),0,1,1),n.precision,n.rounding)};d.equals=d.eq=function(e){return this.cmp(e)===0};d.floor=function(){return k(new this.constructor(this),this.e+1,3)};d.greaterThan=d.gt=function(e){return this.cmp(e)>0};d.greaterThanOrEqualTo=d.gte=function(e){var t=this.cmp(e);return t==1||t===0};d.hyperbolicCosine=d.cosh=function(){var e,t,n,r,o,i=this,s=i.constructor,c=new s(1);if(!i.isFinite())return new s(i.s?1/0:NaN);if(i.isZero())return c;n=s.precision,r=s.rounding,s.precision=n+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(e=Math.ceil(o/3),t=(1/qe(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=ge(s,1,i.times(t),new s(1),!0);for(var u,a=e,l=new s(8);a--;)u=i.times(i),i=c.minus(u.times(l.minus(u.times(l))));return k(i,s.precision=n,s.rounding=r,!0)};d.hyperbolicSine=d.sinh=function(){var e,t,n,r,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(t=i.precision,n=i.rounding,i.precision=t+Math.max(o.e,o.sd())+4,i.rounding=1,r=o.d.length,r<3)o=ge(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/qe(5,e)),o=ge(i,2,o,o,!0);for(var s,c=new i(5),u=new i(16),a=new i(20);e--;)s=o.times(o),o=o.times(c.plus(s.times(u.times(s).plus(a))))}return i.precision=t,i.rounding=n,k(o,t,n,!0)};d.hyperbolicTangent=d.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,R(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};d.inverseCosine=d.acos=function(){var e,t=this,n=t.constructor,r=t.abs().cmp(1),o=n.precision,i=n.rounding;return r!==-1?r===0?t.isNeg()?X(n,o,i):new n(0):new n(NaN):t.isZero()?X(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=X(n,o+4,i).times(.5),n.precision=o,n.rounding=i,e.minus(t))};d.inverseHyperbolicCosine=d.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,B=!1,n=n.times(n).minus(1).sqrt().plus(n),B=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};d.inverseHyperbolicSine=d.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,B=!1,n=n.times(n).plus(1).sqrt().plus(n),B=!0,r.precision=e,r.rounding=t,n.ln())};d.inverseHyperbolicTangent=d.atanh=function(){var e,t,n,r,o=this,i=o.constructor;return o.isFinite()?o.e>=0?new i(o.abs().eq(1)?o.s/0:o.isZero()?o:NaN):(e=i.precision,t=i.rounding,r=o.sd(),Math.max(r,e)<2*-o.e-1?k(new i(o),e,t,!0):(i.precision=n=r-o.e,o=R(o.plus(1),new i(1).minus(o),n+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};d.inverseSine=d.asin=function(){var e,t,n,r,o=this,i=o.constructor;return o.isZero()?new i(o):(t=o.abs().cmp(1),n=i.precision,r=i.rounding,t!==-1?t===0?(e=X(i,n+4,r).times(.5),e.s=o.s,e):new i(NaN):(i.precision=n+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=n,i.rounding=r,o.times(2)))};d.inverseTangent=d.atan=function(){var e,t,n,r,o,i,s,c,u,a=this,l=a.constructor,f=l.precision,p=l.rounding;if(a.isFinite()){if(a.isZero())return new l(a);if(a.abs().eq(1)&&f+4<=pt)return s=X(l,f+4,p).times(.25),s.s=a.s,s}else{if(!a.s)return new l(NaN);if(f+4<=pt)return s=X(l,f+4,p).times(.5),s.s=a.s,s}for(l.precision=c=f+10,l.rounding=1,n=Math.min(28,c/C+2|0),e=n;e;--e)a=a.div(a.times(a).plus(1).sqrt().plus(1));for(B=!1,t=Math.ceil(c/C),r=1,u=a.times(a),s=new l(a),o=a;e!==-1;)if(o=o.times(u),i=s.minus(o.div(r+=2)),o=o.times(u),s=i.plus(o.div(r+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===i.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),B=!0,k(s,l.precision=f,l.rounding=p,!0)};d.isFinite=function(){return!!this.d};d.isInteger=d.isInt=function(){return!!this.d&&z(this.e/C)>this.d.length-2};d.isNaN=function(){return!this.s};d.isNegative=d.isNeg=function(){return this.s<0};d.isPositive=d.isPos=function(){return this.s>0};d.isZero=function(){return!!this.d&&this.d[0]===0};d.lessThan=d.lt=function(e){return this.cmp(e)<0};d.lessThanOrEqualTo=d.lte=function(e){return this.cmp(e)<1};d.logarithm=d.log=function(e){var t,n,r,o,i,s,c,u,a=this,l=a.constructor,f=l.precision,p=l.rounding,m=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(n=a.d,a.s<0||!n||!n[0]||a.eq(1))return new l(n&&!n[0]?-1/0:a.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)i=!0;else{for(o=n[0];o%10===0;)o/=10;i=o!==1}if(B=!1,c=f+m,s=ce(a,c),r=t?Ve(l,c+10):ce(e,c),u=R(s,r,c,1),Te(u.d,o=f,p))do if(c+=10,s=ce(a,c),r=t?Ve(l,c+10):ce(e,c),u=R(s,r,c,1),!i){+H(u.d).slice(o+1,o+15)+1==1e14&&(u=k(u,f+1,0));break}while(Te(u.d,o+=10,p));return B=!0,k(u,f,p)};d.minus=d.sub=function(e){var t,n,r,o,i,s,c,u,a,l,f,p,m=this,h=m.constructor;if(e=new h(e),!m.d||!e.d)return!m.s||!e.s?e=new h(NaN):m.d?e.s=-e.s:e=new h(e.d||m.s!==e.s?m:NaN),e;if(m.s!=e.s)return e.s=-e.s,m.plus(e);if(a=m.d,p=e.d,c=h.precision,u=h.rounding,!a[0]||!p[0]){if(p[0])e.s=-e.s;else if(a[0])e=new h(m);else return new h(u===3?-0:0);return B?k(e,c,u):e}if(n=z(e.e/C),l=z(m.e/C),a=a.slice(),i=l-n,i){for(f=i<0,f?(t=a,i=-i,s=p.length):(t=p,n=l,s=a.length),r=Math.max(Math.ceil(c/C),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=a.length,s=p.length,f=r<s,f&&(s=r),r=0;r<s;r++)if(a[r]!=p[r]){f=a[r]<p[r];break}i=0}for(f&&(t=a,a=p,p=t,e.s=-e.s),s=a.length,r=p.length-s;r>0;--r)a[s++]=0;for(r=p.length;r>i;){if(a[--r]<p[r]){for(o=r;o&&a[--o]===0;)a[o]=Q-1;--a[o],a[r]+=Q}a[r]-=p[r]}for(;a[--s]===0;)a.pop();for(;a[0]===0;a.shift())--n;return a[0]?(e.d=a,e.e=Ue(a,n),B?k(e,c,u):e):new h(u===3?-0:0)};d.modulo=d.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?k(new r(n),r.precision,r.rounding):(B=!1,r.modulo==9?(t=R(n,e.abs(),0,3,1),t.s*=e.s):t=R(n,e,0,r.modulo,1),t=t.times(e),B=!0,n.minus(t))};d.naturalExponential=d.exp=function(){return mt(this)};d.naturalLogarithm=d.ln=function(){return ce(this)};d.negated=d.neg=function(){var e=new this.constructor(this);return e.s=-e.s,k(e)};d.plus=d.add=function(e){var t,n,r,o,i,s,c,u,a,l,f=this,p=f.constructor;if(e=new p(e),!f.d||!e.d)return!f.s||!e.s?e=new p(NaN):f.d||(e=new p(e.d||f.s===e.s?f:NaN)),e;if(f.s!=e.s)return e.s=-e.s,f.minus(e);if(a=f.d,l=e.d,c=p.precision,u=p.rounding,!a[0]||!l[0])return l[0]||(e=new p(f)),B?k(e,c,u):e;if(i=z(f.e/C),r=z(e.e/C),a=a.slice(),o=i-r,o){for(o<0?(n=a,o=-o,s=l.length):(n=l,r=i,s=a.length),i=Math.ceil(c/C),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=a.length,o=l.length,s-o<0&&(o=s,n=l,l=a,a=n),t=0;o;)t=(a[--o]=a[o]+l[o]+t)/Q|0,a[o]%=Q;for(t&&(a.unshift(t),++r),s=a.length;a[--s]==0;)a.pop();return e.d=a,e.e=Ue(a,r),B?k(e,c,u):e};d.precision=d.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ae+e);return n.d?(t=en(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};d.round=function(){var e=this,t=e.constructor;return k(new t(e),e.e+1,t.rounding)};d.sine=d.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+C,r.rounding=1,n=Xn(r,on(r,n)),r.precision=e,r.rounding=t,k(te>2?n.neg():n,e,t,!0)):new r(NaN)};d.squareRoot=d.sqrt=function(){var e,t,n,r,o,i,s=this,c=s.d,u=s.e,a=s.s,l=s.constructor;if(a!==1||!c||!c[0])return new l(!a||a<0&&(!c||c[0])?NaN:c?s:1/0);for(B=!1,a=Math.sqrt(+s),a==0||a==1/0?(t=H(c),(t.length+u)%2==0&&(t+="0"),a=Math.sqrt(t),u=z((u+1)/2)-(u<0||u%2),a==1/0?t="5e"+u:(t=a.toExponential(),t=t.slice(0,t.indexOf("e")+1)+u),r=new l(t)):r=new l(a.toString()),n=(u=l.precision)+3;;)if(i=r,r=i.plus(R(s,i,n+2,1)).times(.5),H(i.d).slice(0,n)===(t=H(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(k(i,u+1,0),i.times(i).eq(s))){r=i;break}n+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(k(r,u+1,1),e=!r.times(r).eq(s));break}return B=!0,k(r,u,l.rounding,e)};d.tangent=d.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=R(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,k(te==2||te==4?n.neg():n,e,t,!0)):new r(NaN)};d.times=d.mul=function(e){var t,n,r,o,i,s,c,u,a,l=this,f=l.constructor,p=l.d,m=(e=new f(e)).d;if(e.s*=l.s,!p||!p[0]||!m||!m[0])return new f(!e.s||p&&!p[0]&&!m||m&&!m[0]&&!p?NaN:!p||!m?e.s/0:e.s*0);for(n=z(l.e/C)+z(e.e/C),u=p.length,a=m.length,u<a&&(i=p,p=m,m=i,s=u,u=a,a=s),i=[],s=u+a,r=s;r--;)i.push(0);for(r=a;--r>=0;){for(t=0,o=u+r;o>r;)c=i[o]+m[r]*p[o-r-1]+t,i[o--]=c%Q|0,t=c/Q|0;i[o]=(i[o]+t)%Q|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=Ue(i,n),B?k(e,f.precision,f.rounding):e};d.toBinary=function(e,t){return ht(this,2,e,t)};d.toDecimalPlaces=d.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(Y(e,0,ue),t===void 0?t=r.rounding:Y(t,0,8),k(n,e+n.e+1,t))};d.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=ee(r,!0):(Y(e,0,ue),t===void 0?t=o.rounding:Y(t,0,8),r=k(new o(r),e+1,t),n=ee(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};d.toFixed=function(e,t){var n,r,o=this,i=o.constructor;return e===void 0?n=ee(o):(Y(e,0,ue),t===void 0?t=i.rounding:Y(t,0,8),r=k(new i(o),e+o.e+1,t),n=ee(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};d.toFraction=function(e){var t,n,r,o,i,s,c,u,a,l,f,p,m=this,h=m.d,g=m.constructor;if(!h)return new g(m);if(a=n=new g(1),r=u=new g(0),t=new g(r),i=t.e=en(h)-m.e-1,s=i%C,t.d[0]=U(10,s<0?C+s:s),e==null)e=i>0?t:a;else{if(c=new g(e),!c.isInt()||c.lt(a))throw Error(ae+c);e=c.gt(t)?i>0?t:a:c}for(B=!1,c=new g(H(h)),l=g.precision,g.precision=i=h.length*C*2;f=R(c,t,0,1,1),o=n.plus(f.times(r)),o.cmp(e)!=1;)n=r,r=o,o=a,a=u.plus(f.times(o)),u=o,o=t,t=c.minus(f.times(o)),c=o;return o=R(e.minus(n),r,0,1,1),u=u.plus(o.times(a)),n=n.plus(o.times(r)),u.s=a.s=m.s,p=R(a,r,i,1).minus(m).abs().cmp(R(u,n,i,1).minus(m).abs())<1?[a,r]:[u,n],g.precision=l,B=!0,p};d.toHexadecimal=d.toHex=function(e,t){return ht(this,16,e,t)};d.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:Y(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(B=!1,n=R(n,e,0,t,1).times(e),B=!0,k(n)):(e.s=n.s,n=e),n};d.toNumber=function(){return+this};d.toOctal=function(e,t){return ht(this,8,e,t)};d.toPower=d.pow=function(e){var t,n,r,o,i,s,c=this,u=c.constructor,a=+(e=new u(e));if(!c.d||!e.d||!c.d[0]||!e.d[0])return new u(U(+c,a));if(c=new u(c),c.eq(1))return c;if(r=u.precision,i=u.rounding,e.eq(1))return k(c,r,i);if(t=z(e.e/C),t>=e.d.length-1&&(n=a<0?-a:a)<=jn)return o=tn(u,c,n,r),e.s<0?new u(1).div(o):k(o,r,i);if(s=c.s,s<0){if(t<e.d.length-1)return new u(NaN);if((e.d[t]&1)==0&&(s=1),c.e==0&&c.d[0]==1&&c.d.length==1)return c.s=s,c}return n=U(+c,a),t=n==0||!isFinite(n)?z(a*(Math.log("0."+H(c.d))/Math.LN10+c.e+1)):new u(n+"").e,t>u.maxE+1||t<u.minE-1?new u(t>0?s/0:0):(B=!1,u.rounding=c.s=1,n=Math.min(12,(t+"").length),o=mt(e.times(ce(c,r+n)),r),o.d&&(o=k(o,r+5,1),Te(o.d,r,i)&&(t=r+10,o=k(mt(e.times(ce(c,t+n)),t),t+5,1),+H(o.d).slice(r+1,r+15)+1==1e14&&(o=k(o,r+1,0)))),o.s=s,B=!0,u.rounding=i,k(o,r,i))};d.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=ee(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(Y(e,1,ue),t===void 0?t=o.rounding:Y(t,0,8),r=k(new o(r),e,t),n=ee(r,e<=r.e||r.e<=o.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};d.toSignificantDigits=d.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(Y(e,1,ue),t===void 0?t=r.rounding:Y(t,0,8)),k(new r(n),e,t)};d.toString=function(){var e=this,t=e.constructor,n=ee(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};d.truncated=d.trunc=function(){return k(new this.constructor(this),this.e+1,1)};d.valueOf=d.toJSON=function(){var e=this,t=e.constructor,n=ee(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function H(e){var t,n,r,o=e.length-1,i="",s=e[0];if(o>0){for(i+=s,t=1;t<o;t++)r=e[t]+"",n=C-r.length,n&&(i+=se(n)),i+=r;s=e[t],r=s+"",n=C-r.length,n&&(i+=se(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function Y(e,t,n){if(e!==~~e||e<t||e>n)throw Error(ae+e)}function Te(e,t,n,r){var o,i,s,c;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=C,o=0):(o=Math.ceil((t+1)/C),t%=C),i=U(10,C-t),c=e[o]%i|0,r==null?t<3?(t==0?c=c/100|0:t==1&&(c=c/10|0),s=n<4&&c==99999||n>3&&c==49999||c==5e4||c==0):s=(n<4&&c+1==i||n>3&&c+1==i/2)&&(e[o+1]/i/100|0)==U(10,t-2)-1||(c==i/2||c==0)&&(e[o+1]/i/100|0)==0:t<4?(t==0?c=c/1e3|0:t==1?c=c/100|0:t==2&&(c=c/10|0),s=(r||n<4)&&c==9999||!r&&n>3&&c==4999):s=((r||n<4)&&c+1==i||!r&&n>3&&c+1==i/2)&&(e[o+1]/i/1e3|0)==U(10,t-3)-1,s}function Ke(e,t,n){for(var r,o=[0],i,s=0,c=e.length;s<c;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=lt.indexOf(e.charAt(s++)),r=0;r<o.length;r++)o[r]>n-1&&(o[r+1]===void 0&&(o[r+1]=0),o[r+1]+=o[r]/n|0,o[r]%=n)}return o.reverse()}function Zn(e,t){var n,r,o;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),o=(1/qe(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=ge(e,1,t.times(o),new e(1));for(var i=n;i--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}var R=function(){function e(r,o,i){var s,c=0,u=r.length;for(r=r.slice();u--;)s=r[u]*o+c,r[u]=s%i|0,c=s/i|0;return c&&r.unshift(c),r}function t(r,o,i,s){var c,u;if(i!=s)u=i>s?1:-1;else for(c=u=0;c<i;c++)if(r[c]!=o[c]){u=r[c]>o[c]?1:-1;break}return u}function n(r,o,i,s){for(var c=0;i--;)r[i]-=c,c=r[i]<o[i]?1:0,r[i]=c*s+r[i]-o[i];for(;!r[0]&&r.length>1;)r.shift()}return function(r,o,i,s,c,u){var a,l,f,p,m,h,g,y,T,A,b,w,x,P,_,S,M,Z,D,v,W=r.constructor,q=r.s==o.s?1:-1,F=r.d,E=o.d;if(!F||!F[0]||!E||!E[0])return new W(!r.s||!o.s||(F?E&&F[0]==E[0]:!E)?NaN:F&&F[0]==0||!E?q*0:q/0);for(u?(m=1,l=r.e-o.e):(u=Q,m=C,l=z(r.e/m)-z(o.e/m)),D=E.length,M=F.length,T=new W(q),A=T.d=[],f=0;E[f]==(F[f]||0);f++);if(E[f]>(F[f]||0)&&l--,i==null?(P=i=W.precision,s=W.rounding):c?P=i+(r.e-o.e)+1:P=i,P<0)A.push(1),h=!0;else{if(P=P/m+2|0,f=0,D==1){for(p=0,E=E[0],P++;(f<M||p)&&P--;f++)_=p*u+(F[f]||0),A[f]=_/E|0,p=_%E|0;h=p||f<M}else{for(p=u/(E[0]+1)|0,p>1&&(E=e(E,p,u),F=e(F,p,u),D=E.length,M=F.length),S=D,b=F.slice(0,D),w=b.length;w<D;)b[w++]=0;v=E.slice(),v.unshift(0),Z=E[0],E[1]>=u/2&&++Z;do p=0,a=t(E,b,D,w),a<0?(x=b[0],D!=w&&(x=x*u+(b[1]||0)),p=x/Z|0,p>1?(p>=u&&(p=u-1),g=e(E,p,u),y=g.length,w=b.length,a=t(g,b,y,w),a==1&&(p--,n(g,D<y?v:E,y,u))):(p==0&&(a=p=1),g=E.slice()),y=g.length,y<w&&g.unshift(0),n(b,g,w,u),a==-1&&(w=b.length,a=t(E,b,D,w),a<1&&(p++,n(b,D<w?v:E,w,u))),w=b.length):a===0&&(p++,b=[0]),A[f++]=p,a&&b[0]?b[w++]=F[S]||0:(b=[F[S]],w=1);while((S++<M||b[0]!==void 0)&&P--);h=b[0]!==void 0}A[0]||A.shift()}if(m==1)T.e=l,Yt=h;else{for(f=1,p=A[0];p>=10;p/=10)f++;T.e=f+l*m-1,k(T,c?i+T.e+1:i,s,h)}return T}}();function k(e,t,n,r){var o,i,s,c,u,a,l,f,p,m=e.constructor;e:if(t!=null){if(f=e.d,!f)return e;for(o=1,c=f[0];c>=10;c/=10)o++;if(i=t-o,i<0)i+=C,s=t,l=f[p=0],u=l/U(10,o-s-1)%10|0;else if(p=Math.ceil((i+1)/C),c=f.length,p>=c)if(r){for(;c++<=p;)f.push(0);l=u=0,o=1,i%=C,s=i-C+1}else break e;else{for(l=c=f[p],o=1;c>=10;c/=10)o++;i%=C,s=i-C+o,u=s<0?0:l/U(10,o-s-1)%10|0}if(r=r||t<0||f[p+1]!==void 0||(s<0?l:l%U(10,o-s-1)),a=n<4?(u||r)&&(n==0||n==(e.s<0?3:2)):u>5||u==5&&(n==4||r||n==6&&(i>0?s>0?l/U(10,o-s):0:f[p-1])%10&1||n==(e.s<0?8:7)),t<1||!f[0])return f.length=0,a?(t-=e.e+1,f[0]=U(10,(C-t%C)%C),e.e=-t||0):f[0]=e.e=0,e;if(i==0?(f.length=p,c=1,p--):(f.length=p+1,c=U(10,C-i),f[p]=s>0?(l/U(10,o-s)%U(10,s)|0)*c:0),a)for(;;)if(p==0){for(i=1,s=f[0];s>=10;s/=10)i++;for(s=f[0]+=c,c=1;s>=10;s/=10)c++;i!=c&&(e.e++,f[0]==Q&&(f[0]=1));break}else{if(f[p]+=c,f[p]!=Q)break;f[p--]=0,c=1}for(i=f.length;f[--i]===0;)f.pop()}return B&&(e.e>m.maxE?(e.d=null,e.e=NaN):e.e<m.minE&&(e.e=0,e.d=[0])),e}function ee(e,t,n){if(!e.isFinite())return rn(e);var r,o=e.e,i=H(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+se(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+se(-o-1)+i,n&&(r=n-s)>0&&(i+=se(r))):o>=s?(i+=se(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+se(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=se(r))),i}function Ue(e,t){var n=e[0];for(t*=C;n>=10;n/=10)t++;return t}function Ve(e,t,n){if(t>zn)throw B=!0,n&&(e.precision=n),Error(Xt);return k(new e(ve),t,1,!0)}function X(e,t,n){if(t>pt)throw Error(Xt);return k(new e(Fe),t,n,!0)}function en(e){var t=e.length-1,n=t*C+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function se(e){for(var t="";e--;)t+="0";return t}function tn(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/C+4);for(B=!1;;){if(n%2&&(i=i.times(t),zt(i.d,s)&&(o=!0)),n=z(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),zt(t.d,s)}return B=!0,i}function jt(e){return e.d[e.d.length-1]&1}function nn(e,t,n){for(var r,o=new e(t[0]),i=0;++i<t.length;)if(r=new e(t[i]),r.s)o[n](r)&&(o=r);else{o=r;break}return o}function mt(e,t){var n,r,o,i,s,c,u,a=0,l=0,f=0,p=e.constructor,m=p.rounding,h=p.precision;if(!e.d||!e.d[0]||e.e>17)return new p(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(B=!1,u=h):u=t,c=new p(.03125);e.e>-2;)e=e.times(c),f+=5;for(r=Math.log(U(2,f))/Math.LN10*2+5|0,u+=r,n=i=s=new p(1),p.precision=u;;){if(i=k(i.times(e),u,1),n=n.times(++l),c=s.plus(R(i,n,u,1)),H(c.d).slice(0,u)===H(s.d).slice(0,u)){for(o=f;o--;)s=k(s.times(s),u,1);if(t==null)if(a<3&&Te(s.d,u-r,m,a))p.precision=u+=10,n=i=c=new p(1),l=0,a++;else return k(s,p.precision=h,m,B=!0);else return p.precision=h,s}s=c}}function ce(e,t){var n,r,o,i,s,c,u,a,l,f,p,m=1,h=10,g=e,y=g.d,T=g.constructor,A=T.rounding,b=T.precision;if(g.s<0||!y||!y[0]||!g.e&&y[0]==1&&y.length==1)return new T(y&&!y[0]?-1/0:g.s!=1?NaN:y?0:g);if(t==null?(B=!1,l=b):l=t,T.precision=l+=h,n=H(y),r=n.charAt(0),Math.abs(i=g.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)g=g.times(e),n=H(g.d),r=n.charAt(0),m++;i=g.e,r>1?(g=new T("0."+n),i++):g=new T(r+"."+n.slice(1))}else return a=Ve(T,l+2,b).times(i+""),g=ce(new T(r+"."+n.slice(1)),l-h).plus(a),T.precision=b,t==null?k(g,b,A,B=!0):g;for(f=g,u=s=g=R(g.minus(1),g.plus(1),l,1),p=k(g.times(g),l,1),o=3;;){if(s=k(s.times(p),l,1),a=u.plus(R(s,new T(o),l,1)),H(a.d).slice(0,l)===H(u.d).slice(0,l))if(u=u.times(2),i!==0&&(u=u.plus(Ve(T,l+2,b).times(i+""))),u=R(u,new T(m),l,1),t==null)if(Te(u.d,l-h,A,c))T.precision=l+=h,a=s=g=R(f.minus(1),f.plus(1),l,1),p=k(g.times(g),l,1),o=c=1;else return k(u,T.precision=b,A,B=!0);else return T.precision=b,u;u=a,o+=2}}function rn(e){return String(e.s*e.s/0)}function dt(e,t){var n,r,o;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(o=t.length;t.charCodeAt(o-1)===48;--o);if(t=t.slice(r,o),t){if(o-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%C,n<0&&(r+=C),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=C;r<o;)e.d.push(+t.slice(r,r+=C));t=t.slice(r),r=C-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),B&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Yn(e,t){var n,r,o,i,s,c,u,a,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),$t.test(t))return dt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Gn.test(t))n=16,t=t.toLowerCase();else if(qn.test(t))n=2;else if(Hn.test(t))n=8;else throw Error(ae+t);for(i=t.search(/p/i),i>0?(u=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,r=e.constructor,s&&(t=t.replace(".",""),c=t.length,i=c-i,o=tn(r,new r(n),i,i*2)),a=Ke(t,n,Q),l=a.length-1,i=l;a[i]===0;--i)a.pop();return i<0?new r(e.s*0):(e.e=Ue(a,l),e.d=a,B=!1,s&&(e=R(e,o,c*4)),u&&(e=e.times(Math.abs(u)<54?U(2,u):Ge.pow(2,u))),B=!0,e)}function Xn(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:ge(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/qe(5,n)),t=ge(e,2,t,t);for(var o,i=new e(5),s=new e(16),c=new e(20);n--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(c))));return t}function ge(e,t,n,r,o){var i,s,c,u,a=1,l=e.precision,f=Math.ceil(l/C);for(B=!1,u=n.times(n),c=new e(r);;){if(s=R(c.times(u),new e(t++*t++),l,1),c=o?r.plus(s):r.minus(s),r=R(s.times(u),new e(t++*t++),l,1),s=c.plus(r),s.d[f]!==void 0){for(i=f;s.d[i]===c.d[i]&&i--;);if(i==-1)break}i=c,c=r,r=s,s=i,a++}return B=!0,s.d.length=f+1,s}function qe(e,t){for(var n=e;--t;)n*=e;return n}function on(e,t){var n,r=t.s<0,o=X(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return te=r?4:1,t;if(n=t.divToInt(o),n.isZero())te=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return te=jt(n)?r?2:3:r?4:1,t;te=jt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function ht(e,t,n,r){var o,i,s,c,u,a,l,f,p,m=e.constructor,h=n!==void 0;if(h?(Y(n,1,ue),r===void 0?r=m.rounding:Y(r,0,8)):(n=m.precision,r=m.rounding),!e.isFinite())l=rn(e);else{for(l=ee(e),s=l.indexOf("."),h?(o=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):o=t,s>=0&&(l=l.replace(".",""),p=new m(1),p.e=l.length-s,p.d=Ke(ee(p),10,o),p.e=p.d.length),f=Ke(l,10,o),i=u=f.length;f[--u]==0;)f.pop();if(!f[0])l=h?"0p+0":"0";else{if(s<0?i--:(e=new m(e),e.d=f,e.e=i,e=R(e,p,n,r,0,o),f=e.d,i=e.e,a=Yt),s=f[n],c=o/2,a=a||f[n+1]!==void 0,a=r<4?(s!==void 0||a)&&(r===0||r===(e.s<0?3:2)):s>c||s===c&&(r===4||a||r===6&&f[n-1]&1||r===(e.s<0?8:7)),f.length=n,a)for(;++f[--n]>o-1;)f[n]=0,n||(++i,f.unshift(1));for(u=f.length;!f[u-1];--u);for(s=0,l="";s<u;s++)l+=lt.charAt(f[s]);if(h){if(u>1)if(t==16||t==8){for(s=t==16?4:3,--u;u%s;u++)l+="0";for(f=Ke(l,o,t),u=f.length;!f[u-1];--u);for(s=1,l="1.";s<u;s++)l+=lt.charAt(f[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)l="0"+l;l="0."+l}else if(++i>u)for(i-=u;i--;)l+="0";else i<u&&(l=l.slice(0,i)+"."+l.slice(i))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function zt(e,t){if(e.length>t)return e.length=t,!0}function Qn(e){return new this(e).abs()}function Jn(e){return new this(e).acos()}function $n(e){return new this(e).acosh()}function er(e,t){return new this(e).plus(t)}function tr(e){return new this(e).asin()}function nr(e){return new this(e).asinh()}function rr(e){return new this(e).atan()}function or(e){return new this(e).atanh()}function ir(e,t){e=new this(e),t=new this(t);var n,r=this.precision,o=this.rounding,i=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=X(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?X(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=X(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(R(e,t,i,1)),t=X(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(R(e,t,i,1)),n}function sr(e){return new this(e).cbrt()}function cr(e){return k(e=new this(e),e.e+1,2)}function ar(e,t,n){return new this(e).clamp(t,n)}function ur(e){if(!e||typeof e!="object")throw Error(We+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,ue,"rounding",0,8,"toExpNeg",-he,0,"toExpPos",0,he,"maxE",0,he,"minE",-he,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=ft[n]),(r=e[n])!==void 0)if(z(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(ae+n+": "+r);if(n="crypto",o&&(this[n]=ft[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Qt);else this[n]=!1;else throw Error(ae+n+": "+r);return this}function lr(e){return new this(e).cos()}function fr(e){return new this(e).cosh()}function sn(e){var t,n,r;function o(i){var s,c,u,a=this;if(!(a instanceof o))return new o(i);if(a.constructor=o,Zt(i)){a.s=i.s,B?!i.d||i.e>o.maxE?(a.e=NaN,a.d=null):i.e<o.minE?(a.e=0,a.d=[0]):(a.e=i.e,a.d=i.d.slice()):(a.e=i.e,a.d=i.d?i.d.slice():i.d);return}if(u=typeof i,u==="number"){if(i===0){a.s=1/i<0?-1:1,a.e=0,a.d=[0];return}if(i<0?(i=-i,a.s=-1):a.s=1,i===~~i&&i<1e7){for(s=0,c=i;c>=10;c/=10)s++;B?s>o.maxE?(a.e=NaN,a.d=null):s<o.minE?(a.e=0,a.d=[0]):(a.e=s,a.d=[i]):(a.e=s,a.d=[i]);return}else if(i*0!==0){i||(a.s=NaN),a.e=NaN,a.d=null;return}return dt(a,i.toString())}else if(u!=="string")throw Error(ae+i);return(c=i.charCodeAt(0))===45?(i=i.slice(1),a.s=-1):(c===43&&(i=i.slice(1)),a.s=1),$t.test(i)?dt(a,i):Yn(a,i)}if(o.prototype=d,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=ur,o.clone=sn,o.isDecimal=Zt,o.abs=Qn,o.acos=Jn,o.acosh=$n,o.add=er,o.asin=tr,o.asinh=nr,o.atan=rr,o.atanh=or,o.atan2=ir,o.cbrt=sr,o.ceil=cr,o.clamp=ar,o.cos=lr,o.cosh=fr,o.div=pr,o.exp=mr,o.floor=dr,o.hypot=hr,o.ln=gr,o.log=br,o.log10=wr,o.log2=yr,o.max=xr,o.min=Tr,o.mod=Pr,o.mul=Ar,o.pow=kr,o.random=Cr,o.round=Br,o.sign=Lr,o.sin=Sr,o.sinh=Ir,o.sqrt=Nr,o.sub=_r,o.sum=Er,o.tan=Rr,o.tanh=Mr,o.trunc=Dr,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return o.config(e),o}function pr(e,t){return new this(e).div(t)}function mr(e){return new this(e).exp()}function dr(e){return k(e=new this(e),e.e+1,3)}function hr(){var e,t,n=new this(0);for(B=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return B=!0,new this(1/0);n=t}return B=!0,n.sqrt()}function Zt(e){return e instanceof Ge||e&&e.toStringTag===Jt||!1}function gr(e){return new this(e).ln()}function br(e,t){return new this(e).log(t)}function yr(e){return new this(e).log(2)}function wr(e){return new this(e).log(10)}function xr(){return nn(this,arguments,"lt")}function Tr(){return nn(this,arguments,"gt")}function Pr(e,t){return new this(e).mod(t)}function Ar(e,t){return new this(e).mul(t)}function kr(e,t){return new this(e).pow(t)}function Cr(e){var t,n,r,o,i=0,s=new this(1),c=[];if(e===void 0?e=this.precision:Y(e,1,ue),r=Math.ceil(e/C),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));i<r;)o=t[i],o>=429e7?t[i]=crypto.getRandomValues(new Uint32Array(1))[0]:c[i++]=o%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);i<r;)o=t[i]+(t[i+1]<<8)+(t[i+2]<<16)+((t[i+3]&127)<<24),o>=214e7?crypto.randomBytes(4).copy(t,i):(c.push(o%1e7),i+=4);i=r/4}else throw Error(Qt);else for(;i<r;)c[i++]=Math.random()*1e7|0;for(r=c[--i],e%=C,r&&e&&(o=U(10,C-e),c[i]=(r/o|0)*o);c[i]===0;i--)c.pop();if(i<0)n=0,c=[0];else{for(n=-1;c[0]===0;n-=C)c.shift();for(r=1,o=c[0];o>=10;o/=10)r++;r<C&&(n-=C-r)}return s.e=n,s.d=c,s}function Br(e){return k(e=new this(e),e.e+1,this.rounding)}function Lr(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Sr(e){return new this(e).sin()}function Ir(e){return new this(e).sinh()}function Nr(e){return new this(e).sqrt()}function _r(e,t){return new this(e).sub(t)}function Er(){var e=0,t=arguments,n=new this(t[e]);for(B=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return B=!0,k(n,this.precision,this.rounding)}function Rr(e){return new this(e).tan()}function Mr(e){return new this(e).tanh()}function Dr(e){return k(e=new this(e),e.e+1,1)}d[Symbol.for("nodejs.util.inspect.custom")]=d.toString;d[Symbol.toStringTag]="Decimal";var Ge=d.constructor=sn(ft);ve=new Ge(ve);Fe=new Ge(Fe);import qr from"big.js";import li from"bn.js";import Or from"toformat";var Kr=Or,Pe=Kr;import je from"big.js";import Fr from"bn.js";import Vr from"decimal.js-light";import Ae from"bn.js";var cn=9007199254740991;function J(e){let t=j("Raydium_parseBigNumberish");if(e instanceof Ae)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new Ae(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=cn||e<=-cn)&&t.logWithError(`BigNumberish number overflow: ${e}`),new Ae(String(e))):typeof e=="bigint"?new Ae(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new Ae(0))}var He=j("module/fraction"),gt=Pe(je),ke=Pe(Vr),Wr={[0]:ke.ROUND_DOWN,[1]:ke.ROUND_HALF_UP,[2]:ke.ROUND_UP},Ur={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},O=class{constructor(t,n=new Fr(1)){this.numerator=J(t),this.denominator=J(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new O(this.denominator,this.numerator)}add(t){let n=t instanceof O?t:new O(J(t));return this.denominator.eq(n.denominator)?new O(this.numerator.add(n.numerator),this.denominator):new O(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof O?t:new O(J(t));return this.denominator.eq(n.denominator)?new O(this.numerator.sub(n.numerator),this.denominator):new O(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof O?t:new O(J(t));return new O(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof O?t:new O(J(t));return new O(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},r=1){Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<=0&&He.logWithError(`${t} is not positive.`),ke.set({precision:t+1,rounding:Wr[r]});let o=new ke(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},r=1){return Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<0&&He.logWithError(`${t} is negative.`),gt.DP=t,gt.RM=Ur[r]||1,new gt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var wi=j("Raydium_amount"),xi=Pe(qr);import{PublicKey as Hr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as an}from"@solana/spl-token";var un={chainId:101,address:Hr.default.toBase58(),programId:an.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ne={chainId:101,address:"So11111111111111111111111111111111111111112",programId:an.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 yt}from"@solana/web3.js";import{PublicKey as K,SystemProgram as ln,SYSVAR_RENT_PUBKEY as jr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as zr}from"@solana/spl-token";function bt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var Si=[bt({pubkey:zr,isWritable:!1}),bt({pubkey:ln.programId,isWritable:!1}),bt({pubkey:jr,isWritable:!1})];function fn({publicKey:e,transformSol:t}){let n=pn(e.toString());if(n instanceof K)return t&&n.equals(Ce)?ie:n;if(t&&n.toString()===Ce.toBase58())return ie;if(typeof n=="string"){if(n===K.default.toBase58())return K.default;try{return new K(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function pn(e){try{return new K(e)}catch{return e}}var Ii=new K("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ni=new K("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),_i=new K("SysvarRent111111111111111111111111111111111"),Ei=new K("SysvarC1ock11111111111111111111111111111111"),Ri=new K("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Mi=new K("Sysvar1nstructions1111111111111111111111111"),Di=ln.programId,Oi=new K("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Ki=new K("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),vi=new K("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Fi=new K("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Vi=new K("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Wi=new K("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ui=new K("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),qi=new K("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Gi=new K("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Hi=new K("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),ji=new K("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),ie=new K("So11111111111111111111111111111111111111112"),Ce=K.default;var wt=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Ce.toBase58()||t instanceof yt&&Ce.equals(t)){this.decimals=ne.decimals,this.symbol=ne.symbol,this.name=ne.name,this.mint=new yt(ne.address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||t.toString().substring(0,6),this.name=o||t.toString().substring(0,6),this.mint=i?yt.default:fn({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},be=wt;be.WSOL=new wt(oe(V({},ne),{mint:ne.address}));var xt=class{constructor({decimals:t,symbol:n="UNKNOWN",name:r="UNKNOWN"}){this.decimals=t,this.symbol=n,this.name=r}equals(t){return this===t}},ze=xt;ze.SOL=new xt(un);import Zr from"bn.js";var os=new O(new Zr(100));var ls=j("Raydium_price");import{PublicKey as Ls}from"@solana/web3.js";import Is from"bn.js";var Yr=new re(0),Zs=new re(1),Ys=new re(2),Xs=new re(3),Qs=new re(5),Gr=new re(10),Js=new re(100),$s=new re(1e3),ec=new re(1e4);function ut(e,t=1,n=[]){let r=[...e];if(t<=0)return n;for(;r.length;)n.push(r.splice(0,t));return n}import{PublicKey as no}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ro}from"@solana/spl-token";import{ComputeBudgetProgram as gn,Keypair as yn,PublicKey as Xr,Transaction as wn,TransactionMessage as Qr,VersionedTransaction as xn}from"@solana/web3.js";var G={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"};import{TOKEN_PROGRAM_ID as Jr}from"@solana/spl-token";var bn=j("Raydium_txUtil"),Tn=1644;function Ze(e){let t=[],n=[];return e.microLamports&&(t.push(gn.setComputeUnitPrice({microLamports:e.microLamports})),n.push(G.SetComputeUnitPrice)),e.units&&(t.push(gn.setComputeUnitLimit({units:e.units})),n.push(G.SetComputeUnitLimit)),{instructions:t,instructionTypes:n}}async function ye(e,t){var r,o;let n=t!=null?t:"confirmed";return(o=await((r=e.getLatestBlockhash)==null?void 0:r.call(e,{commitment:n})))==null?void 0:o.blockhash}async function Ye(e,t){return e.getSignatureStatuses([t]),new Promise((n,r)=>{let o=setTimeout(r,6e4);e.onSignature(t,i=>{if(clearTimeout(o),!i.err){n("");return}r(i.err.toString())},"confirmed")})}function $r(e,t){e.length<1&&bn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&bn.logWithError(`no signers provided:, ${t.toString()}`);let n=new wn;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<Tn}catch{return!1}}function Pn(e,t){let[n,r]=Xr.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Be({instructions:e,payer:t,signers:n}){return $r(e,[t,...n])}function Le({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=yn.generate().publicKey.toString()}){let i=new Qr({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new xn(i).serialize()).toString("base64").length<Tn}catch{return!1}}var eo=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e),to=e=>{let t=e.serialize({requireAllSignatures:!1,verifySignatures:!1});e instanceof xn&&(t=eo(t));try{return t instanceof Buffer?t.toString("base64"):Buffer.from(t).toString("base64")}catch{return t.toString("base64")}};function de(e){let t=[];return e.forEach(n=>{n instanceof wn&&(n.recentBlockhash||(n.recentBlockhash=Jr.toBase58()),n.feePayer||(n.feePayer=yn.generate().publicKey)),t.push(to(n))}),console.log("simulate tx string:",t),t}function Xe(e,t,n){return Pn([e.toBuffer(),(n!=null?n:ro).toBuffer(),t.toBuffer()],new no("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as L}from"@solana/web3.js";var Tc=new L("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Pc=new L("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Ac=new L("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),kc=new L("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Cc=new L("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Bc=new L("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Lc=new L("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Sc=new L("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Ic=new L("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Nc=new L("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),_c=new L("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Ec=new L("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Rc=new L("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Mc=new L("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Dc=new L("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Oc=new L("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Kc=new L("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),vc=new L("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Fc=new L("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),Vc=new L("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Wc=new L("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Uc=new L("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),oo=new L("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),io=new L("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),so=new L("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),qc=new L("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),co=new L("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Gc=new L("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),ao=new L("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var Hc={SERUM_MARKET:L.default,OPENBOOK_MARKET:new L("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:L.default,FarmV3:new L("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new L("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new L("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new L("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new L("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new L("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new L("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new L("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new L("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:oo,CREATE_CPMM_POOL_AUTH:io,CREATE_CPMM_POOL_FEE_ACC:so,FEE_DESTINATION_ID:new L("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:co,LCOK_CPMM_AUTH:ao};import Zc from"bn.js";import{PublicKey as An,AddressLookupTableAccount as Qe}from"@solana/web3.js";async function Tt({connection:e,address:t}){let n=await Ht(e,[...new Set(t.map(o=>o.toString()))].map(o=>new An(o))),r={};for(let o=0;o<t.length;o++){let i=n[o],s=t[o];if(!i)continue;let c=new Qe({key:s,state:Qe.deserialize(i.data)});r[s.toString()]=c,Je[s.toString()]=c}return r}var Je={"2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17":new Qe({key:new An("2immgwYNHBbyVQKVGCEkgWpi53bLwWNRMB5G2nbgYV17"),state:Qe.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 Se,sendAndConfirmTransaction as Pt,Transaction as Ie,TransactionMessage as Ne,VersionedTransaction as _e}from"@solana/web3.js";import uo from"axios";var $e=class{constructor(t){this.instructions=[];this.endInstructions=[];this.lookupTableAddress=[];this.signers=[];this.instructionTypes=[];this.endInstructionTypes=[];this.connection=t.connection,this.feePayer=t.feePayer,this.signAllTransactions=t.signAllTransactions,this.owner=t.owner,this.cluster=t.cluster,this.blockhashCommitment=t.blockhashCommitment,this.api=t.api}get AllTxData(){return{instructions:this.instructions,endInstructions:this.endInstructions,signers:this.signers,instructionTypes:this.instructionTypes,endInstructionTypes:this.endInstructionTypes,lookupTableAddress:this.lookupTableAddress}}get allInstructions(){return[...this.instructions,...this.endInstructions]}async getComputeBudgetConfig(){var r;let t=(await uo.get(`https://solanacompass.com/api/fees?cacheFreshTime=${3e5}`)).data,{avg:n}=(r=t==null?void 0:t[15])!=null?r:{};if(!!n)return{units:6e5,microLamports:Math.min(Math.ceil(n*1e6/6e5),25e3)}}addCustomComputeBudget(t){if(t){let{instructions:n,instructionTypes:r}=Ze(t);return this.instructions.unshift(...n),this.instructionTypes.unshift(...r),!0}return!1}async calComputeBudget({config:t,defaultIns:n}){try{let r=t||await this.getComputeBudgetConfig();if(this.addCustomComputeBudget(r))return;n&&this.instructions.unshift(...n)}catch{n&&this.instructions.unshift(...n)}}addInstruction({instructions:t=[],endInstructions:n=[],signers:r=[],instructionTypes:o=[],endInstructionTypes:i=[],lookupTableAddress:s=[]}){return this.instructions.push(...t),this.endInstructions.push(...n),this.signers.push(...r),this.instructionTypes.push(...o),this.endInstructionTypes.push(...i),this.lookupTableAddress.push(...s.filter(c=>c!==Se.default.toString())),this}async versionBuild({txVersion:t,extInfo:n}){return t===0?await this.buildV0(V({},n||{})):this.build(n)}build(t){var r;let n=new Ie;return this.allInstructions.length&&n.add(...this.allInstructions),n.feePayer=this.feePayer,((r=this.owner)==null?void 0:r.signer)&&!this.signers.some(o=>o.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer),{builder:this,transaction:n,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async o=>{var a;let{recentBlockHash:i,skipPreflight:s=!0,sendAndConfirm:c}=o||{},u=i!=null?i:await ye(this.connection,this.blockhashCommitment);if(n.recentBlockhash=u,this.signers.length&&n.sign(...this.signers),de([n]),(a=this.owner)!=null&&a.isKeyPair)return{txId:c?await Pt(this.connection,n,this.signers.find(f=>f.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:s}):await this.connection.sendRawTransaction(n.serialize(),{skipPreflight:s}),signedTx:n};if(this.signAllTransactions){let l=await this.signAllTransactions([n]);return{txId:await this.connection.sendRawTransaction(l[0].serialize(),{skipPreflight:s}),signedTx:l[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:t||{}}}buildMultiTx(t){var a;let{extraPreBuildData:n=[],extInfo:r}=t,{transaction:o}=this.build(r),i=n.filter(l=>l.transaction.instructions.length>0),s=[o,...i.map(l=>l.transaction)],c=[this.signers,...i.map(l=>l.signers)],u=[...this.instructionTypes,...i.map(l=>l.instructionTypes).flat()];return(a=this.owner)!=null&&a.signer&&c.forEach(l=>{l.some(f=>f.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),{builder:this,transactions:s,signers:c,instructionTypes:u,execute:async l=>{var T;let{sequentially:f,onTxUpdate:p,skipTxCount:m=0,recentBlockHash:h,skipPreflight:g=!0}=l||{},y=h!=null?h:await ye(this.connection,this.blockhashCommitment);if((T=this.owner)!=null&&T.isKeyPair){if(f){let A=[],b=0;for(let w of s){if(++b,b<=m)continue;let x=await Pt(this.connection,w,this.signers.find(P=>P.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:g});A.push(x)}return{txIds:A,signedTxs:s}}return{txIds:await await Promise.all(s.map(async A=>(A.recentBlockhash=y,await this.connection.sendRawTransaction(A.serialize(),{skipPreflight:g})))),signedTxs:s}}if(this.signAllTransactions){let A=s.map((w,x)=>(w.recentBlockhash=y,c[x].length&&w.sign(...c[x]),w));de(A);let b=await this.signAllTransactions(A);if(f){let w=0,x=[],P=async()=>{if(!b[w])return;let _=await this.connection.sendRawTransaction(b[w].serialize(),{skipPreflight:g});x.push({txId:_,status:"sent",signedTx:b[w]}),p==null||p([...x]),w++,this.connection.onSignature(_,S=>{let M=x.findIndex(Z=>Z.txId===_);M>-1&&(x[M].status=S.err?"error":"success"),p==null||p([...x]),S.err||P()},"processed"),this.connection.getSignatureStatus(_)};return await P(),{txIds:x.map(_=>_.txId),signedTxs:b}}else{let w=[];for(let x=0;x<b.length;x+=1){let P=await this.connection.sendRawTransaction(b[x].serialize(),{skipPreflight:g});w.push(P)}return{txIds:w,signedTxs:b}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async versionMultiBuild({extraPreBuildData:t,txVersion:n,extInfo:r}){return n===0?await this.buildV0MultiTx({extraPreBuildData:t,buildProps:r||{}}):this.buildMultiTx({extraPreBuildData:t,extInfo:r})}async buildV0(t){var g;let h=t||{},{lookupTableCache:n={},lookupTableAddress:r=[],forerunCreate:o,recentBlockhash:i}=h,s=me(h,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),c=V(V({},this.cluster==="devnet"?{}:Je),n),u=Array.from(new Set([...r,...this.lookupTableAddress])),a=[];for(let y of u)c[y]===void 0&&a.push(new Se(y));let l=await Tt({connection:this.connection,address:a});for(let[y,T]of Object.entries(l))c[y]=T;let f=o?Se.default.toBase58():i!=null?i:await ye(this.connection,this.blockhashCommitment),p=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...this.allInstructions]}).compileToV0Message(Object.values(c));((g=this.owner)==null?void 0:g.signer)&&!this.signers.some(y=>y.publicKey.equals(this.owner.publicKey))&&this.signers.push(this.owner.signer);let m=new _e(p);return m.sign(this.signers),{builder:this,transaction:m,signers:this.signers,instructionTypes:[...this.instructionTypes,...this.endInstructionTypes],execute:async y=>{var b;let{skipPreflight:T=!0,sendAndConfirm:A}=y||{};if(de([m]),(b=this.owner)!=null&&b.isKeyPair){let w=await this.connection.sendTransaction(m,{skipPreflight:T});return A&&await Ye(this.connection,w),{txId:w,signedTx:m}}if(this.signAllTransactions){let w=await this.signAllTransactions([m]);return{txId:await this.connection.sendTransaction(w[0],{skipPreflight:T}),signedTx:w[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}async buildV0MultiTx(t){var a;let{extraPreBuildData:n=[],buildProps:r}=t,{transaction:o}=await this.buildV0(r),i=n.filter(l=>l.builder.instructions.length>0),s=[o,...i.map(l=>l.transaction)],c=[this.signers,...i.map(l=>l.signers)],u=[...this.instructionTypes,...i.map(l=>l.instructionTypes).flat()];return(a=this.owner)!=null&&a.signer&&c.forEach(l=>{l.some(f=>f.publicKey.equals(this.owner.publicKey))||this.signers.push(this.owner.signer)}),s.forEach(async(l,f)=>{l.sign(c[f])}),{builder:this,transactions:s,signers:c,instructionTypes:u,buildProps:r,execute:async l=>{var g;let{sequentially:f,onTxUpdate:p,recentBlockHash:m,skipPreflight:h=!0}=l||{};if(m&&s.forEach(y=>y.message.recentBlockhash=m),de(s),(g=this.owner)!=null&&g.isKeyPair){if(f){let y=[];for(let T of s){let A=await this.connection.sendTransaction(T,{skipPreflight:h});await Ye(this.connection,A),y.push(A)}return{txIds:y,signedTxs:s}}return{txIds:await Promise.all(s.map(async y=>await this.connection.sendTransaction(y,{skipPreflight:h}))),signedTxs:s}}if(this.signAllTransactions){let y=await this.signAllTransactions(s);if(f){let T=0,A=[],b=async()=>{if(!y[T])return;let w=await this.connection.sendTransaction(y[T],{skipPreflight:h});A.push({txId:w,status:"sent",signedTx:y[T]}),p==null||p([...A]),T++,this.connection.onSignature(w,x=>{let P=A.findIndex(_=>_.txId===w);P>-1&&(A[P].status=x.err?"error":"success"),p==null||p([...A]),x.err||b()},"processed"),this.connection.getSignatureStatus(w)};return b(),{txIds:[],signedTxs:y}}else{let T=[];for(let A=0;A<y.length;A+=1){let b=await this.connection.sendTransaction(y[A],{skipPreflight:h});T.push(b)}return{txIds:T,signedTxs:y}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuild(t){var p;let f=t||{},{splitIns:n=[],computeBudgetConfig:r}=f,o=me(f,["splitIns","computeBudgetConfig"]),i=r?Ze(r):{instructions:[],instructionTypes:[]},s=this.signers.reduce((m,h)=>oe(V({},m),{[h.publicKey.toBase58()]:h}),{}),c=[],u=[],a=[],l=0;if(this.allInstructions.forEach(m=>{let h=[...a,m],g=r?[...i.instructions,...h]:h,T=[...new Set(h.map(A=>A.keys.filter(b=>b.isSigner).map(b=>b.pubkey.toString())).flat()).values()].map(A=>new Se(A));if(m!==n[l]&&a.length<12&&(Be({instructions:g,payer:this.feePayer,signers:T})||Be({instructions:h,payer:this.feePayer,signers:T})))a.push(m);else{if(a.length===0)throw Error("item ins too big");l+=m===n[l]?1:0,Be({instructions:r?[...i.instructions,...a]:[...a],payer:this.feePayer,signers:T})?c.push(new Ie().add(...i.instructions,...a)):c.push(new Ie().add(...a)),u.push(Array.from(new Set(a.map(A=>A.keys.filter(b=>b.isSigner).map(b=>b.pubkey.toString())).flat())).map(A=>s[A]).filter(A=>A!==void 0)),a=[m]}}),a.length>0){let h=[...new Set(a.map(g=>g.keys.filter(y=>y.isSigner).map(y=>y.pubkey.toString())).flat()).values()].map(g=>s[g]).filter(g=>g!==void 0);Be({instructions:r?[...i.instructions,...a]:[...a],payer:this.feePayer,signers:h.map(g=>g.publicKey)})?c.push(new Ie().add(...i.instructions,...a)):c.push(new Ie().add(...a)),u.push(h)}return c.forEach(m=>m.feePayer=this.feePayer),(p=this.owner)!=null&&p.signer&&u.forEach(m=>{m.some(h=>h.publicKey.equals(this.owner.publicKey))||m.push(this.owner.signer)}),{builder:this,transactions:c,signers:u,instructionTypes:this.instructionTypes,execute:async m=>{var w;let{sequentially:h,onTxUpdate:g,skipTxCount:y=0,recentBlockHash:T,skipPreflight:A=!0}=m||{},b=T!=null?T:await ye(this.connection,this.blockhashCommitment);if(c.forEach(async(x,P)=>{x.recentBlockhash=b,u[P].length&&x.sign(...u[P])}),de(c),(w=this.owner)!=null&&w.isKeyPair){if(h){let x=0,P=[];for(let _ of c){if(++x,x<=y){P.push("tx skipped");continue}let S=await Pt(this.connection,_,this.signers.find(M=>M.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:A});P.push(S)}return{txIds:P,signedTxs:c}}return{txIds:await Promise.all(c.map(async x=>await this.connection.sendRawTransaction(x.serialize(),{skipPreflight:A}))),signedTxs:c}}if(this.signAllTransactions){let x=await this.signAllTransactions(c.slice(y,c.length)),P=[...c.slice(0,y),...x];if(h){let _=0,S=[],M=async()=>{if(!P[_])return;_<y&&(S.push({txId:"",status:"success",signedTx:P[_]}),g==null||g([...S]),_++,M());let Z=await this.connection.sendRawTransaction(P[_].serialize(),{skipPreflight:A});S.push({txId:Z,status:"sent",signedTx:P[_]}),g==null||g([...S]),_++,this.connection.onSignature(Z,D=>{let v=S.findIndex(W=>W.txId===Z);v>-1&&(S[v].status=D.err?"error":"success"),g==null||g([...S]),D.err||M()},"processed"),this.connection.getSignatureStatus(Z)};return await M(),{txIds:S.map(Z=>Z.txId),signedTxs:P}}else{let _=[];for(let S=0;S<P.length;S+=1){let M=await this.connection.sendRawTransaction(P[S].serialize(),{skipPreflight:A});_.push(M)}return{txIds:_,signedTxs:P}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:o||{}}}async sizeCheckBuildV0(t){var b;let A=t||{},{computeBudgetConfig:n,splitIns:r=[],lookupTableCache:o={},lookupTableAddress:i=[]}=A,s=me(A,["computeBudgetConfig","splitIns","lookupTableCache","lookupTableAddress"]),c=V(V({},this.cluster==="devnet"?{}:Je),o),u=Array.from(new Set([...this.lookupTableAddress,...i])),a=[];for(let w of u)c[w]===void 0&&a.push(new Se(w));let l=await Tt({connection:this.connection,address:a});for(let[w,x]of Object.entries(l))c[w]=x;let f=n?Ze(n):{instructions:[],instructionTypes:[]},p=await ye(this.connection,this.blockhashCommitment),m=this.signers.reduce((w,x)=>oe(V({},w),{[x.publicKey.toBase58()]:x}),{}),h=[],g=[],y=[],T=0;if(this.allInstructions.forEach(w=>{let x=[...y,w],P=n?[...f.instructions,...x]:x;if(w!==r[T]&&y.length<12&&(Le({instructions:P,payer:this.feePayer,lookupTableAddressAccount:c})||Le({instructions:x,payer:this.feePayer,lookupTableAddressAccount:c})))y.push(w);else{if(y.length===0)throw Error("item ins too big");T+=w===r[T]?1:0;let _={};for(let S of[...new Set(u)])c[S]!==void 0&&(_[S]=c[S]);if(n&&Le({instructions:[...f.instructions,...y],payer:this.feePayer,lookupTableAddressAccount:c,recentBlockhash:p})){let S=new Ne({payerKey:this.feePayer,recentBlockhash:p,instructions:[...f.instructions,...y]}).compileToV0Message(Object.values(c));h.push(new _e(S))}else{let S=new Ne({payerKey:this.feePayer,recentBlockhash:p,instructions:[...y]}).compileToV0Message(Object.values(c));h.push(new _e(S))}g.push(Array.from(new Set(y.map(S=>S.keys.filter(M=>M.isSigner).map(M=>M.pubkey.toString())).flat())).map(S=>m[S]).filter(S=>S!==void 0)),y=[w]}}),y.length>0){let x=[...new Set(y.map(P=>P.keys.filter(_=>_.isSigner).map(_=>_.pubkey.toString())).flat()).values()].map(P=>m[P]).filter(P=>P!==void 0);if(n&&Le({instructions:[...f.instructions,...y],payer:this.feePayer,lookupTableAddressAccount:c,recentBlockhash:p})){let P=new Ne({payerKey:this.feePayer,recentBlockhash:p,instructions:[...f.instructions,...y]}).compileToV0Message(Object.values(c));h.push(new _e(P))}else{let P=new Ne({payerKey:this.feePayer,recentBlockhash:p,instructions:[...y]}).compileToV0Message(Object.values(c));h.push(new _e(P))}g.push(x)}return(b=this.owner)!=null&&b.signer&&g.forEach(w=>{w.some(x=>x.publicKey.equals(this.owner.publicKey))||w.push(this.owner.signer)}),{builder:this,transactions:h,buildProps:t,signers:g,instructionTypes:this.instructionTypes,execute:async w=>{var Z;let{sequentially:x,onTxUpdate:P,skipTxCount:_=0,recentBlockHash:S,skipPreflight:M=!0}=w||{};if(h.map(async(D,v)=>{g[v].length&&D.sign(g[v]),S&&(D.message.recentBlockhash=S)}),de(h),(Z=this.owner)!=null&&Z.isKeyPair){if(x){let D=0,v=[];for(let W of h){if(++D,D<=_){console.log("skip tx: ",D),v.push("tx skipped");continue}let q=await this.connection.sendTransaction(W,{skipPreflight:M});await Ye(this.connection,q),v.push(q)}return{txIds:v,signedTxs:h}}return{txIds:await Promise.all(h.map(async D=>await this.connection.sendTransaction(D,{skipPreflight:M}))),signedTxs:h}}if(this.signAllTransactions){let D=await this.signAllTransactions(h.slice(_,h.length)),v=[...h.slice(0,_),...D];if(x){let W=0,q=[],F=async()=>{if(!v[W])return;if(W<_){q.push({txId:"",status:"success",signedTx:v[W]}),P==null||P([...q]),W++,F();return}let E=await this.connection.sendTransaction(v[W],{skipPreflight:M});q.push({txId:E,status:"sent",signedTx:v[W]}),P==null||P([...q]),W++,this.connection.onSignature(E,vt=>{let Ft=q.findIndex(On=>On.txId===E);Ft>-1&&(q[Ft].status=vt.err?"error":"success"),P==null||P([...q]),vt.err||F()},"processed"),this.connection.getSignatureStatus(E)};return F(),{txIds:[],signedTxs:v}}else{let W=[];for(let q=0;q<v.length;q+=1){let F=await this.connection.sendTransaction(v[q],{skipPreflight:M});W.push(F)}return{txIds:W,signedTxs:v}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}};import{AccountLayout as xe,createAssociatedTokenAccountInstruction as Ot,TOKEN_PROGRAM_ID as pe,TOKEN_2022_PROGRAM_ID as _o}from"@solana/spl-token";var At=(...e)=>e.map(t=>{try{return typeof t=="object"?JSON.stringify(t):t}catch{return t}}).join(", "),Ee=class{constructor({scope:t,moduleName:n}){this.disabled=!1;this.scope=t,this.logger=j(n)}createTxBuilder(t){return this.scope.checkOwner(),new $e({connection:this.scope.connection,feePayer:t||this.scope.ownerPubKey,cluster:this.scope.cluster,owner:this.scope.owner,blockhashCommitment:this.scope.blockhashCommitment,api:this.scope.api,signAllTransactions:this.scope.signAllTransactions})}logDebug(...t){this.logger.debug(At(t))}logInfo(...t){this.logger.info(At(t))}logAndCreateError(...t){let n=At(t);throw new Error(n)}checkDisabled(){(this.disabled||!this.scope)&&this.logAndCreateError("module not working")}};import{PublicKey as ko,SystemProgram as Co}from"@solana/web3.js";import Bo from"bn.js";import{createCloseAccountInstruction as Lo,createInitializeAccountInstruction as So,createTransferInstruction as Io,TOKEN_PROGRAM_ID as we}from"@solana/spl-token";import{Keypair as xo,PublicKey as Rn}from"@solana/web3.js";import To from"bn.js";import{TOKEN_PROGRAM_ID as Po}from"@solana/spl-token";function lo(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function kt(e,...t){if(!lo(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ct(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function kn(e,t){kt(e);let n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}var tt=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),$=(e,t)=>e<<32-t|e>>>t;var Oa=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function fo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Bt(e){return typeof e=="string"&&(e=fo(e)),kt(e),e}var et=class{clone(){return this._cloneInto()}},Ka={}.toString;function Cn(e){let t=r=>e().update(Bt(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function po(e,t,n,r){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,n,r);let o=BigInt(32),i=BigInt(4294967295),s=Number(n>>o&i),c=Number(n&i),u=r?4:0,a=r?0:4;e.setUint32(t+u,s,r),e.setUint32(t+a,c,r)}var Bn=(e,t,n)=>e&t^~e&n,Ln=(e,t,n)=>e&t^e&n^t&n,nt=class extends et{constructor(t,n,r,o){super(),this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=tt(this.buffer)}update(t){Ct(this);let{view:n,buffer:r,blockLen:o}=this;t=Bt(t);let i=t.length;for(let s=0;s<i;){let c=Math.min(o-this.pos,i-s);if(c===o){let u=tt(t);for(;o<=i-s;s+=o)this.process(u,s);continue}r.set(t.subarray(s,s+c),this.pos),this.pos+=c,s+=c,this.pos===o&&(this.process(n,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ct(this),kn(t,this),this.finished=!0;let{buffer:n,view:r,blockLen:o,isLE:i}=this,{pos:s}=this;n[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>o-s&&(this.process(r,0),s=0);for(let f=s;f<o;f++)n[f]=0;po(r,o-8,BigInt(this.length*8),i),this.process(r,0);let c=tt(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let a=u/4,l=this.get();if(a>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<a;f++)c.setUint32(4*f,l[f],i)}digest(){let{buffer:t,outputLen:n}=this;this.digestInto(t);let r=t.slice(0,n);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:n,buffer:r,length:o,finished:i,destroyed:s,pos:c}=this;return t.length=o,t.pos=c,t.finished=i,t.destroyed=s,o%n&&t.buffer.set(r),t}};var mo=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]),fe=new Uint32Array(64),Lt=class extends nt{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:n,C:r,D:o,E:i,F:s,G:c,H:u}=this;return[t,n,r,o,i,s,c,u]}set(t,n,r,o,i,s,c,u){this.A=t|0,this.B=n|0,this.C=r|0,this.D=o|0,this.E=i|0,this.F=s|0,this.G=c|0,this.H=u|0}process(t,n){for(let f=0;f<16;f++,n+=4)fe[f]=t.getUint32(n,!1);for(let f=16;f<64;f++){let p=fe[f-15],m=fe[f-2],h=$(p,7)^$(p,18)^p>>>3,g=$(m,17)^$(m,19)^m>>>10;fe[f]=g+fe[f-7]+h+fe[f-16]|0}let{A:r,B:o,C:i,D:s,E:c,F:u,G:a,H:l}=this;for(let f=0;f<64;f++){let p=$(c,6)^$(c,11)^$(c,25),m=l+p+Bn(c,u,a)+mo[f]+fe[f]|0,g=($(r,2)^$(r,13)^$(r,22))+Ln(r,o,i)|0;l=a,a=u,u=c,c=s+m|0,s=i,i=o,o=r,r=m+g|0}r=r+this.A|0,o=o+this.B|0,i=i+this.C|0,s=s+this.D|0,c=c+this.E|0,u=u+this.F|0,a=a+this.G|0,l=l+this.H|0,this.set(r,o,i,s,c,u,a,l)}roundClean(){fe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Sn=Cn(()=>new Lt);import{PublicKey as wo}from"@solana/web3.js";import Nn,{isBN as Hu}from"bn.js";import{bits as ja,BitStructure as za,blob as ho,Blob as Za,cstr as Ya,f32 as Xa,f32be as Qa,f64 as Ja,f64be as $a,greedy as eu,Layout as go,ns64 as tu,ns64be as nu,nu64 as ru,nu64be as ou,offset as iu,s16 as su,s16be as cu,s24 as au,s24be as uu,s32 as lu,s32be as fu,s40 as pu,s40be as mu,s48 as du,s48be as hu,s8 as gu,seq as bu,struct as yu,Structure as bo,u16 as wu,u16be as xu,u24 as Tu,u24be as Pu,u32 as Au,u32be as ku,u40 as Cu,u40be as Bu,u48 as Lu,u48be as Su,u8 as Iu,UInt as yo,union as Nu,Union as _u,unionLayoutDiscriminator as Eu,utf8 as Ru}from"@solana/buffer-layout";var St=go,In=bo;var It=yo;var Nt=ho;var _t=class extends St{constructor(n,r,o){super(n,o);this.blob=Nt(n),this.signed=r}decode(n,r=0){let o=new Nn(this.blob.decode(n,r),10,"le");return this.signed?o.fromTwos(this.span*8).clone():o}encode(n,r,o=0){return typeof n=="number"&&(n=new Nn(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function _n(e){return new It(1,e)}function rt(e){return new It(4,e)}function ot(e){return new _t(8,!1,e)}var Et=class extends St{constructor(n,r,o,i){super(n.span,i);this.layout=n,this.decoder=r,this.encoder=o}decode(n,r){return this.decoder(this.layout.decode(n,r))}encode(n,r,o){return this.layout.encode(this.encoder(n),r,o)}getSpan(n,r){return this.layout.getSpan(n,r)}};function Re(e){return new Et(Nt(32),t=>new wo(t),t=>t.toBuffer(),e)}var Rt=class extends In{decode(t,n){return super.decode(t,n)}};function En(e,t,n){return new Rt(e,t,n)}var Me=En([Re("mint"),Re("owner"),ot("amount"),rt("delegateOption"),Re("delegate"),_n("state"),rt("isNativeOption"),ot("isNative"),ot("delegatedAmount"),rt("closeAuthorityOption"),Re("closeAuthority")]);var sl=j("Raydium_Util");function Mn({owner:e,solAccountResp:t,tokenAccountResp:n}){let r=[],o=[];for(let{pubkey:i,account:s}of n.value){let c=Me.decode(s.data),{mint:u,amount:a}=c;r.push({publicKey:i,mint:u,amount:a,isAssociated:Xe(e,u,s.owner).publicKey.equals(i),isNative:!1,programId:s.owner}),o.push({pubkey:i,accountInfo:c,programId:s.owner})}return t&&r.push({mint:Rn.default,amount:new To(String(t.lamports)),isNative:!0,programId:t.owner}),{tokenAccounts:r,tokenAccountRawInfos:o}}function it({fromPublicKey:e,programId:t=Po,assignSeed:n}){let r=n?btoa(n).slice(0,32):xo.generate().publicKey.toBase58().slice(0,32);return{publicKey:Ao(e,r,t),seed:r}}function Ao(e,t,n){let r=Buffer.concat([e.toBuffer(),Buffer.from(t),n.toBuffer()]),o=Sn(r);return new Rn(o)}function Mt(e){let{mint:t,tokenAccount:n,owner:r,programId:o=we}=e;return So(n,t,r,o)}function De(e){let{tokenAccount:t,payer:n,multiSigners:r=[],owner:o,programId:i=we}=e;return Lo(t,n,o,r,i)}async function Dt(e){let{connection:t,amount:n,commitment:r,payer:o,owner:i,skipCloseAccount:s}=e,c=await t.getMinimumBalanceForRentExemption(Me.span,r),u=J(n).add(new Bo(c)),a=it({fromPublicKey:o,programId:we});return{addresses:{newAccount:a.publicKey},signers:[],instructions:[Co.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:a.seed,newAccountPubkey:a.publicKey,lamports:u.toNumber(),space:Me.span,programId:we}),Mt({mint:new ko(ne.address),tokenAccount:a.publicKey,owner:i,programId:we})],instructionTypes:[G.CreateAccount,G.InitAccount],endInstructionTypes:s?[]:[G.CloseAccount],endInstructions:s?[]:[De({tokenAccount:a.publicKey,payer:o,owner:i})]}}function Dn({source:e,destination:t,owner:n,amount:r,multiSigners:o=[],tokenProgram:i=we}){return Io(e,t,n,BigInt(String(r)),o,i)}var Kt=class extends Ee{constructor(n){super(n);this._tokenAccounts=[];this._tokenAccountRawInfos=[];this._accountListener=[];this._clientOwnedToken=!1;this._notSubscribeAccountChange=!1;this._accountFetchTime=0;let{tokenAccounts:r,tokenAccountRawInfos:o,notSubscribeAccountChange:i}=n;this._tokenAccounts=r||[],this._tokenAccountRawInfos=o||[],this._notSubscribeAccountChange=i!=null?i:!0,this._clientOwnedToken=!!(r||o)}get tokenAccounts(){return this._tokenAccounts}get tokenAccountRawInfos(){return this._tokenAccountRawInfos}set notSubscribeAccountChange(n){this._notSubscribeAccountChange=n}updateTokenAccount({tokenAccounts:n,tokenAccountRawInfos:r}){return n&&(this._tokenAccounts=n),r&&(this._tokenAccountRawInfos=r),this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=void 0,this._clientOwnedToken=!0,this}addAccountChangeListener(n){return this._accountListener.push(n),this}removeAccountChangeListener(n){return this._accountListener=this._accountListener.filter(r=>r!==n),this}getAssociatedTokenAccount(n,r){return Xe(this.scope.ownerPubKey,n,r).publicKey}resetTokenAccounts(){this._clientOwnedToken||(this._tokenAccounts=[],this._tokenAccountRawInfos=[])}async fetchWalletTokenAccounts(n){if(this._clientOwnedToken||!(n!=null&&n.forceUpdate)&&this._tokenAccounts.length&&Date.now()-this._accountFetchTime<(this._notSubscribeAccountChange?1e3*5:1e3*60*3))return{tokenAccounts:this._tokenAccounts,tokenAccountRawInfos:this._tokenAccountRawInfos};this.scope.checkOwner();let o=V(V({},{}),n),[i,s,c]=await Promise.all([this.scope.connection.getAccountInfo(this.scope.ownerPubKey,o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:pe},o.commitment),this.scope.connection.getTokenAccountsByOwner(this.scope.ownerPubKey,{programId:_o},o.commitment)]),{tokenAccounts:u,tokenAccountRawInfos:a}=Mn({owner:this.scope.ownerPubKey,solAccountResp:i,tokenAccountResp:{context:s.context,value:[...s.value,...c.value]}});return this._tokenAccounts=u,this._tokenAccountRawInfos=a,this._accountFetchTime=Date.now(),this._notSubscribeAccountChange||(this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=this.scope.connection.onAccountChange(this.scope.ownerPubKey,()=>{this.fetchWalletTokenAccounts({forceUpdate:!0}),this._accountListener.forEach(l=>l({tokenAccounts:this._tokenAccounts,tokenAccountRawInfos:this._tokenAccountRawInfos}))},{commitment:n==null?void 0:n.commitment})),{tokenAccounts:u,tokenAccountRawInfos:a}}clearAccountChangeCkb(){this._accountChangeListenerId!==void 0&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId)}async getCreatedTokenAccount({mint:n,programId:r=pe,associatedOnly:o=!0}){await this.fetchWalletTokenAccounts();let i=this._tokenAccounts.filter(({mint:c})=>c==null?void 0:c.equals(n)).sort((c,u)=>c.amount.lt(u.amount)?1:-1),s=this.getAssociatedTokenAccount(n,r);for(let c of i){let{publicKey:u}=c;if(u&&(!o||o&&s.equals(u)))return u}}async getOrCreateTokenAccount(n){var g,y,T,A;await this.fetchWalletTokenAccounts();let{mint:r,createInfo:o,associatedOnly:i,owner:s,notUseTokenAccount:c=!1,skipCloseAccount:u=!1,checkCreateATAOwner:a=!1,assignSeed:l}=n,f=new st(n.tokenProgram||pe),p=this.getAssociatedTokenAccount(r,new st(f)),m=(c?[]:this.tokenAccountRawInfos).filter(b=>b.accountInfo.mint.equals(r)&&(!i||b.pubkey.equals(p))).sort((b,w)=>b.accountInfo.amount.lt(w.accountInfo.amount)?1:-1);if(o===void 0||m.length>0)return m.length>0?{account:m[0].pubkey}:{};let h={instructions:[],endInstructions:[],signers:[],instructionTypes:[],endInstructionTypes:[]};if(i){let b=Ot(s,p,s,r,f),w=this.tokenAccountRawInfos.find(x=>x.pubkey.equals(p));if(a){let x=await this.scope.connection.getAccountInfo(p);if(x===null)(g=h.instructions)==null||g.push(b),h.instructionTypes.push(G.CreateATA);else if(!(x.owner.equals(f)&&xe.decode(x.data).mint.equals(r)&&xe.decode(x.data).owner.equals(s)))throw Error(`create ata check error -> mint: ${r.toString()}, ata: ${p.toString()}`)}else w===void 0&&(h.instructions.push(b),h.instructionTypes.push(G.CreateATA));if(r.equals(ie)&&o.amount){let x=await Dt({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:o.payer||this.scope.ownerPubKey,amount:(y=o.amount)!=null?y:0,skipCloseAccount:u});h.instructions.push(...x.instructions||[]),h.endInstructions.push(...x.endInstructions||[]),h.instructionTypes.push(...x.instructionTypes||[]),h.endInstructionTypes.push(...x.endInstructionTypes||[]),o.amount&&(h.instructions.push(Dn({source:x.addresses.newAccount,destination:p,owner:this.scope.ownerPubKey,amount:o.amount,tokenProgram:pe})),h.instructionTypes.push(G.TransferAmount))}return!u&&w===void 0&&(h.endInstructions.push(De({owner:s,payer:o.payer||s,tokenAccount:p,programId:f})),h.endInstructionTypes.push(G.CloseAccount)),{account:p,instructionParams:h}}else{let b=it({fromPublicKey:s,programId:f,assignSeed:l}),w=await this.scope.connection.getMinimumBalanceForRentExemption(xe.span),x=No.createAccountWithSeed({fromPubkey:s,basePubkey:s,seed:b.seed,newAccountPubkey:b.publicKey,lamports:w+Number((A=(T=o.amount)==null?void 0:T.toString())!=null?A:0),space:xe.span,programId:f});return h.instructions.push(x,Mt({mint:r,tokenAccount:b.publicKey,owner:this.scope.ownerPubKey,programId:f})),h.instructionTypes.push(G.CreateAccount),h.instructionTypes.push(G.InitAccount),u||(h.endInstructions.push(De({owner:s,payer:o.payer||s,tokenAccount:b.publicKey,programId:f})),h.endInstructionTypes.push(G.CloseAccount)),{account:b.publicKey,instructionParams:h}}}async checkOrCreateAta({mint:n,programId:r=pe,autoUnwrapWSOLToSOL:o}){var u;await this.fetchWalletTokenAccounts();let i=(u=this.scope.account.tokenAccounts.find(({mint:a})=>(a==null?void 0:a.toBase58())===n.toBase58()))==null?void 0:u.publicKey,s=this.scope.ownerPubKey,c={};if(!i){let a=this.getAssociatedTokenAccount(n,r),l=await Ot(s,a,s,n,r);c.instructions=[l],c.instructionTypes=[G.CreateATA],i=a}return o&&ie.toBase58()===n.toBase58()&&(c.endInstructions=[De({owner:s,payer:s,tokenAccount:i,programId:r})],c.endInstructionTypes=[G.CloseAccount]),{pubKey:i,newInstructions:c}}async handleTokenAccount(n){let{side:r,amount:o,mint:i,programId:s=pe,tokenAccount:c,payer:u=this.scope.ownerPubKey,bypassAssociatedCheck:a,skipCloseAccount:l,checkCreateATAOwner:f}=n,p=this.getAssociatedTokenAccount(i,s);if(new st(ie).equals(i)){let m=await Dt({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:u,amount:o,skipCloseAccount:l});return V({tokenAccount:m.addresses.newAccount},m)}else if(!c||r==="out"&&!p.equals(c)&&!a){let m=[],h=Ot(this.scope.ownerPubKey,p,this.scope.ownerPubKey,i,s);if(f){let g=await this.scope.connection.getAccountInfo(p);if(g===null)m.push(h);else if(!(g.owner.equals(pe)&&xe.decode(g.data).mint.equals(i)&&xe.decode(g.data).owner.equals(this.scope.ownerPubKey)))throw Error(`create ata check error -> mint: ${i.toString()}, ata: ${p.toString()}`)}else m.push(h);return{tokenAccount:p,instructions:m,instructionTypes:[G.CreateATA]}}return{tokenAccount:c}}async processTokenAccount(n){let{mint:r,programId:o=pe,amount:i,useSOLBalance:s,handleTokenAccount:c}=n,u,a=this.createTxBuilder();if(r.equals(new st(ie))&&s){let l=await this.handleTokenAccount({side:"in",amount:i||0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=l,m=me(l,["tokenAccount"]);u=p,a.addInstruction(m)}else if(u=await this.getCreatedTokenAccount({mint:r,associatedOnly:!1,programId:o}),!u&&c){let f=await this.scope.account.handleTokenAccount({side:"in",amount:0,mint:r,bypassAssociatedCheck:!0,programId:o}),{tokenAccount:p}=f,m=me(f,["tokenAccount"]);u=p,a.addInstruction(m)}return V({tokenAccount:u},a.AllTxData)}};export{Kt as default};
|
|
2
2
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
3
|
//# sourceMappingURL=account.mjs.map
|