@raydium-io/raydium-sdk-v2 0.1.80-alpha → 0.1.81-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-32ee53bc.d.ts → api-7264fa6b.d.ts} +13 -13
- 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/layout.d.ts +2 -2
- 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 +15 -15
- 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/layout.d.ts +3 -3
- 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 +2 -2
- 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/serum/layout.d.ts +2 -2
- package/lib/raydium/token/constant.d.ts +1 -1
- package/lib/raydium/token/index.d.ts +1 -1
- package/lib/raydium/token/layout.d.ts +2 -2
- 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-7a07027a.d.ts → raydium-dc89bd2c.d.ts} +8 -5
- package/lib/{type-af770c47.d.ts → type-c36f6551.d.ts} +1 -1
- package/package.json +2 -2
- package/src/raydium/account/account.ts +21 -7
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var Dn=Object.defineProperty,On=Object.defineProperties;var Kn=Object.getOwnPropertyDescriptors;var Oe=Object.getOwnPropertySymbols;var Ft=Object.prototype.hasOwnProperty,Vt=Object.prototype.propertyIsEnumerable;var vt=(e,t,n)=>t in e?Dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))Ft.call(t,n)&&vt(e,n,t[n]);if(Oe)for(var n of Oe(t))Vt.call(t,n)&&vt(e,n,t[n]);return e},oe=(e,t)=>On(e,Kn(t));var me=(e,t)=>{var n={};for(var r in e)Ft.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&&Vt.call(e,r)&&(n[r]=e[r]);return n};import{PublicKey as st,SystemProgram as So}from"@solana/web3.js";import{PublicKey as Vn}from"@solana/web3.js";import{get as Wt,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}},Ut={},Fn={};function H(e){let t=Wt(Ut,e);if(!t){let n=Wt(Fn,e);t=new at({name:e,logLevel:n}),vn(Ut,e,t)}return t}import{MINT_SIZE as Vo,TOKEN_PROGRAM_ID as Wo,getTransferFeeConfig as Uo,unpackMint as qo}from"@solana/spl-token";var ct=H("Raydium_accountInfo_util");async function qt(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 c=s.map(f=>{let p=e._buildArgs([f.map(m=>m.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:p}}),u=ut(c,10);a=(await(await Promise.all(u.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:y,lamports:h,owner:x,rentEpoch:T}=p;return m.length!==2&&m[1]!=="base64"&&ct.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(m[0],"base64"),executable:y,lamports:h,owner:new Vn(x),rentEpoch:T}}return null})))}else try{a=await Promise.all(s.map(c=>e.getMultipleAccountsInfo(c,o)))}catch(c){c instanceof Error&&ct.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}import ne 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},zt,ee,C=!0,We="[DecimalError] ",ce=We+"Invalid argument: ",Zt=We+"Precision limit exceeded",Yt=We+"crypto unavailable",Xt="[object Decimal]",j=Math.floor,W=Math.pow,Wn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Un=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,qn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Qt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Y=1e7,k=7,Gn=9007199254740991,Hn=ve.length-1,pt=Fe.length-1,d={toStringTag:Xt};d.absoluteValue=d.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),P(e)};d.ceil=function(){return P(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,c=i.s,u=e.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(i.e!==e.e)return i.e>e.e^c<0?1:-1;for(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]^c<0?1:-1;return r===o?0:r>o^c<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())+k,r.rounding=1,n=jn(r,nn(r,n)),r.precision=e,r.rounding=t,P(ee==2||ee==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,c,u,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(C=!1,i=l.s*W(l.s*l,1/3),!i||Math.abs(i)==1/0?(n=G(l.d),e=l.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=W(n,1/3),e=j((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,c=a.times(a).times(a),u=c.plus(l),r=E(u.plus(l).times(a),u.plus(c),s+2,1),G(a.d).slice(0,s)===(n=G(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(P(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")&&(P(r,e+1,1),t=!r.times(r).times(r).eq(l));break}return C=!0,P(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-j(this.e/k))*k,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};d.dividedBy=d.div=function(e){return E(this,new this.constructor(e))};d.dividedToIntegerBy=d.divToInt=function(e){var t=this,n=t.constructor;return P(E(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 P(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 c,u=e,l=new s(8);u--;)c=i.times(i),i=a.minus(c.times(l.minus(c.times(l))));return P(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),c=new i(16),u=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(c.times(s).plus(u))))}return i.precision=t,i.rounding=n,P(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,E(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()?Z(n,o,i):new n(0):new n(NaN):t.isZero()?Z(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=Z(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,C=!1,n=n.times(n).minus(1).sqrt().plus(n),C=!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,C=!1,n=n.times(n).plus(1).sqrt().plus(n),C=!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?P(new i(o),e,t,!0):(i.precision=n=r-o.e,o=E(o.plus(1),new i(1).minus(o),n+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};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=Z(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,c,u=this,l=u.constructor,f=l.precision,p=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&f+4<=pt)return s=Z(l,f+4,p).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(f+4<=pt)return s=Z(l,f+4,p).times(.5),s.s=u.s,s}for(l.precision=a=f+10,l.rounding=1,n=Math.min(28,a/k+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(C=!1,t=Math.ceil(a/k),r=1,c=u.times(u),s=new l(u),o=u;e!==-1;)if(o=o.times(c),i=s.minus(o.div(r+=2)),o=o.times(c),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)),C=!0,P(s,l.precision=f,l.rounding=p,!0)};d.isFinite=function(){return!!this.d};d.isInteger=d.isInt=function(){return!!this.d&&j(this.e/k)>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,c,u=this,l=u.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=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.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(C=!1,a=f+m,s=ae(u,a),r=t?Ve(l,a+10):ae(e,a),c=E(s,r,a,1),Te(c.d,o=f,p))do if(a+=10,s=ae(u,a),r=t?Ve(l,a+10):ae(e,a),c=E(s,r,a,1),!i){+G(c.d).slice(o+1,o+15)+1==1e14&&(c=P(c,f+1,0));break}while(Te(c.d,o+=10,p));return C=!0,P(c,f,p)};d.minus=d.sub=function(e){var t,n,r,o,i,s,a,c,u,l,f,p,m=this,y=m.constructor;if(e=new y(e),!m.d||!e.d)return!m.s||!e.s?e=new y(NaN):m.d?e.s=-e.s:e=new y(e.d||m.s!==e.s?m:NaN),e;if(m.s!=e.s)return e.s=-e.s,m.plus(e);if(u=m.d,p=e.d,a=y.precision,c=y.rounding,!u[0]||!p[0]){if(p[0])e.s=-e.s;else if(u[0])e=new y(m);else return new y(c===3?-0:0);return C?P(e,a,c):e}if(n=j(e.e/k),l=j(m.e/k),u=u.slice(),i=l-n,i){for(f=i<0,f?(t=u,i=-i,s=p.length):(t=p,n=l,s=u.length),r=Math.max(Math.ceil(a/k),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=u.length,s=p.length,f=r<s,f&&(s=r),r=0;r<s;r++)if(u[r]!=p[r]){f=u[r]<p[r];break}i=0}for(f&&(t=u,u=p,p=t,e.s=-e.s),s=u.length,r=p.length-s;r>0;--r)u[s++]=0;for(r=p.length;r>i;){if(u[--r]<p[r]){for(o=r;o&&u[--o]===0;)u[o]=Y-1;--u[o],u[r]+=Y}u[r]-=p[r]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=Ue(u,n),C?P(e,a,c):e):new y(c===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]?P(new r(n),r.precision,r.rounding):(C=!1,r.modulo==9?(t=E(n,e.abs(),0,3,1),t.s*=e.s):t=E(n,e,0,r.modulo,1),t=t.times(e),C=!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,P(e)};d.plus=d.add=function(e){var t,n,r,o,i,s,a,c,u,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(u=f.d,l=e.d,a=p.precision,c=p.rounding,!u[0]||!l[0])return l[0]||(e=new p(f)),C?P(e,a,c):e;if(i=j(f.e/k),r=j(e.e/k),u=u.slice(),o=i-r,o){for(o<0?(n=u,o=-o,s=l.length):(n=l,r=i,s=u.length),i=Math.ceil(a/k),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=u.length,o=l.length,s-o<0&&(o=s,n=l,l=u,u=n),t=0;o;)t=(u[--o]=u[o]+l[o]+t)/Y|0,u[o]%=Y;for(t&&(u.unshift(t),++r),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=Ue(u,r),C?P(e,a,c):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=Jt(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};d.round=function(){var e=this,t=e.constructor;return P(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())+k,r.rounding=1,n=Zn(r,nn(r,n)),r.precision=e,r.rounding=t,P(ee>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,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(C=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=G(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=j((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),r=new l(t)):r=new l(u.toString()),n=(c=l.precision)+3;;)if(i=r,r=i.plus(E(s,i,n+2,1)).times(.5),G(i.d).slice(0,n)===(t=G(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(P(i,c+1,0),i.times(i).eq(s))){r=i;break}n+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(P(r,c+1,1),e=!r.times(r).eq(s));break}return C=!0,P(r,c,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=E(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,P(ee==2||ee==4?n.neg():n,e,t,!0)):new r(NaN)};d.times=d.mul=function(e){var t,n,r,o,i,s,a,c,u,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=j(l.e/k)+j(e.e/k),c=p.length,u=m.length,c<u&&(i=p,p=m,m=i,s=c,c=u,u=s),i=[],s=c+u,r=s;r--;)i.push(0);for(r=u;--r>=0;){for(t=0,o=c+r;o>r;)a=i[o]+m[r]*p[o-r-1]+t,i[o--]=a%Y|0,t=a/Y|0;i[o]=(i[o]+t)%Y|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=Ue(i,n),C?P(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:(z(e,0,ue),t===void 0?t=r.rounding:z(t,0,8),P(n,e+n.e+1,t))};d.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=$(r,!0):(z(e,0,ue),t===void 0?t=o.rounding:z(t,0,8),r=P(new o(r),e+1,t),n=$(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=$(o):(z(e,0,ue),t===void 0?t=i.rounding:z(t,0,8),r=P(new i(o),e+o.e+1,t),n=$(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};d.toFraction=function(e){var t,n,r,o,i,s,a,c,u,l,f,p,m=this,y=m.d,h=m.constructor;if(!y)return new h(m);if(u=n=new h(1),r=c=new h(0),t=new h(r),i=t.e=Jt(y)-m.e-1,s=i%k,t.d[0]=W(10,s<0?k+s:s),e==null)e=i>0?t:u;else{if(a=new h(e),!a.isInt()||a.lt(u))throw Error(ce+a);e=a.gt(t)?i>0?t:u:a}for(C=!1,a=new h(G(y)),l=h.precision,h.precision=i=y.length*k*2;f=E(a,t,0,1,1),o=n.plus(f.times(r)),o.cmp(e)!=1;)n=r,r=o,o=u,u=c.plus(f.times(o)),c=o,o=t,t=a.minus(f.times(o)),a=o;return o=E(e.minus(n),r,0,1,1),c=c.plus(o.times(u)),n=n.plus(o.times(r)),c.s=u.s=m.s,p=E(u,r,i,1).minus(m).abs().cmp(E(c,n,i,1).minus(m).abs())<1?[u,r]:[c,n],h.precision=l,C=!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:z(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]?(C=!1,n=E(n,e,0,t,1).times(e),C=!0,P(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,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(W(+a,u));if(a=new c(a),a.eq(1))return a;if(r=c.precision,i=c.rounding,e.eq(1))return P(a,r,i);if(t=j(e.e/k),t>=e.d.length-1&&(n=u<0?-u:u)<=Gn)return o=$t(c,a,n,r),e.s<0?new c(1).div(o):P(o,r,i);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=W(+a,u),t=n==0||!isFinite(n)?j(u*(Math.log("0."+G(a.d))/Math.LN10+a.e+1)):new c(n+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(C=!1,c.rounding=a.s=1,n=Math.min(12,(t+"").length),o=mt(e.times(ae(a,r+n)),r),o.d&&(o=P(o,r+5,1),Te(o.d,r,i)&&(t=r+10,o=P(mt(e.times(ae(a,t+n)),t),t+5,1),+G(o.d).slice(r+1,r+15)+1==1e14&&(o=P(o,r+1,0)))),o.s=s,C=!0,c.rounding=i,P(o,r,i))};d.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=$(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(z(e,1,ue),t===void 0?t=o.rounding:z(t,0,8),r=P(new o(r),e,t),n=$(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):(z(e,1,ue),t===void 0?t=r.rounding:z(t,0,8)),P(new r(n),e,t)};d.toString=function(){var e=this,t=e.constructor,n=$(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};d.truncated=d.trunc=function(){return P(new this.constructor(this),this.e+1,1)};d.valueOf=d.toJSON=function(){var e=this,t=e.constructor,n=$(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function G(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=k-r.length,n&&(i+=se(n)),i+=r;s=e[t],r=s+"",n=k-r.length,n&&(i+=se(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function z(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+=k,o=0):(o=Math.ceil((t+1)/k),t%=k),i=W(10,k-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)==W(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)==W(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 jn(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 E=function(){function e(r,o,i){var s,a=0,c=r.length;for(r=r.slice();c--;)s=r[c]*o+a,r[c]=s%i|0,a=s/i|0;return a&&r.unshift(a),r}function t(r,o,i,s){var a,c;if(i!=s)c=i>s?1:-1;else for(a=c=0;a<i;a++)if(r[a]!=o[a]){c=r[a]>o[a]?1:-1;break}return c}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,c){var u,l,f,p,m,y,h,x,T,w,g,b,B,A,N,q,K,D,R,F,J=r.constructor,re=r.s==o.s?1:-1,V=r.d,_=o.d;if(!V||!V[0]||!_||!_[0])return new J(!r.s||!o.s||(V?_&&V[0]==_[0]:!_)?NaN:V&&V[0]==0||!_?re*0:re/0);for(c?(m=1,l=r.e-o.e):(c=Y,m=k,l=j(r.e/m)-j(o.e/m)),R=_.length,K=V.length,T=new J(re),w=T.d=[],f=0;_[f]==(V[f]||0);f++);if(_[f]>(V[f]||0)&&l--,i==null?(A=i=J.precision,s=J.rounding):a?A=i+(r.e-o.e)+1:A=i,A<0)w.push(1),y=!0;else{if(A=A/m+2|0,f=0,R==1){for(p=0,_=_[0],A++;(f<K||p)&&A--;f++)N=p*c+(V[f]||0),w[f]=N/_|0,p=N%_|0;y=p||f<K}else{for(p=c/(_[0]+1)|0,p>1&&(_=e(_,p,c),V=e(V,p,c),R=_.length,K=V.length),q=R,g=V.slice(0,R),b=g.length;b<R;)g[b++]=0;F=_.slice(),F.unshift(0),D=_[0],_[1]>=c/2&&++D;do p=0,u=t(_,g,R,b),u<0?(B=g[0],R!=b&&(B=B*c+(g[1]||0)),p=B/D|0,p>1?(p>=c&&(p=c-1),h=e(_,p,c),x=h.length,b=g.length,u=t(h,g,x,b),u==1&&(p--,n(h,R<x?F:_,x,c))):(p==0&&(u=p=1),h=_.slice()),x=h.length,x<b&&h.unshift(0),n(g,h,b,c),u==-1&&(b=g.length,u=t(_,g,R,b),u<1&&(p++,n(g,R<b?F:_,b,c))),b=g.length):u===0&&(p++,g=[0]),w[f++]=p,u&&g[0]?g[b++]=V[q]||0:(g=[V[q]],b=1);while((q++<K||g[0]!==void 0)&&A--);y=g[0]!==void 0}w[0]||w.shift()}if(m==1)T.e=l,zt=y;else{for(f=1,p=w[0];p>=10;p/=10)f++;T.e=f+l*m-1,P(T,a?i+T.e+1:i,s,y)}return T}}();function P(e,t,n,r){var o,i,s,a,c,u,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+=k,s=t,l=f[p=0],c=l/W(10,o-s-1)%10|0;else if(p=Math.ceil((i+1)/k),a=f.length,p>=a)if(r){for(;a++<=p;)f.push(0);l=c=0,o=1,i%=k,s=i-k+1}else break e;else{for(l=a=f[p],o=1;a>=10;a/=10)o++;i%=k,s=i-k+o,c=s<0?0:l/W(10,o-s-1)%10|0}if(r=r||t<0||f[p+1]!==void 0||(s<0?l:l%W(10,o-s-1)),u=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(i>0?s>0?l/W(10,o-s):0:f[p-1])%10&1||n==(e.s<0?8:7)),t<1||!f[0])return f.length=0,u?(t-=e.e+1,f[0]=W(10,(k-t%k)%k),e.e=-t||0):f[0]=e.e=0,e;if(i==0?(f.length=p,a=1,p--):(f.length=p+1,a=W(10,k-i),f[p]=s>0?(l/W(10,o-s)%W(10,s)|0)*a:0),u)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]==Y&&(f[0]=1));break}else{if(f[p]+=a,f[p]!=Y)break;f[p--]=0,a=1}for(i=f.length;f[--i]===0;)f.pop()}return C&&(e.e>m.maxE?(e.d=null,e.e=NaN):e.e<m.minE&&(e.e=0,e.d=[0])),e}function $(e,t,n){if(!e.isFinite())return tn(e);var r,o=e.e,i=G(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*=k;n>=10;n/=10)t++;return t}function Ve(e,t,n){if(t>Hn)throw C=!0,n&&(e.precision=n),Error(Zt);return P(new e(ve),t,1,!0)}function Z(e,t,n){if(t>pt)throw Error(Zt);return P(new e(Fe),t,n,!0)}function Jt(e){var t=e.length-1,n=t*k+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 $t(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/k+4);for(C=!1;;){if(n%2&&(i=i.times(t),Ht(i.d,s)&&(o=!0)),n=j(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),Ht(t.d,s)}return C=!0,i}function Gt(e){return e.d[e.d.length-1]&1}function en(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,c,u=0,l=0,f=0,p=e.constructor,m=p.rounding,y=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?(C=!1,c=y):c=t,a=new p(.03125);e.e>-2;)e=e.times(a),f+=5;for(r=Math.log(W(2,f))/Math.LN10*2+5|0,c+=r,n=i=s=new p(1),p.precision=c;;){if(i=P(i.times(e),c,1),n=n.times(++l),a=s.plus(E(i,n,c,1)),G(a.d).slice(0,c)===G(s.d).slice(0,c)){for(o=f;o--;)s=P(s.times(s),c,1);if(t==null)if(u<3&&Te(s.d,c-r,m,u))p.precision=c+=10,n=i=a=new p(1),l=0,u++;else return P(s,p.precision=y,m,C=!0);else return p.precision=y,s}s=a}}function ae(e,t){var n,r,o,i,s,a,c,u,l,f,p,m=1,y=10,h=e,x=h.d,T=h.constructor,w=T.rounding,g=T.precision;if(h.s<0||!x||!x[0]||!h.e&&x[0]==1&&x.length==1)return new T(x&&!x[0]?-1/0:h.s!=1?NaN:x?0:h);if(t==null?(C=!1,l=g):l=t,T.precision=l+=y,n=G(x),r=n.charAt(0),Math.abs(i=h.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=G(h.d),r=n.charAt(0),m++;i=h.e,r>1?(h=new T("0."+n),i++):h=new T(r+"."+n.slice(1))}else return u=Ve(T,l+2,g).times(i+""),h=ae(new T(r+"."+n.slice(1)),l-y).plus(u),T.precision=g,t==null?P(h,g,w,C=!0):h;for(f=h,c=s=h=E(h.minus(1),h.plus(1),l,1),p=P(h.times(h),l,1),o=3;;){if(s=P(s.times(p),l,1),u=c.plus(E(s,new T(o),l,1)),G(u.d).slice(0,l)===G(c.d).slice(0,l))if(c=c.times(2),i!==0&&(c=c.plus(Ve(T,l+2,g).times(i+""))),c=E(c,new T(m),l,1),t==null)if(Te(c.d,l-y,w,a))T.precision=l+=y,u=s=h=E(f.minus(1),f.plus(1),l,1),p=P(h.times(h),l,1),o=a=1;else return P(c,T.precision=g,w,C=!0);else return T.precision=g,c;c=u,o+=2}}function tn(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)%k,n<0&&(r+=k),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=k;r<o;)e.d.push(+t.slice(r,r+=k));t=t.slice(r),r=k-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),C&&(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 zn(e,t){var n,r,o,i,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Qt.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(Un.test(t))n=16,t=t.toLowerCase();else if(Wn.test(t))n=2;else if(qn.test(t))n=8;else throw Error(ce+t);for(i=t.search(/p/i),i>0?(c=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=$t(r,new r(n),i,i*2)),u=Ke(t,n,Y),l=u.length-1,i=l;u[i]===0;--i)u.pop();return i<0?new r(e.s*0):(e.e=Ue(u,l),e.d=u,C=!1,s&&(e=E(e,o,a*4)),c&&(e=e.times(Math.abs(c)<54?W(2,c):Ge.pow(2,c))),C=!0,e)}function Zn(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,c,u=1,l=e.precision,f=Math.ceil(l/k);for(C=!1,c=n.times(n),a=new e(r);;){if(s=E(a.times(c),new e(t++*t++),l,1),a=o?r.plus(s):r.minus(s),r=E(s.times(c),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,u++}return C=!0,s.d.length=f+1,s}function qe(e,t){for(var n=e;--t;)n*=e;return n}function nn(e,t){var n,r=t.s<0,o=Z(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return ee=r?4:1,t;if(n=t.divToInt(o),n.isZero())ee=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return ee=Gt(n)?r?2:3:r?4:1,t;ee=Gt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function ht(e,t,n,r){var o,i,s,a,c,u,l,f,p,m=e.constructor,y=n!==void 0;if(y?(z(n,1,ue),r===void 0?r=m.rounding:z(r,0,8)):(n=m.precision,r=m.rounding),!e.isFinite())l=tn(e);else{for(l=$(e),s=l.indexOf("."),y?(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($(p),10,o),p.e=p.d.length),f=Ke(l,10,o),i=c=f.length;f[--c]==0;)f.pop();if(!f[0])l=y?"0p+0":"0";else{if(s<0?i--:(e=new m(e),e.d=f,e.e=i,e=E(e,p,n,r,0,o),f=e.d,i=e.e,u=zt),s=f[n],a=o/2,u=u||f[n+1]!==void 0,u=r<4?(s!==void 0||u)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||u||r===6&&f[n-1]&1||r===(e.s<0?8:7)),f.length=n,u)for(;++f[--n]>o-1;)f[n]=0,n||(++i,f.unshift(1));for(c=f.length;!f[c-1];--c);for(s=0,l="";s<c;s++)l+=lt.charAt(f[s]);if(y){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(f=Ke(l,o,t),c=f.length;!f[c-1];--c);for(s=1,l="1.";s<c;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>c)for(i-=c;i--;)l+="0";else i<c&&(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 Ht(e,t){if(e.length>t)return e.length=t,!0}function Yn(e){return new this(e).abs()}function Xn(e){return new this(e).acos()}function Qn(e){return new this(e).acosh()}function Jn(e,t){return new this(e).plus(t)}function $n(e){return new this(e).asin()}function er(e){return new this(e).asinh()}function tr(e){return new this(e).atan()}function nr(e){return new this(e).atanh()}function rr(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=Z(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Z(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Z(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(E(e,t,i,1)),t=Z(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(E(e,t,i,1)),n}function or(e){return new this(e).cbrt()}function ir(e){return P(e=new this(e),e.e+1,2)}function sr(e,t,n){return new this(e).clamp(t,n)}function ar(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(j(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(Yt);else this[n]=!1;else throw Error(ce+n+": "+r);return this}function cr(e){return new this(e).cos()}function ur(e){return new this(e).cosh()}function rn(e){var t,n,r;function o(i){var s,a,c,u=this;if(!(u instanceof o))return new o(i);if(u.constructor=o,jt(i)){u.s=i.s,C?!i.d||i.e>o.maxE?(u.e=NaN,u.d=null):i.e<o.minE?(u.e=0,u.d=[0]):(u.e=i.e,u.d=i.d.slice()):(u.e=i.e,u.d=i.d?i.d.slice():i.d);return}if(c=typeof i,c==="number"){if(i===0){u.s=1/i<0?-1:1,u.e=0,u.d=[0];return}if(i<0?(i=-i,u.s=-1):u.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;C?s>o.maxE?(u.e=NaN,u.d=null):s<o.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[i]):(u.e=s,u.d=[i]);return}else if(i*0!==0){i||(u.s=NaN),u.e=NaN,u.d=null;return}return dt(u,i.toString())}else if(c!=="string")throw Error(ce+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),u.s=-1):(a===43&&(i=i.slice(1)),u.s=1),Qt.test(i)?dt(u,i):zn(u,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=ar,o.clone=rn,o.isDecimal=jt,o.abs=Yn,o.acos=Xn,o.acosh=Qn,o.add=Jn,o.asin=$n,o.asinh=er,o.atan=tr,o.atanh=nr,o.atan2=rr,o.cbrt=or,o.ceil=ir,o.clamp=sr,o.cos=cr,o.cosh=ur,o.div=lr,o.exp=fr,o.floor=pr,o.hypot=mr,o.ln=dr,o.log=hr,o.log10=br,o.log2=gr,o.max=yr,o.min=wr,o.mod=xr,o.mul=Tr,o.pow=Pr,o.random=Ar,o.round=kr,o.sign=Br,o.sin=Cr,o.sinh=Lr,o.sqrt=Sr,o.sub=Ir,o.sum=Nr,o.tan=_r,o.tanh=Er,o.trunc=Rr,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 lr(e,t){return new this(e).div(t)}function fr(e){return new this(e).exp()}function pr(e){return P(e=new this(e),e.e+1,3)}function mr(){var e,t,n=new this(0);for(C=!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 C=!0,new this(1/0);n=t}return C=!0,n.sqrt()}function jt(e){return e instanceof Ge||e&&e.toStringTag===Xt||!1}function dr(e){return new this(e).ln()}function hr(e,t){return new this(e).log(t)}function gr(e){return new this(e).log(2)}function br(e){return new this(e).log(10)}function yr(){return en(this,arguments,"lt")}function wr(){return en(this,arguments,"gt")}function xr(e,t){return new this(e).mod(t)}function Tr(e,t){return new this(e).mul(t)}function Pr(e,t){return new this(e).pow(t)}function Ar(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:z(e,1,ue),r=Math.ceil(e/k),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(Yt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=k,r&&e&&(o=W(10,k-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-=k)a.shift();for(r=1,o=a[0];o>=10;o/=10)r++;r<k&&(n-=k-r)}return s.e=n,s.d=a,s}function kr(e){return P(e=new this(e),e.e+1,this.rounding)}function Br(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Cr(e){return new this(e).sin()}function Lr(e){return new this(e).sinh()}function Sr(e){return new this(e).sqrt()}function Ir(e,t){return new this(e).sub(t)}function Nr(){var e=0,t=arguments,n=new this(t[e]);for(C=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return C=!0,P(n,this.precision,this.rounding)}function _r(e){return new this(e).tan()}function Er(e){return new this(e).tanh()}function Rr(e){return P(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=rn(ft);ve=new Ge(ve);Fe=new Ge(Fe);import Wr from"big.js";import ci from"bn.js";import Mr from"toformat";var Dr=Mr,Pe=Dr;import je from"big.js";import Kr from"bn.js";import vr from"decimal.js-light";import Ae from"bn.js";var on=9007199254740991;function X(e){let t=H("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>=on||e<=-on)&&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=H("module/fraction"),gt=Pe(je),ke=Pe(vr),Fr={[0]:ke.ROUND_DOWN,[1]:ke.ROUND_HALF_UP,[2]:ke.ROUND_UP},Vr={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},M=class{constructor(t,n=new Kr(1)){this.numerator=X(t),this.denominator=X(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new M(this.denominator,this.numerator)}add(t){let n=t instanceof M?t:new M(X(t));return this.denominator.eq(n.denominator)?new M(this.numerator.add(n.numerator),this.denominator):new M(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof M?t:new M(X(t));return this.denominator.eq(n.denominator)?new M(this.numerator.sub(n.numerator),this.denominator):new M(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof M?t:new M(X(t));return new M(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof M?t:new M(X(t));return new M(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:Fr[r]});let o=new ke(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},r=1){return Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<0&&He.logWithError(`${t} is negative.`),gt.DP=t,gt.RM=Vr[r]||1,new gt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var bi=H("Raydium_amount"),yi=Pe(Wr);import{PublicKey as qr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as sn}from"@solana/spl-token";var an={chainId:101,address:qr.default.toBase58(),programId:sn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},te={chainId:101,address:"So11111111111111111111111111111111111111112",programId:sn.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 O,SystemProgram as cn,SYSVAR_RENT_PUBKEY as Gr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Hr}from"@solana/spl-token";function bt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var Ci=[bt({pubkey:Hr,isWritable:!1}),bt({pubkey:cn.programId,isWritable:!1}),bt({pubkey:Gr,isWritable:!1})];function un({publicKey:e,transformSol:t}){let n=ln(e.toString());if(n instanceof O)return t&&n.equals(Be)?ie:n;if(t&&n.toString()===Be.toBase58())return ie;if(typeof n=="string"){if(n===O.default.toBase58())return O.default;try{return new O(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function ln(e){try{return new O(e)}catch{return e}}var Li=new O("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Si=new O("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ii=new O("SysvarRent111111111111111111111111111111111"),Ni=new O("SysvarC1ock11111111111111111111111111111111"),_i=new O("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ei=new O("Sysvar1nstructions1111111111111111111111111"),Ri=cn.programId,Mi=new O("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Di=new O("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Oi=new O("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ki=new O("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),vi=new O("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Fi=new O("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Vi=new O("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Wi=new O("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ui=new O("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),qi=new O("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Gi=new O("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),ie=new O("So11111111111111111111111111111111111111112"),Be=O.default;var wt=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Be.toBase58()||t instanceof yt&&Be.equals(t)){this.decimals=te.decimals,this.symbol=te.symbol,this.name=te.name,this.mint=new yt(te.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:un({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},be=wt;be.WSOL=new wt(oe(v({},te),{mint:te.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(an);import jr from"bn.js";var ns=new M(new jr(100));var cs=H("Raydium_price");import{PublicKey as Bs}from"@solana/web3.js";import Ls from"bn.js";var zr=new ne(0),js=new ne(1),zs=new ne(2),Zs=new ne(3),Ys=new ne(5),Ur=new ne(10),Xs=new ne(100),Qs=new ne(1e3),Js=new ne(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 eo}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as to}from"@solana/spl-token";import{ComputeBudgetProgram as dn,Keypair as gn,PublicKey as Zr,Transaction as bn,TransactionMessage as Yr,VersionedTransaction as yn}from"@solana/web3.js";var U={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 Xr}from"@solana/spl-token";var hn=H("Raydium_txUtil"),wn=1644;function Ze(e){let t=[],n=[];return e.microLamports&&(t.push(dn.setComputeUnitPrice({microLamports:e.microLamports})),n.push(U.SetComputeUnitPrice)),e.units&&(t.push(dn.setComputeUnitLimit({units:e.units})),n.push(U.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 Qr(e,t){e.length<1&&hn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&hn.logWithError(`no signers provided:, ${t.toString()}`);let n=new bn;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<wn}catch{return!1}}function xn(e,t){let[n,r]=Zr.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Ce({instructions:e,payer:t,signers:n}){return Qr(e,[t,...n])}function Le({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=gn.generate().publicKey.toString()}){let i=new Yr({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new yn(i).serialize()).toString("base64").length<wn}catch{return!1}}var Jr=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e),$r=e=>{let t=e.serialize({requireAllSignatures:!1,verifySignatures:!1});e instanceof yn&&(t=Jr(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 bn&&(n.recentBlockhash||(n.recentBlockhash=Xr.toBase58()),n.feePayer||(n.feePayer=gn.generate().publicKey)),t.push($r(n))}),console.log("simulate tx string:",t),t}function Xe(e,t,n){return xn([e.toBuffer(),(n!=null?n:to).toBuffer(),t.toBuffer()],new eo("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as L}from"@solana/web3.js";var wa=new L("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),xa=new L("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Ta=new L("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Pa=new L("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Aa=new L("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ka=new L("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Ba=new L("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Ca=new L("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),La=new L("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Sa=new L("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Ia=new L("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Na=new L("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),_a=new L("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Ea=new L("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ra=new L("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Ma=new L("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Da=new L("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Oa=new L("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Ka=new L("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),va=new L("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Fa=new L("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Va=new L("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),no=new L("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),ro=new L("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),oo=new L("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),Wa=new L("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),io=new L("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Ua=new L("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),so=new L("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var qa={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:no,CREATE_CPMM_POOL_AUTH:ro,CREATE_CPMM_POOL_FEE_ACC:oo,FEE_DESTINATION_ID:new L("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:io,LCOK_CPMM_AUTH:so};import ja from"bn.js";import{PublicKey as Tn,AddressLookupTableAccount as Qe}from"@solana/web3.js";async function Tt({connection:e,address:t}){let n=await qt(e,[...new Set(t.map(o=>o.toString()))].map(o=>new Tn(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 Tn("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 ao 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 ao.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 u;let{recentBlockHash:i,skipPreflight:s=!0,sendAndConfirm:a}=o||{},c=i!=null?i:await ye(this.connection,this.blockhashCommitment);if(n.recentBlockhash=c,this.signers.length&&n.sign(...this.signers),de([n]),(u=this.owner)!=null&&u.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 u;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)],c=[...this.instructionTypes,...i.map(l=>l.instructionTypes).flat()];return(u=this.owner)!=null&&u.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:c,execute:async l=>{var T;let{sequentially:f,onTxUpdate:p,skipTxCount:m=0,recentBlockHash:y,skipPreflight:h=!0}=l||{},x=y!=null?y:await ye(this.connection,this.blockhashCommitment);if((T=this.owner)!=null&&T.isKeyPair){if(f){let w=[],g=0;for(let b of s){if(++g,g<=m)continue;let B=await Pt(this.connection,b,this.signers.find(A=>A.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:h});w.push(B)}return{txIds:w,signedTxs:s}}return{txIds:await await Promise.all(s.map(async w=>(w.recentBlockhash=x,await this.connection.sendRawTransaction(w.serialize(),{skipPreflight:h})))),signedTxs:s}}if(this.signAllTransactions){let w=s.map((b,B)=>(b.recentBlockhash=x,a[B].length&&b.sign(...a[B]),b));de(w);let g=await this.signAllTransactions(w);if(f){let b=0,B=[],A=async()=>{if(!g[b])return;let N=await this.connection.sendRawTransaction(g[b].serialize(),{skipPreflight:h});B.push({txId:N,status:"sent",signedTx:g[b]}),p==null||p([...B]),b++,this.connection.onSignature(N,q=>{let K=B.findIndex(D=>D.txId===N);K>-1&&(B[K].status=q.err?"error":"success"),p==null||p([...B]),q.err||A()},"processed"),this.connection.getSignatureStatus(N)};return await A(),{txIds:B.map(N=>N.txId),signedTxs:g}}else{let b=[];for(let B=0;B<g.length;B+=1){let A=await this.connection.sendRawTransaction(g[B].serialize(),{skipPreflight:h});b.push(A)}return{txIds:b,signedTxs:g}}}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 h;let y=t||{},{lookupTableCache:n={},lookupTableAddress:r=[],forerunCreate:o,recentBlockhash:i}=y,s=me(y,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),a=v(v({},this.cluster==="devnet"?{}:Je),n),c=Array.from(new Set([...r,...this.lookupTableAddress])),u=[];for(let x of c)a[x]===void 0&&u.push(new Se(x));let l=await Tt({connection:this.connection,address:u});for(let[x,T]of Object.entries(l))a[x]=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(a));((h=this.owner)==null?void 0:h.signer)&&!this.signers.some(x=>x.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 x=>{var g;let{skipPreflight:T=!0,sendAndConfirm:w}=x||{};if(de([m]),(g=this.owner)!=null&&g.isKeyPair){let b=await this.connection.sendTransaction(m,{skipPreflight:T});return w&&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:T}),signedTx:b[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}async buildV0MultiTx(t){var u;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)],c=[...this.instructionTypes,...i.map(l=>l.instructionTypes).flat()];return(u=this.owner)!=null&&u.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:c,buildProps:r,execute:async l=>{var h;let{sequentially:f,onTxUpdate:p,recentBlockHash:m,skipPreflight:y=!0}=l||{};if(m&&s.forEach(x=>x.message.recentBlockhash=m),de(s),(h=this.owner)!=null&&h.isKeyPair){if(f){let x=[];for(let T of s){let w=await this.connection.sendTransaction(T,{skipPreflight:y});await Ye(this.connection,w),x.push(w)}return{txIds:x,signedTxs:s}}return{txIds:await Promise.all(s.map(async x=>await this.connection.sendTransaction(x,{skipPreflight:y}))),signedTxs:s}}if(this.signAllTransactions){let x=await this.signAllTransactions(s);if(f){let T=0,w=[],g=async()=>{if(!x[T])return;let b=await this.connection.sendTransaction(x[T],{skipPreflight:y});w.push({txId:b,status:"sent",signedTx:x[T]}),p==null||p([...w]),T++,this.connection.onSignature(b,B=>{let A=w.findIndex(N=>N.txId===b);A>-1&&(w[A].status=B.err?"error":"success"),p==null||p([...w]),B.err||g()},"processed"),this.connection.getSignatureStatus(b)};return g(),{txIds:[],signedTxs:x}}else{let T=[];for(let w=0;w<x.length;w+=1){let g=await this.connection.sendTransaction(x[w],{skipPreflight:y});T.push(g)}return{txIds:T,signedTxs:x}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuild(t){var l;let u=t||{},{computeBudgetConfig:n}=u,r=me(u,["computeBudgetConfig"]),o=n?Ze(n):{instructions:[],instructionTypes:[]},i=this.signers.reduce((f,p)=>oe(v({},f),{[p.publicKey.toBase58()]:p}),{}),s=[],a=[],c=[];if(this.allInstructions.forEach(f=>{let p=[...c,f],m=n?[...o.instructions,...p]:p,h=[...new Set(p.map(x=>x.keys.filter(T=>T.isSigner).map(T=>T.pubkey.toString())).flat()).values()].map(x=>new Se(x));if(c.length<12&&Ce({instructions:m,payer:this.feePayer,signers:h})||Ce({instructions:p,payer:this.feePayer,signers:h}))c.push(f);else{if(c.length===0)throw Error("item ins too big");Ce({instructions:n?[...o.instructions,...c]:[...c],payer:this.feePayer,signers:h})?s.push(new Ie().add(...o.instructions,...c)):s.push(new Ie().add(...c)),a.push(Array.from(new Set(c.map(x=>x.keys.filter(T=>T.isSigner).map(T=>T.pubkey.toString())).flat())).map(x=>i[x]).filter(x=>x!==void 0)),c=[f]}}),c.length>0){let p=[...new Set(c.map(m=>m.keys.filter(y=>y.isSigner).map(y=>y.pubkey.toString())).flat()).values()].map(m=>i[m]).filter(m=>m!==void 0);Ce({instructions:n?[...o.instructions,...c]:[...c],payer:this.feePayer,signers:p.map(m=>m.publicKey)})?s.push(new Ie().add(...o.instructions,...c)):s.push(new Ie().add(...c)),a.push(p)}return s.forEach(f=>f.feePayer=this.feePayer),(l=this.owner)!=null&&l.signer&&a.forEach(f=>{f.some(p=>p.publicKey.equals(this.owner.publicKey))||f.push(this.owner.signer)}),{builder:this,transactions:s,signers:a,instructionTypes:this.instructionTypes,execute:async f=>{var w;let{sequentially:p,onTxUpdate:m,skipTxCount:y=0,recentBlockHash:h,skipPreflight:x=!0}=f||{},T=h!=null?h:await ye(this.connection,this.blockhashCommitment);if(s.forEach(async(g,b)=>{g.recentBlockhash=T,a[b].length&&g.sign(...a[b])}),de(s),(w=this.owner)!=null&&w.isKeyPair){if(p){let g=0,b=[];for(let B of s){if(++g,g<=y){b.push("tx skipped");continue}let A=await Pt(this.connection,B,this.signers.find(N=>N.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:x});b.push(A)}return{txIds:b,signedTxs:s}}return{txIds:await Promise.all(s.map(async g=>await this.connection.sendRawTransaction(g.serialize(),{skipPreflight:x}))),signedTxs:s}}if(this.signAllTransactions){let g=await this.signAllTransactions(s.slice(y,s.length)),b=[...s.slice(0,y),...g];if(p){let B=0,A=[],N=async()=>{if(!b[B])return;B<y&&(A.push({txId:"",status:"success",signedTx:b[B]}),m==null||m([...A]),B++,N());let q=await this.connection.sendRawTransaction(b[B].serialize(),{skipPreflight:x});A.push({txId:q,status:"sent",signedTx:b[B]}),m==null||m([...A]),B++,this.connection.onSignature(q,K=>{let D=A.findIndex(R=>R.txId===q);D>-1&&(A[D].status=K.err?"error":"success"),m==null||m([...A]),K.err||N()},"processed"),this.connection.getSignatureStatus(q)};return await N(),{txIds:A.map(q=>q.txId),signedTxs:b}}else{let B=[];for(let A=0;A<b.length;A+=1){let N=await this.connection.sendRawTransaction(b[A].serialize(),{skipPreflight:x});B.push(N)}return{txIds:B,signedTxs:b}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuildV0(t){var T;let x=t||{},{computeBudgetConfig:n,lookupTableCache:r={},lookupTableAddress:o=[]}=x,i=me(x,["computeBudgetConfig","lookupTableCache","lookupTableAddress"]),s=v(v({},this.cluster==="devnet"?{}:Je),r),a=Array.from(new Set([...this.lookupTableAddress,...o])),c=[];for(let w of a)s[w]===void 0&&c.push(new Se(w));let u=await Tt({connection:this.connection,address:c});for(let[w,g]of Object.entries(u))s[w]=g;let l=n?Ze(n):{instructions:[],instructionTypes:[]},f=await ye(this.connection,this.blockhashCommitment),p=this.signers.reduce((w,g)=>oe(v({},w),{[g.publicKey.toBase58()]:g}),{}),m=[],y=[],h=[];if(this.allInstructions.forEach(w=>{let g=[...h,w],b=n?[...l.instructions,...g]:g;if(h.length<12&&Le({instructions:b,payer:this.feePayer,lookupTableAddressAccount:s})||Le({instructions:g,payer:this.feePayer,lookupTableAddressAccount:s}))h.push(w);else{if(h.length===0)throw Error("item ins too big");let B={};for(let A of[...new Set(a)])s[A]!==void 0&&(B[A]=s[A]);if(n&&Le({instructions:[...l.instructions,...h],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:f})){let A=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...l.instructions,...h]}).compileToV0Message(Object.values(s));m.push(new _e(A))}else{let A=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...h]}).compileToV0Message(Object.values(s));m.push(new _e(A))}y.push(Array.from(new Set(h.map(A=>A.keys.filter(N=>N.isSigner).map(N=>N.pubkey.toString())).flat())).map(A=>p[A]).filter(A=>A!==void 0)),h=[w]}}),h.length>0){let g=[...new Set(h.map(b=>b.keys.filter(B=>B.isSigner).map(B=>B.pubkey.toString())).flat()).values()].map(b=>p[b]).filter(b=>b!==void 0);if(n&&Le({instructions:[...l.instructions,...h],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:f})){let b=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...l.instructions,...h]}).compileToV0Message(Object.values(s));m.push(new _e(b))}else{let b=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...h]}).compileToV0Message(Object.values(s));m.push(new _e(b))}y.push(g)}return(T=this.owner)!=null&&T.signer&&y.forEach(w=>{w.some(g=>g.publicKey.equals(this.owner.publicKey))||w.push(this.owner.signer)}),{builder:this,transactions:m,buildProps:t,signers:y,instructionTypes:this.instructionTypes,execute:async w=>{var q;let{sequentially:g,onTxUpdate:b,skipTxCount:B=0,recentBlockHash:A,skipPreflight:N=!0}=w||{};if(m.map(async(K,D)=>{y[D].length&&K.sign(y[D]),A&&(K.message.recentBlockhash=A)}),de(m),(q=this.owner)!=null&&q.isKeyPair){if(g){let K=0,D=[];for(let R of m){if(++K,K<=B){console.log("skip tx: ",K),D.push("tx skipped");continue}let F=await this.connection.sendTransaction(R,{skipPreflight:N});await Ye(this.connection,F),D.push(F)}return{txIds:D,signedTxs:m}}return{txIds:await Promise.all(m.map(async K=>await this.connection.sendTransaction(K,{skipPreflight:N}))),signedTxs:m}}if(this.signAllTransactions){let K=await this.signAllTransactions(m.slice(B,m.length)),D=[...m.slice(0,B),...K];if(g){let R=0,F=[],J=async()=>{if(!D[R])return;if(R<B){F.push({txId:"",status:"success",signedTx:D[R]}),b==null||b([...F]),R++,J();return}let re=await this.connection.sendTransaction(D[R],{skipPreflight:N});F.push({txId:re,status:"sent",signedTx:D[R]}),b==null||b([...F]),R++,this.connection.onSignature(re,V=>{let _=F.findIndex(Mn=>Mn.txId===re);_>-1&&(F[_].status=V.err?"error":"success"),b==null||b([...F]),V.err||J()},"processed"),this.connection.getSignatureStatus(re)};return J(),{txIds:[],signedTxs:D}}else{let R=[];for(let F=0;F<D.length;F+=1){let J=await this.connection.sendTransaction(D[F],{skipPreflight:N});R.push(J)}return{txIds:R,signedTxs:D}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}};import{AccountLayout as xe,createAssociatedTokenAccountInstruction as Ot,TOKEN_PROGRAM_ID as pe,TOKEN_2022_PROGRAM_ID as Io}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=H(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 Po,SystemProgram as Ao}from"@solana/web3.js";import ko from"bn.js";import{createCloseAccountInstruction as Bo,createInitializeAccountInstruction as Co,createTransferInstruction as Lo,TOKEN_PROGRAM_ID as we}from"@solana/spl-token";import{Keypair as yo,PublicKey as _n}from"@solana/web3.js";import wo from"bn.js";import{TOKEN_PROGRAM_ID as xo}from"@solana/spl-token";function co(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function kt(e,...t){if(!co(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 Bt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Pn(e,t){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),Q=(e,t)=>e<<32-t|e>>>t;var Mc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function uo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ct(e){return typeof e=="string"&&(e=uo(e)),kt(e),e}var et=class{clone(){return this._cloneInto()}},Dc={}.toString;function An(e){let t=r=>e().update(Ct(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function lo(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),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}var kn=(e,t,n)=>e&t^~e&n,Bn=(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){Bt(this);let{view:n,buffer:r,blockLen:o}=this;t=Ct(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=tt(t);for(;o<=i-s;s+=o)this.process(c,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){Bt(this),Pn(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;lo(r,o-8,BigInt(this.length*8),i),this.process(r,0);let a=tt(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;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 fo=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:c}=this;return[t,n,r,o,i,s,a,c]}set(t,n,r,o,i,s,a,c){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=c|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],y=Q(p,7)^Q(p,18)^p>>>3,h=Q(m,17)^Q(m,19)^m>>>10;fe[f]=h+fe[f-7]+y+fe[f-16]|0}let{A:r,B:o,C:i,D:s,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let p=Q(a,6)^Q(a,11)^Q(a,25),m=l+p+kn(a,c,u)+fo[f]+fe[f]|0,h=(Q(r,2)^Q(r,13)^Q(r,22))+Bn(r,o,i)|0;l=u,u=c,c=a,a=s+m|0,s=i,i=o,o=r,r=m+h|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,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,o,i,s,a,c,u,l)}roundClean(){fe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Cn=An(()=>new Lt);import{PublicKey as bo}from"@solana/web3.js";import Sn,{isBN as qu}from"bn.js";import{bits as Gc,BitStructure as Hc,blob as po,Blob as jc,cstr as zc,f32 as Zc,f32be as Yc,f64 as Xc,f64be as Qc,greedy as Jc,Layout as mo,ns64 as $c,ns64be as eu,nu64 as tu,nu64be as nu,offset as ru,s16 as ou,s16be as iu,s24 as su,s24be as au,s32 as cu,s32be as uu,s40 as lu,s40be as fu,s48 as pu,s48be as mu,s8 as du,seq as hu,struct as gu,Structure as ho,u16 as bu,u16be as yu,u24 as wu,u24be as xu,u32 as Tu,u32be as Pu,u40 as Au,u40be as ku,u48 as Bu,u48be as Cu,u8 as Lu,UInt as go,union as Su,Union as Iu,unionLayoutDiscriminator as Nu,utf8 as _u}from"@solana/buffer-layout";var St=mo,Ln=ho;var It=go;var Nt=po;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 Sn(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 Sn(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function In(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 bo(t),t=>t.toBuffer(),e)}var Rt=class extends Ln{decode(t,n){return super.decode(t,n)}};function Nn(e,t,n){return new Rt(e,t,n)}var Me=Nn([Re("mint"),Re("owner"),ot("amount"),rt("delegateOption"),Re("delegate"),In("state"),rt("isNativeOption"),ot("isNative"),ot("delegatedAmount"),rt("closeAuthorityOption"),Re("closeAuthority")]);var ol=H("Raydium_Util");function En({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:c,amount:u}=a;r.push({publicKey:i,mint:c,amount:u,isAssociated:Xe(e,c,s.owner).publicKey.equals(i),isNative:!1,programId:s.owner}),o.push({pubkey:i,accountInfo:a,programId:s.owner})}return t&&r.push({mint:_n.default,amount:new wo(String(t.lamports)),isNative:!0,programId:t.owner}),{tokenAccounts:r,tokenAccountRawInfos:o}}function it({fromPublicKey:e,programId:t=xo,assignSeed:n}){let r=n?btoa(n).slice(0,32):yo.generate().publicKey.toBase58().slice(0,32);return{publicKey:To(e,r,t),seed:r}}function To(e,t,n){let r=Buffer.concat([e.toBuffer(),Buffer.from(t),n.toBuffer()]),o=Cn(r);return new _n(o)}function Mt(e){let{mint:t,tokenAccount:n,owner:r,programId:o=we}=e;return Co(n,t,r,o)}function De(e){let{tokenAccount:t,payer:n,multiSigners:r=[],owner:o,programId:i=we}=e;return Bo(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),c=X(n).add(new ko(a)),u=it({fromPublicKey:o,programId:we});return{addresses:{newAccount:u.publicKey},signers:[],instructions:[Ao.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:u.seed,newAccountPubkey:u.publicKey,lamports:c.toNumber(),space:Me.span,programId:we}),Mt({mint:new Po(te.address),tokenAccount:u.publicKey,owner:i,programId:we})],instructionTypes:[U.CreateAccount,U.InitAccount],endInstructionTypes:s?[]:[U.CloseAccount],endInstructions:s?[]:[De({tokenAccount:u.publicKey,payer:o,owner:i})]}}function Rn({source:e,destination:t,owner:n,amount:r,multiSigners:o=[],tokenProgram:i=we}){return Lo(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._accountFetchTime=0;let{tokenAccounts:r,tokenAccountRawInfos:o}=n;this._tokenAccounts=r||[],this._tokenAccountRawInfos=o||[],this._clientOwnedToken=!!(r||o)}get tokenAccounts(){return this._tokenAccounts}get tokenAccountRawInfos(){return this._tokenAccountRawInfos}updateTokenAccount({tokenAccounts:n,tokenAccountRawInfos:r}){return n&&(this._tokenAccounts=n),r&&(this._tokenAccountRawInfos=r),this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=void 0,this._clientOwnedToken=!0,this}addAccountChangeListener(n){return this._accountListener.push(n),this}removeAccountChangeListener(n){return this._accountListener=this._accountListener.filter(r=>r!==n),this}getAssociatedTokenAccount(n,r){return 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<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:Io},o.commitment)]),{tokenAccounts:c,tokenAccountRawInfos:u}=En({owner:this.scope.ownerPubKey,solAccountResp:i,tokenAccountResp:{context:s.context,value:[...s.value,...a.value]}});return this._tokenAccounts=c,this._tokenAccountRawInfos=u,this._accountFetchTime=Date.now(),this._accountChangeListenerId&&this.scope.connection.removeAccountChangeListener(this._accountChangeListenerId),this._accountChangeListenerId=this.scope.connection.onAccountChange(this.scope.ownerPubKey,()=>this.fetchWalletTokenAccounts({forceUpdate:!0}),n==null?void 0:n.commitment),{tokenAccounts:c,tokenAccountRawInfos:u}}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,c)=>a.amount.lt(c.amount)?1:-1),s=this.getAssociatedTokenAccount(n,r);for(let a of i){let{publicKey:c}=a;if(c&&(!o||o&&s.equals(c)))return c}}async getOrCreateTokenAccount(n){var y,h,x,T;await this.fetchWalletTokenAccounts();let{mint:r,createInfo:o,associatedOnly:i,owner:s,notUseTokenAccount:a=!1,skipCloseAccount:c=!1,checkCreateATAOwner:u=!1}=n,l=new st(n.tokenProgram||pe),f=this.getAssociatedTokenAccount(r,new st(l)),p=(a?[]:this.tokenAccountRawInfos).filter(w=>w.accountInfo.mint.equals(r)&&(!i||w.pubkey.equals(f))).sort((w,g)=>w.accountInfo.amount.lt(g.accountInfo.amount)?1:-1);if(o===void 0||p.length>0)return p.length>0?{account:p[0].pubkey}:{};let m={instructions:[],endInstructions:[],signers:[],instructionTypes:[],endInstructionTypes:[]};if(i){let w=Ot(s,f,s,r,l);if(u){let g=await this.scope.connection.getAccountInfo(f);if(g===null)(y=m.instructions)==null||y.push(w),m.instructionTypes.push(U.CreateATA);else if(!(g.owner.equals(l)&&xe.decode(g.data).mint.equals(r)&&xe.decode(g.data).owner.equals(s)))throw Error(`create ata check error -> mint: ${r.toString()}, ata: ${f.toString()}`)}else m.instructions.push(w),m.instructionTypes.push(U.CreateATA);if(r.equals(ie)&&o.amount){let g=await Dt({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:o.payer||this.scope.ownerPubKey,amount:(h=o.amount)!=null?h:0,skipCloseAccount:c});m.instructions.push(...g.instructions||[]),m.endInstructions.push(...g.endInstructions||[]),m.instructionTypes.push(...g.instructionTypes||[]),m.endInstructionTypes.push(...g.endInstructionTypes||[]),o.amount&&(m.instructions.push(Rn({source:g.addresses.newAccount,destination:f,owner:this.scope.ownerPubKey,amount:o.amount,tokenProgram:pe})),m.instructionTypes.push(U.TransferAmount))}return c||(m.endInstructions.push(De({owner:s,payer:o.payer||s,tokenAccount:f,programId:l})),m.endInstructionTypes.push(U.CloseAccount)),{account:f,instructionParams:m}}else{let w=it({fromPublicKey:s,programId:l}),g=await this.scope.connection.getMinimumBalanceForRentExemption(xe.span),b=So.createAccountWithSeed({fromPubkey:s,basePubkey:s,seed:w.seed,newAccountPubkey:w.publicKey,lamports:g+Number((T=(x=o.amount)==null?void 0:x.toString())!=null?T:0),space:xe.span,programId:l});return m.instructions.push(b,Mt({mint:r,tokenAccount:w.publicKey,owner:this.scope.ownerPubKey,programId:l})),m.instructionTypes.push(U.CreateAccount),m.instructionTypes.push(U.InitAccount),c||(m.endInstructions.push(De({owner:s,payer:o.payer||s,tokenAccount:w.publicKey,programId:l})),m.endInstructionTypes.push(U.CloseAccount)),{account:w.publicKey,instructionParams:m}}}async checkOrCreateAta({mint:n,programId:r=pe,autoUnwrapWSOLToSOL:o}){var c;await this.fetchWalletTokenAccounts();let i=(c=this.scope.account.tokenAccounts.find(({mint:u})=>(u==null?void 0:u.toBase58())===n.toBase58()))==null?void 0:c.publicKey,s=this.scope.ownerPubKey,a={};if(!i){let u=this.getAssociatedTokenAccount(n,r),l=await Ot(s,u,s,n,r);a.instructions=[l],a.instructionTypes=[U.CreateATA],i=u}return o&&ie.toBase58()===n.toBase58()&&(a.endInstructions=[De({owner:s,payer:s,tokenAccount:i,programId:r})],a.endInstructionTypes=[U.CloseAccount]),{pubKey:i,newInstructions:a}}async handleTokenAccount(n){let{side:r,amount:o,mint:i,programId:s=pe,tokenAccount:a,payer:c=this.scope.ownerPubKey,bypassAssociatedCheck:u,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:c,amount:o,skipCloseAccount:l});return v({tokenAccount:m.addresses.newAccount},m)}else if(!a||r==="out"&&!p.equals(a)&&!u){let m=[],y=Ot(this.scope.ownerPubKey,p,this.scope.ownerPubKey,i,s);if(f){let h=await this.scope.connection.getAccountInfo(p);if(h===null)m.push(y);else if(!(h.owner.equals(pe)&&xe.decode(h.data).mint.equals(i)&&xe.decode(h.data).owner.equals(this.scope.ownerPubKey)))throw Error(`create ata check error -> mint: ${i.toString()}, ata: ${p.toString()}`)}else m.push(y);return{tokenAccount:p,instructions:m,instructionTypes:[U.CreateATA]}}return{tokenAccount:a}}async processTokenAccount(n){let{mint:r,programId:o=pe,amount:i,useSOLBalance:s,handleTokenAccount:a}=n,c,u=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"]);c=p,u.addInstruction(m)}else if(c=await this.getCreatedTokenAccount({mint:r,associatedOnly:!1,programId:o}),!c&&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"]);c=p,u.addInstruction(m)}return v({tokenAccount:c},u.AllTxData)}};export{Kt as default};
|
|
1
|
+
var Dn=Object.defineProperty,On=Object.defineProperties;var Kn=Object.getOwnPropertyDescriptors;var Oe=Object.getOwnPropertySymbols;var Ft=Object.prototype.hasOwnProperty,Vt=Object.prototype.propertyIsEnumerable;var vt=(e,t,n)=>t in e?Dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,v=(e,t)=>{for(var n in t||(t={}))Ft.call(t,n)&&vt(e,n,t[n]);if(Oe)for(var n of Oe(t))Vt.call(t,n)&&vt(e,n,t[n]);return e},oe=(e,t)=>On(e,Kn(t));var me=(e,t)=>{var n={};for(var r in e)Ft.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&&Vt.call(e,r)&&(n[r]=e[r]);return n};import{PublicKey as st,SystemProgram as Lo}from"@solana/web3.js";import{PublicKey as Vn}from"@solana/web3.js";import{get as Wt,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}},Ut={},Fn={};function H(e){let t=Wt(Ut,e);if(!t){let n=Wt(Fn,e);t=new at({name:e,logLevel:n}),vn(Ut,e,t)}return t}import{MINT_SIZE as Vo,TOKEN_PROGRAM_ID as Wo,getTransferFeeConfig as Uo,unpackMint as qo}from"@solana/spl-token";var ct=H("Raydium_accountInfo_util");async function qt(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 c=s.map(f=>{let p=e._buildArgs([f.map(m=>m.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:p}}),u=ut(c,10);a=(await(await Promise.all(u.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:y,lamports:h,owner:x,rentEpoch:T}=p;return m.length!==2&&m[1]!=="base64"&&ct.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(m[0],"base64"),executable:y,lamports:h,owner:new Vn(x),rentEpoch:T}}return null})))}else try{a=await Promise.all(s.map(c=>e.getMultipleAccountsInfo(c,o)))}catch(c){c instanceof Error&&ct.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}import ne 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},zt,ee,C=!0,We="[DecimalError] ",ce=We+"Invalid argument: ",Zt=We+"Precision limit exceeded",Yt=We+"crypto unavailable",Xt="[object Decimal]",j=Math.floor,W=Math.pow,Wn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Un=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,qn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Qt=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Y=1e7,k=7,Gn=9007199254740991,Hn=ve.length-1,pt=Fe.length-1,d={toStringTag:Xt};d.absoluteValue=d.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),P(e)};d.ceil=function(){return P(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,c=i.s,u=e.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(i.e!==e.e)return i.e>e.e^c<0?1:-1;for(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]^c<0?1:-1;return r===o?0:r>o^c<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())+k,r.rounding=1,n=jn(r,nn(r,n)),r.precision=e,r.rounding=t,P(ee==2||ee==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,c,u,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(C=!1,i=l.s*W(l.s*l,1/3),!i||Math.abs(i)==1/0?(n=G(l.d),e=l.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=W(n,1/3),e=j((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,c=a.times(a).times(a),u=c.plus(l),r=E(u.plus(l).times(a),u.plus(c),s+2,1),G(a.d).slice(0,s)===(n=G(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(P(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")&&(P(r,e+1,1),t=!r.times(r).times(r).eq(l));break}return C=!0,P(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-j(this.e/k))*k,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};d.dividedBy=d.div=function(e){return E(this,new this.constructor(e))};d.dividedToIntegerBy=d.divToInt=function(e){var t=this,n=t.constructor;return P(E(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 P(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 c,u=e,l=new s(8);u--;)c=i.times(i),i=a.minus(c.times(l.minus(c.times(l))));return P(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),c=new i(16),u=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(c.times(s).plus(u))))}return i.precision=t,i.rounding=n,P(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,E(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()?Z(n,o,i):new n(0):new n(NaN):t.isZero()?Z(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=Z(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,C=!1,n=n.times(n).minus(1).sqrt().plus(n),C=!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,C=!1,n=n.times(n).plus(1).sqrt().plus(n),C=!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?P(new i(o),e,t,!0):(i.precision=n=r-o.e,o=E(o.plus(1),new i(1).minus(o),n+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};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=Z(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,c,u=this,l=u.constructor,f=l.precision,p=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&f+4<=pt)return s=Z(l,f+4,p).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(f+4<=pt)return s=Z(l,f+4,p).times(.5),s.s=u.s,s}for(l.precision=a=f+10,l.rounding=1,n=Math.min(28,a/k+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(C=!1,t=Math.ceil(a/k),r=1,c=u.times(u),s=new l(u),o=u;e!==-1;)if(o=o.times(c),i=s.minus(o.div(r+=2)),o=o.times(c),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)),C=!0,P(s,l.precision=f,l.rounding=p,!0)};d.isFinite=function(){return!!this.d};d.isInteger=d.isInt=function(){return!!this.d&&j(this.e/k)>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,c,u=this,l=u.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=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.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(C=!1,a=f+m,s=ae(u,a),r=t?Ve(l,a+10):ae(e,a),c=E(s,r,a,1),Te(c.d,o=f,p))do if(a+=10,s=ae(u,a),r=t?Ve(l,a+10):ae(e,a),c=E(s,r,a,1),!i){+G(c.d).slice(o+1,o+15)+1==1e14&&(c=P(c,f+1,0));break}while(Te(c.d,o+=10,p));return C=!0,P(c,f,p)};d.minus=d.sub=function(e){var t,n,r,o,i,s,a,c,u,l,f,p,m=this,y=m.constructor;if(e=new y(e),!m.d||!e.d)return!m.s||!e.s?e=new y(NaN):m.d?e.s=-e.s:e=new y(e.d||m.s!==e.s?m:NaN),e;if(m.s!=e.s)return e.s=-e.s,m.plus(e);if(u=m.d,p=e.d,a=y.precision,c=y.rounding,!u[0]||!p[0]){if(p[0])e.s=-e.s;else if(u[0])e=new y(m);else return new y(c===3?-0:0);return C?P(e,a,c):e}if(n=j(e.e/k),l=j(m.e/k),u=u.slice(),i=l-n,i){for(f=i<0,f?(t=u,i=-i,s=p.length):(t=p,n=l,s=u.length),r=Math.max(Math.ceil(a/k),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=u.length,s=p.length,f=r<s,f&&(s=r),r=0;r<s;r++)if(u[r]!=p[r]){f=u[r]<p[r];break}i=0}for(f&&(t=u,u=p,p=t,e.s=-e.s),s=u.length,r=p.length-s;r>0;--r)u[s++]=0;for(r=p.length;r>i;){if(u[--r]<p[r]){for(o=r;o&&u[--o]===0;)u[o]=Y-1;--u[o],u[r]+=Y}u[r]-=p[r]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=Ue(u,n),C?P(e,a,c):e):new y(c===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]?P(new r(n),r.precision,r.rounding):(C=!1,r.modulo==9?(t=E(n,e.abs(),0,3,1),t.s*=e.s):t=E(n,e,0,r.modulo,1),t=t.times(e),C=!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,P(e)};d.plus=d.add=function(e){var t,n,r,o,i,s,a,c,u,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(u=f.d,l=e.d,a=p.precision,c=p.rounding,!u[0]||!l[0])return l[0]||(e=new p(f)),C?P(e,a,c):e;if(i=j(f.e/k),r=j(e.e/k),u=u.slice(),o=i-r,o){for(o<0?(n=u,o=-o,s=l.length):(n=l,r=i,s=u.length),i=Math.ceil(a/k),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=u.length,o=l.length,s-o<0&&(o=s,n=l,l=u,u=n),t=0;o;)t=(u[--o]=u[o]+l[o]+t)/Y|0,u[o]%=Y;for(t&&(u.unshift(t),++r),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=Ue(u,r),C?P(e,a,c):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=Jt(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};d.round=function(){var e=this,t=e.constructor;return P(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())+k,r.rounding=1,n=Zn(r,nn(r,n)),r.precision=e,r.rounding=t,P(ee>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,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(C=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=G(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=j((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),r=new l(t)):r=new l(u.toString()),n=(c=l.precision)+3;;)if(i=r,r=i.plus(E(s,i,n+2,1)).times(.5),G(i.d).slice(0,n)===(t=G(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(P(i,c+1,0),i.times(i).eq(s))){r=i;break}n+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(P(r,c+1,1),e=!r.times(r).eq(s));break}return C=!0,P(r,c,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=E(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,P(ee==2||ee==4?n.neg():n,e,t,!0)):new r(NaN)};d.times=d.mul=function(e){var t,n,r,o,i,s,a,c,u,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=j(l.e/k)+j(e.e/k),c=p.length,u=m.length,c<u&&(i=p,p=m,m=i,s=c,c=u,u=s),i=[],s=c+u,r=s;r--;)i.push(0);for(r=u;--r>=0;){for(t=0,o=c+r;o>r;)a=i[o]+m[r]*p[o-r-1]+t,i[o--]=a%Y|0,t=a/Y|0;i[o]=(i[o]+t)%Y|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=Ue(i,n),C?P(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:(z(e,0,ue),t===void 0?t=r.rounding:z(t,0,8),P(n,e+n.e+1,t))};d.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=$(r,!0):(z(e,0,ue),t===void 0?t=o.rounding:z(t,0,8),r=P(new o(r),e+1,t),n=$(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=$(o):(z(e,0,ue),t===void 0?t=i.rounding:z(t,0,8),r=P(new i(o),e+o.e+1,t),n=$(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};d.toFraction=function(e){var t,n,r,o,i,s,a,c,u,l,f,p,m=this,y=m.d,h=m.constructor;if(!y)return new h(m);if(u=n=new h(1),r=c=new h(0),t=new h(r),i=t.e=Jt(y)-m.e-1,s=i%k,t.d[0]=W(10,s<0?k+s:s),e==null)e=i>0?t:u;else{if(a=new h(e),!a.isInt()||a.lt(u))throw Error(ce+a);e=a.gt(t)?i>0?t:u:a}for(C=!1,a=new h(G(y)),l=h.precision,h.precision=i=y.length*k*2;f=E(a,t,0,1,1),o=n.plus(f.times(r)),o.cmp(e)!=1;)n=r,r=o,o=u,u=c.plus(f.times(o)),c=o,o=t,t=a.minus(f.times(o)),a=o;return o=E(e.minus(n),r,0,1,1),c=c.plus(o.times(u)),n=n.plus(o.times(r)),c.s=u.s=m.s,p=E(u,r,i,1).minus(m).abs().cmp(E(c,n,i,1).minus(m).abs())<1?[u,r]:[c,n],h.precision=l,C=!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:z(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]?(C=!1,n=E(n,e,0,t,1).times(e),C=!0,P(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,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(W(+a,u));if(a=new c(a),a.eq(1))return a;if(r=c.precision,i=c.rounding,e.eq(1))return P(a,r,i);if(t=j(e.e/k),t>=e.d.length-1&&(n=u<0?-u:u)<=Gn)return o=$t(c,a,n,r),e.s<0?new c(1).div(o):P(o,r,i);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=W(+a,u),t=n==0||!isFinite(n)?j(u*(Math.log("0."+G(a.d))/Math.LN10+a.e+1)):new c(n+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(C=!1,c.rounding=a.s=1,n=Math.min(12,(t+"").length),o=mt(e.times(ae(a,r+n)),r),o.d&&(o=P(o,r+5,1),Te(o.d,r,i)&&(t=r+10,o=P(mt(e.times(ae(a,t+n)),t),t+5,1),+G(o.d).slice(r+1,r+15)+1==1e14&&(o=P(o,r+1,0)))),o.s=s,C=!0,c.rounding=i,P(o,r,i))};d.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=$(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(z(e,1,ue),t===void 0?t=o.rounding:z(t,0,8),r=P(new o(r),e,t),n=$(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):(z(e,1,ue),t===void 0?t=r.rounding:z(t,0,8)),P(new r(n),e,t)};d.toString=function(){var e=this,t=e.constructor,n=$(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};d.truncated=d.trunc=function(){return P(new this.constructor(this),this.e+1,1)};d.valueOf=d.toJSON=function(){var e=this,t=e.constructor,n=$(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function G(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=k-r.length,n&&(i+=se(n)),i+=r;s=e[t],r=s+"",n=k-r.length,n&&(i+=se(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function z(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+=k,o=0):(o=Math.ceil((t+1)/k),t%=k),i=W(10,k-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)==W(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)==W(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 jn(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 E=function(){function e(r,o,i){var s,a=0,c=r.length;for(r=r.slice();c--;)s=r[c]*o+a,r[c]=s%i|0,a=s/i|0;return a&&r.unshift(a),r}function t(r,o,i,s){var a,c;if(i!=s)c=i>s?1:-1;else for(a=c=0;a<i;a++)if(r[a]!=o[a]){c=r[a]>o[a]?1:-1;break}return c}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,c){var u,l,f,p,m,y,h,x,T,w,g,b,B,A,N,q,K,D,R,F,J=r.constructor,re=r.s==o.s?1:-1,V=r.d,_=o.d;if(!V||!V[0]||!_||!_[0])return new J(!r.s||!o.s||(V?_&&V[0]==_[0]:!_)?NaN:V&&V[0]==0||!_?re*0:re/0);for(c?(m=1,l=r.e-o.e):(c=Y,m=k,l=j(r.e/m)-j(o.e/m)),R=_.length,K=V.length,T=new J(re),w=T.d=[],f=0;_[f]==(V[f]||0);f++);if(_[f]>(V[f]||0)&&l--,i==null?(A=i=J.precision,s=J.rounding):a?A=i+(r.e-o.e)+1:A=i,A<0)w.push(1),y=!0;else{if(A=A/m+2|0,f=0,R==1){for(p=0,_=_[0],A++;(f<K||p)&&A--;f++)N=p*c+(V[f]||0),w[f]=N/_|0,p=N%_|0;y=p||f<K}else{for(p=c/(_[0]+1)|0,p>1&&(_=e(_,p,c),V=e(V,p,c),R=_.length,K=V.length),q=R,g=V.slice(0,R),b=g.length;b<R;)g[b++]=0;F=_.slice(),F.unshift(0),D=_[0],_[1]>=c/2&&++D;do p=0,u=t(_,g,R,b),u<0?(B=g[0],R!=b&&(B=B*c+(g[1]||0)),p=B/D|0,p>1?(p>=c&&(p=c-1),h=e(_,p,c),x=h.length,b=g.length,u=t(h,g,x,b),u==1&&(p--,n(h,R<x?F:_,x,c))):(p==0&&(u=p=1),h=_.slice()),x=h.length,x<b&&h.unshift(0),n(g,h,b,c),u==-1&&(b=g.length,u=t(_,g,R,b),u<1&&(p++,n(g,R<b?F:_,b,c))),b=g.length):u===0&&(p++,g=[0]),w[f++]=p,u&&g[0]?g[b++]=V[q]||0:(g=[V[q]],b=1);while((q++<K||g[0]!==void 0)&&A--);y=g[0]!==void 0}w[0]||w.shift()}if(m==1)T.e=l,zt=y;else{for(f=1,p=w[0];p>=10;p/=10)f++;T.e=f+l*m-1,P(T,a?i+T.e+1:i,s,y)}return T}}();function P(e,t,n,r){var o,i,s,a,c,u,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+=k,s=t,l=f[p=0],c=l/W(10,o-s-1)%10|0;else if(p=Math.ceil((i+1)/k),a=f.length,p>=a)if(r){for(;a++<=p;)f.push(0);l=c=0,o=1,i%=k,s=i-k+1}else break e;else{for(l=a=f[p],o=1;a>=10;a/=10)o++;i%=k,s=i-k+o,c=s<0?0:l/W(10,o-s-1)%10|0}if(r=r||t<0||f[p+1]!==void 0||(s<0?l:l%W(10,o-s-1)),u=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(i>0?s>0?l/W(10,o-s):0:f[p-1])%10&1||n==(e.s<0?8:7)),t<1||!f[0])return f.length=0,u?(t-=e.e+1,f[0]=W(10,(k-t%k)%k),e.e=-t||0):f[0]=e.e=0,e;if(i==0?(f.length=p,a=1,p--):(f.length=p+1,a=W(10,k-i),f[p]=s>0?(l/W(10,o-s)%W(10,s)|0)*a:0),u)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]==Y&&(f[0]=1));break}else{if(f[p]+=a,f[p]!=Y)break;f[p--]=0,a=1}for(i=f.length;f[--i]===0;)f.pop()}return C&&(e.e>m.maxE?(e.d=null,e.e=NaN):e.e<m.minE&&(e.e=0,e.d=[0])),e}function $(e,t,n){if(!e.isFinite())return tn(e);var r,o=e.e,i=G(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*=k;n>=10;n/=10)t++;return t}function Ve(e,t,n){if(t>Hn)throw C=!0,n&&(e.precision=n),Error(Zt);return P(new e(ve),t,1,!0)}function Z(e,t,n){if(t>pt)throw Error(Zt);return P(new e(Fe),t,n,!0)}function Jt(e){var t=e.length-1,n=t*k+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 $t(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/k+4);for(C=!1;;){if(n%2&&(i=i.times(t),Ht(i.d,s)&&(o=!0)),n=j(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),Ht(t.d,s)}return C=!0,i}function Gt(e){return e.d[e.d.length-1]&1}function en(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,c,u=0,l=0,f=0,p=e.constructor,m=p.rounding,y=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?(C=!1,c=y):c=t,a=new p(.03125);e.e>-2;)e=e.times(a),f+=5;for(r=Math.log(W(2,f))/Math.LN10*2+5|0,c+=r,n=i=s=new p(1),p.precision=c;;){if(i=P(i.times(e),c,1),n=n.times(++l),a=s.plus(E(i,n,c,1)),G(a.d).slice(0,c)===G(s.d).slice(0,c)){for(o=f;o--;)s=P(s.times(s),c,1);if(t==null)if(u<3&&Te(s.d,c-r,m,u))p.precision=c+=10,n=i=a=new p(1),l=0,u++;else return P(s,p.precision=y,m,C=!0);else return p.precision=y,s}s=a}}function ae(e,t){var n,r,o,i,s,a,c,u,l,f,p,m=1,y=10,h=e,x=h.d,T=h.constructor,w=T.rounding,g=T.precision;if(h.s<0||!x||!x[0]||!h.e&&x[0]==1&&x.length==1)return new T(x&&!x[0]?-1/0:h.s!=1?NaN:x?0:h);if(t==null?(C=!1,l=g):l=t,T.precision=l+=y,n=G(x),r=n.charAt(0),Math.abs(i=h.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)h=h.times(e),n=G(h.d),r=n.charAt(0),m++;i=h.e,r>1?(h=new T("0."+n),i++):h=new T(r+"."+n.slice(1))}else return u=Ve(T,l+2,g).times(i+""),h=ae(new T(r+"."+n.slice(1)),l-y).plus(u),T.precision=g,t==null?P(h,g,w,C=!0):h;for(f=h,c=s=h=E(h.minus(1),h.plus(1),l,1),p=P(h.times(h),l,1),o=3;;){if(s=P(s.times(p),l,1),u=c.plus(E(s,new T(o),l,1)),G(u.d).slice(0,l)===G(c.d).slice(0,l))if(c=c.times(2),i!==0&&(c=c.plus(Ve(T,l+2,g).times(i+""))),c=E(c,new T(m),l,1),t==null)if(Te(c.d,l-y,w,a))T.precision=l+=y,u=s=h=E(f.minus(1),f.plus(1),l,1),p=P(h.times(h),l,1),o=a=1;else return P(c,T.precision=g,w,C=!0);else return T.precision=g,c;c=u,o+=2}}function tn(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)%k,n<0&&(r+=k),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=k;r<o;)e.d.push(+t.slice(r,r+=k));t=t.slice(r),r=k-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),C&&(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 zn(e,t){var n,r,o,i,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Qt.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(Un.test(t))n=16,t=t.toLowerCase();else if(Wn.test(t))n=2;else if(qn.test(t))n=8;else throw Error(ce+t);for(i=t.search(/p/i),i>0?(c=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=$t(r,new r(n),i,i*2)),u=Ke(t,n,Y),l=u.length-1,i=l;u[i]===0;--i)u.pop();return i<0?new r(e.s*0):(e.e=Ue(u,l),e.d=u,C=!1,s&&(e=E(e,o,a*4)),c&&(e=e.times(Math.abs(c)<54?W(2,c):Ge.pow(2,c))),C=!0,e)}function Zn(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,c,u=1,l=e.precision,f=Math.ceil(l/k);for(C=!1,c=n.times(n),a=new e(r);;){if(s=E(a.times(c),new e(t++*t++),l,1),a=o?r.plus(s):r.minus(s),r=E(s.times(c),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,u++}return C=!0,s.d.length=f+1,s}function qe(e,t){for(var n=e;--t;)n*=e;return n}function nn(e,t){var n,r=t.s<0,o=Z(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return ee=r?4:1,t;if(n=t.divToInt(o),n.isZero())ee=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return ee=Gt(n)?r?2:3:r?4:1,t;ee=Gt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function ht(e,t,n,r){var o,i,s,a,c,u,l,f,p,m=e.constructor,y=n!==void 0;if(y?(z(n,1,ue),r===void 0?r=m.rounding:z(r,0,8)):(n=m.precision,r=m.rounding),!e.isFinite())l=tn(e);else{for(l=$(e),s=l.indexOf("."),y?(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($(p),10,o),p.e=p.d.length),f=Ke(l,10,o),i=c=f.length;f[--c]==0;)f.pop();if(!f[0])l=y?"0p+0":"0";else{if(s<0?i--:(e=new m(e),e.d=f,e.e=i,e=E(e,p,n,r,0,o),f=e.d,i=e.e,u=zt),s=f[n],a=o/2,u=u||f[n+1]!==void 0,u=r<4?(s!==void 0||u)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||u||r===6&&f[n-1]&1||r===(e.s<0?8:7)),f.length=n,u)for(;++f[--n]>o-1;)f[n]=0,n||(++i,f.unshift(1));for(c=f.length;!f[c-1];--c);for(s=0,l="";s<c;s++)l+=lt.charAt(f[s]);if(y){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(f=Ke(l,o,t),c=f.length;!f[c-1];--c);for(s=1,l="1.";s<c;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>c)for(i-=c;i--;)l+="0";else i<c&&(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 Ht(e,t){if(e.length>t)return e.length=t,!0}function Yn(e){return new this(e).abs()}function Xn(e){return new this(e).acos()}function Qn(e){return new this(e).acosh()}function Jn(e,t){return new this(e).plus(t)}function $n(e){return new this(e).asin()}function er(e){return new this(e).asinh()}function tr(e){return new this(e).atan()}function nr(e){return new this(e).atanh()}function rr(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=Z(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?Z(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=Z(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(E(e,t,i,1)),t=Z(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(E(e,t,i,1)),n}function or(e){return new this(e).cbrt()}function ir(e){return P(e=new this(e),e.e+1,2)}function sr(e,t,n){return new this(e).clamp(t,n)}function ar(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(j(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(Yt);else this[n]=!1;else throw Error(ce+n+": "+r);return this}function cr(e){return new this(e).cos()}function ur(e){return new this(e).cosh()}function rn(e){var t,n,r;function o(i){var s,a,c,u=this;if(!(u instanceof o))return new o(i);if(u.constructor=o,jt(i)){u.s=i.s,C?!i.d||i.e>o.maxE?(u.e=NaN,u.d=null):i.e<o.minE?(u.e=0,u.d=[0]):(u.e=i.e,u.d=i.d.slice()):(u.e=i.e,u.d=i.d?i.d.slice():i.d);return}if(c=typeof i,c==="number"){if(i===0){u.s=1/i<0?-1:1,u.e=0,u.d=[0];return}if(i<0?(i=-i,u.s=-1):u.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;C?s>o.maxE?(u.e=NaN,u.d=null):s<o.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[i]):(u.e=s,u.d=[i]);return}else if(i*0!==0){i||(u.s=NaN),u.e=NaN,u.d=null;return}return dt(u,i.toString())}else if(c!=="string")throw Error(ce+i);return(a=i.charCodeAt(0))===45?(i=i.slice(1),u.s=-1):(a===43&&(i=i.slice(1)),u.s=1),Qt.test(i)?dt(u,i):zn(u,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=ar,o.clone=rn,o.isDecimal=jt,o.abs=Yn,o.acos=Xn,o.acosh=Qn,o.add=Jn,o.asin=$n,o.asinh=er,o.atan=tr,o.atanh=nr,o.atan2=rr,o.cbrt=or,o.ceil=ir,o.clamp=sr,o.cos=cr,o.cosh=ur,o.div=lr,o.exp=fr,o.floor=pr,o.hypot=mr,o.ln=dr,o.log=hr,o.log10=br,o.log2=gr,o.max=yr,o.min=wr,o.mod=xr,o.mul=Tr,o.pow=Pr,o.random=Ar,o.round=kr,o.sign=Br,o.sin=Cr,o.sinh=Sr,o.sqrt=Lr,o.sub=Ir,o.sum=Nr,o.tan=_r,o.tanh=Er,o.trunc=Rr,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 lr(e,t){return new this(e).div(t)}function fr(e){return new this(e).exp()}function pr(e){return P(e=new this(e),e.e+1,3)}function mr(){var e,t,n=new this(0);for(C=!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 C=!0,new this(1/0);n=t}return C=!0,n.sqrt()}function jt(e){return e instanceof Ge||e&&e.toStringTag===Xt||!1}function dr(e){return new this(e).ln()}function hr(e,t){return new this(e).log(t)}function gr(e){return new this(e).log(2)}function br(e){return new this(e).log(10)}function yr(){return en(this,arguments,"lt")}function wr(){return en(this,arguments,"gt")}function xr(e,t){return new this(e).mod(t)}function Tr(e,t){return new this(e).mul(t)}function Pr(e,t){return new this(e).pow(t)}function Ar(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:z(e,1,ue),r=Math.ceil(e/k),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(Yt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=k,r&&e&&(o=W(10,k-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-=k)a.shift();for(r=1,o=a[0];o>=10;o/=10)r++;r<k&&(n-=k-r)}return s.e=n,s.d=a,s}function kr(e){return P(e=new this(e),e.e+1,this.rounding)}function Br(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function Cr(e){return new this(e).sin()}function Sr(e){return new this(e).sinh()}function Lr(e){return new this(e).sqrt()}function Ir(e,t){return new this(e).sub(t)}function Nr(){var e=0,t=arguments,n=new this(t[e]);for(C=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return C=!0,P(n,this.precision,this.rounding)}function _r(e){return new this(e).tan()}function Er(e){return new this(e).tanh()}function Rr(e){return P(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=rn(ft);ve=new Ge(ve);Fe=new Ge(Fe);import Wr from"big.js";import ci from"bn.js";import Mr from"toformat";var Dr=Mr,Pe=Dr;import je from"big.js";import Kr from"bn.js";import vr from"decimal.js-light";import Ae from"bn.js";var on=9007199254740991;function X(e){let t=H("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>=on||e<=-on)&&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=H("module/fraction"),gt=Pe(je),ke=Pe(vr),Fr={[0]:ke.ROUND_DOWN,[1]:ke.ROUND_HALF_UP,[2]:ke.ROUND_UP},Vr={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},M=class{constructor(t,n=new Kr(1)){this.numerator=X(t),this.denominator=X(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new M(this.denominator,this.numerator)}add(t){let n=t instanceof M?t:new M(X(t));return this.denominator.eq(n.denominator)?new M(this.numerator.add(n.numerator),this.denominator):new M(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof M?t:new M(X(t));return this.denominator.eq(n.denominator)?new M(this.numerator.sub(n.numerator),this.denominator):new M(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof M?t:new M(X(t));return new M(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof M?t:new M(X(t));return new M(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:Fr[r]});let o=new ke(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},r=1){return Number.isInteger(t)||He.logWithError(`${t} is not an integer.`),t<0&&He.logWithError(`${t} is negative.`),gt.DP=t,gt.RM=Vr[r]||1,new gt(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var bi=H("Raydium_amount"),yi=Pe(Wr);import{PublicKey as qr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as sn}from"@solana/spl-token";var an={chainId:101,address:qr.default.toBase58(),programId:sn.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img-v1.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},te={chainId:101,address:"So11111111111111111111111111111111111111112",programId:sn.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 O,SystemProgram as cn,SYSVAR_RENT_PUBKEY as Gr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Hr}from"@solana/spl-token";function bt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var Ci=[bt({pubkey:Hr,isWritable:!1}),bt({pubkey:cn.programId,isWritable:!1}),bt({pubkey:Gr,isWritable:!1})];function un({publicKey:e,transformSol:t}){let n=ln(e.toString());if(n instanceof O)return t&&n.equals(Be)?ie:n;if(t&&n.toString()===Be.toBase58())return ie;if(typeof n=="string"){if(n===O.default.toBase58())return O.default;try{return new O(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function ln(e){try{return new O(e)}catch{return e}}var Si=new O("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Li=new O("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Ii=new O("SysvarRent111111111111111111111111111111111"),Ni=new O("SysvarC1ock11111111111111111111111111111111"),_i=new O("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ei=new O("Sysvar1nstructions1111111111111111111111111"),Ri=cn.programId,Mi=new O("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),Di=new O("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Oi=new O("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ki=new O("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),vi=new O("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Fi=new O("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Vi=new O("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Wi=new O("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ui=new O("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),qi=new O("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Gi=new O("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),ie=new O("So11111111111111111111111111111111111111112"),Be=O.default;var wt=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Be.toBase58()||t instanceof yt&&Be.equals(t)){this.decimals=te.decimals,this.symbol=te.symbol,this.name=te.name,this.mint=new yt(te.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:un({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},be=wt;be.WSOL=new wt(oe(v({},te),{mint:te.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(an);import jr from"bn.js";var ns=new M(new jr(100));var cs=H("Raydium_price");import{PublicKey as Bs}from"@solana/web3.js";import Ss from"bn.js";var zr=new ne(0),js=new ne(1),zs=new ne(2),Zs=new ne(3),Ys=new ne(5),Ur=new ne(10),Xs=new ne(100),Qs=new ne(1e3),Js=new ne(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 eo}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as to}from"@solana/spl-token";import{ComputeBudgetProgram as dn,Keypair as gn,PublicKey as Zr,Transaction as bn,TransactionMessage as Yr,VersionedTransaction as yn}from"@solana/web3.js";var U={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 Xr}from"@solana/spl-token";var hn=H("Raydium_txUtil"),wn=1644;function Ze(e){let t=[],n=[];return e.microLamports&&(t.push(dn.setComputeUnitPrice({microLamports:e.microLamports})),n.push(U.SetComputeUnitPrice)),e.units&&(t.push(dn.setComputeUnitLimit({units:e.units})),n.push(U.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 Qr(e,t){e.length<1&&hn.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&hn.logWithError(`no signers provided:, ${t.toString()}`);let n=new bn;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<wn}catch{return!1}}function xn(e,t){let[n,r]=Zr.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}function Ce({instructions:e,payer:t,signers:n}){return Qr(e,[t,...n])}function Se({instructions:e,payer:t,lookupTableAddressAccount:n,recentBlockhash:r=gn.generate().publicKey.toString()}){let i=new Yr({payerKey:t,recentBlockhash:r,instructions:e}).compileToV0Message(Object.values(n!=null?n:{}));try{return Buffer.from(new yn(i).serialize()).toString("base64").length<wn}catch{return!1}}var Jr=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e),$r=e=>{let t=e.serialize({requireAllSignatures:!1,verifySignatures:!1});e instanceof yn&&(t=Jr(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 bn&&(n.recentBlockhash||(n.recentBlockhash=Xr.toBase58()),n.feePayer||(n.feePayer=gn.generate().publicKey)),t.push($r(n))}),console.log("simulate tx string:",t),t}function Xe(e,t,n){return xn([e.toBuffer(),(n!=null?n:to).toBuffer(),t.toBuffer()],new eo("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"))}import{PublicKey as S}from"@solana/web3.js";var wa=new S("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),xa=new S("CBuCnLe26faBpcBP2fktp4rp8abpcAnTWft6ZrP5Q4T"),Ta=new S("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Pa=new S("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Aa=new S("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),ka=new S("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Ba=new S("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Ca=new S("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),Sa=new S("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),La=new S("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Ia=new S("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),Na=new S("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),_a=new S("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Ea=new S("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Ra=new S("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Ma=new S("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Da=new S("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Oa=new S("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),Ka=new S("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),va=new S("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Fa=new S("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Va=new S("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),no=new S("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),ro=new S("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),oo=new S("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),Wa=new S("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),io=new S("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),Ua=new S("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),so=new S("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var qa={SERUM_MARKET:S.default,OPENBOOK_MARKET:new S("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:S.default,FarmV3:new S("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new S("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new S("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new S("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new S("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new S("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new S("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new S("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new S("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:no,CREATE_CPMM_POOL_AUTH:ro,CREATE_CPMM_POOL_FEE_ACC:oo,FEE_DESTINATION_ID:new S("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:io,LCOK_CPMM_AUTH:so};import ja from"bn.js";import{PublicKey as Tn,AddressLookupTableAccount as Qe}from"@solana/web3.js";async function Tt({connection:e,address:t}){let n=await qt(e,[...new Set(t.map(o=>o.toString()))].map(o=>new Tn(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 Tn("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 Le,sendAndConfirmTransaction as Pt,Transaction as Ie,TransactionMessage as Ne,VersionedTransaction as _e}from"@solana/web3.js";import ao 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 ao.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!==Le.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 u;let{recentBlockHash:i,skipPreflight:s=!0,sendAndConfirm:a}=o||{},c=i!=null?i:await ye(this.connection,this.blockhashCommitment);if(n.recentBlockhash=c,this.signers.length&&n.sign(...this.signers),de([n]),(u=this.owner)!=null&&u.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 u;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)],c=[...this.instructionTypes,...i.map(l=>l.instructionTypes).flat()];return(u=this.owner)!=null&&u.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:c,execute:async l=>{var T;let{sequentially:f,onTxUpdate:p,skipTxCount:m=0,recentBlockHash:y,skipPreflight:h=!0}=l||{},x=y!=null?y:await ye(this.connection,this.blockhashCommitment);if((T=this.owner)!=null&&T.isKeyPair){if(f){let w=[],g=0;for(let b of s){if(++g,g<=m)continue;let B=await Pt(this.connection,b,this.signers.find(A=>A.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:h});w.push(B)}return{txIds:w,signedTxs:s}}return{txIds:await await Promise.all(s.map(async w=>(w.recentBlockhash=x,await this.connection.sendRawTransaction(w.serialize(),{skipPreflight:h})))),signedTxs:s}}if(this.signAllTransactions){let w=s.map((b,B)=>(b.recentBlockhash=x,a[B].length&&b.sign(...a[B]),b));de(w);let g=await this.signAllTransactions(w);if(f){let b=0,B=[],A=async()=>{if(!g[b])return;let N=await this.connection.sendRawTransaction(g[b].serialize(),{skipPreflight:h});B.push({txId:N,status:"sent",signedTx:g[b]}),p==null||p([...B]),b++,this.connection.onSignature(N,q=>{let K=B.findIndex(D=>D.txId===N);K>-1&&(B[K].status=q.err?"error":"success"),p==null||p([...B]),q.err||A()},"processed"),this.connection.getSignatureStatus(N)};return await A(),{txIds:B.map(N=>N.txId),signedTxs:g}}else{let b=[];for(let B=0;B<g.length;B+=1){let A=await this.connection.sendRawTransaction(g[B].serialize(),{skipPreflight:h});b.push(A)}return{txIds:b,signedTxs:g}}}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 h;let y=t||{},{lookupTableCache:n={},lookupTableAddress:r=[],forerunCreate:o,recentBlockhash:i}=y,s=me(y,["lookupTableCache","lookupTableAddress","forerunCreate","recentBlockhash"]),a=v(v({},this.cluster==="devnet"?{}:Je),n),c=Array.from(new Set([...r,...this.lookupTableAddress])),u=[];for(let x of c)a[x]===void 0&&u.push(new Le(x));let l=await Tt({connection:this.connection,address:u});for(let[x,T]of Object.entries(l))a[x]=T;let f=o?Le.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));((h=this.owner)==null?void 0:h.signer)&&!this.signers.some(x=>x.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 x=>{var g;let{skipPreflight:T=!0,sendAndConfirm:w}=x||{};if(de([m]),(g=this.owner)!=null&&g.isKeyPair){let b=await this.connection.sendTransaction(m,{skipPreflight:T});return w&&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:T}),signedTx:b[0]}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:s||{}}}async buildV0MultiTx(t){var u;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)],c=[...this.instructionTypes,...i.map(l=>l.instructionTypes).flat()];return(u=this.owner)!=null&&u.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:c,buildProps:r,execute:async l=>{var h;let{sequentially:f,onTxUpdate:p,recentBlockHash:m,skipPreflight:y=!0}=l||{};if(m&&s.forEach(x=>x.message.recentBlockhash=m),de(s),(h=this.owner)!=null&&h.isKeyPair){if(f){let x=[];for(let T of s){let w=await this.connection.sendTransaction(T,{skipPreflight:y});await Ye(this.connection,w),x.push(w)}return{txIds:x,signedTxs:s}}return{txIds:await Promise.all(s.map(async x=>await this.connection.sendTransaction(x,{skipPreflight:y}))),signedTxs:s}}if(this.signAllTransactions){let x=await this.signAllTransactions(s);if(f){let T=0,w=[],g=async()=>{if(!x[T])return;let b=await this.connection.sendTransaction(x[T],{skipPreflight:y});w.push({txId:b,status:"sent",signedTx:x[T]}),p==null||p([...w]),T++,this.connection.onSignature(b,B=>{let A=w.findIndex(N=>N.txId===b);A>-1&&(w[A].status=B.err?"error":"success"),p==null||p([...w]),B.err||g()},"processed"),this.connection.getSignatureStatus(b)};return g(),{txIds:[],signedTxs:x}}else{let T=[];for(let w=0;w<x.length;w+=1){let g=await this.connection.sendTransaction(x[w],{skipPreflight:y});T.push(g)}return{txIds:T,signedTxs:x}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuild(t){var l;let u=t||{},{computeBudgetConfig:n}=u,r=me(u,["computeBudgetConfig"]),o=n?Ze(n):{instructions:[],instructionTypes:[]},i=this.signers.reduce((f,p)=>oe(v({},f),{[p.publicKey.toBase58()]:p}),{}),s=[],a=[],c=[];if(this.allInstructions.forEach(f=>{let p=[...c,f],m=n?[...o.instructions,...p]:p,h=[...new Set(p.map(x=>x.keys.filter(T=>T.isSigner).map(T=>T.pubkey.toString())).flat()).values()].map(x=>new Le(x));if(c.length<12&&Ce({instructions:m,payer:this.feePayer,signers:h})||Ce({instructions:p,payer:this.feePayer,signers:h}))c.push(f);else{if(c.length===0)throw Error("item ins too big");Ce({instructions:n?[...o.instructions,...c]:[...c],payer:this.feePayer,signers:h})?s.push(new Ie().add(...o.instructions,...c)):s.push(new Ie().add(...c)),a.push(Array.from(new Set(c.map(x=>x.keys.filter(T=>T.isSigner).map(T=>T.pubkey.toString())).flat())).map(x=>i[x]).filter(x=>x!==void 0)),c=[f]}}),c.length>0){let p=[...new Set(c.map(m=>m.keys.filter(y=>y.isSigner).map(y=>y.pubkey.toString())).flat()).values()].map(m=>i[m]).filter(m=>m!==void 0);Ce({instructions:n?[...o.instructions,...c]:[...c],payer:this.feePayer,signers:p.map(m=>m.publicKey)})?s.push(new Ie().add(...o.instructions,...c)):s.push(new Ie().add(...c)),a.push(p)}return s.forEach(f=>f.feePayer=this.feePayer),(l=this.owner)!=null&&l.signer&&a.forEach(f=>{f.some(p=>p.publicKey.equals(this.owner.publicKey))||f.push(this.owner.signer)}),{builder:this,transactions:s,signers:a,instructionTypes:this.instructionTypes,execute:async f=>{var w;let{sequentially:p,onTxUpdate:m,skipTxCount:y=0,recentBlockHash:h,skipPreflight:x=!0}=f||{},T=h!=null?h:await ye(this.connection,this.blockhashCommitment);if(s.forEach(async(g,b)=>{g.recentBlockhash=T,a[b].length&&g.sign(...a[b])}),de(s),(w=this.owner)!=null&&w.isKeyPair){if(p){let g=0,b=[];for(let B of s){if(++g,g<=y){b.push("tx skipped");continue}let A=await Pt(this.connection,B,this.signers.find(N=>N.publicKey.equals(this.owner.publicKey))?this.signers:[...this.signers,this.owner.signer],{skipPreflight:x});b.push(A)}return{txIds:b,signedTxs:s}}return{txIds:await Promise.all(s.map(async g=>await this.connection.sendRawTransaction(g.serialize(),{skipPreflight:x}))),signedTxs:s}}if(this.signAllTransactions){let g=await this.signAllTransactions(s.slice(y,s.length)),b=[...s.slice(0,y),...g];if(p){let B=0,A=[],N=async()=>{if(!b[B])return;B<y&&(A.push({txId:"",status:"success",signedTx:b[B]}),m==null||m([...A]),B++,N());let q=await this.connection.sendRawTransaction(b[B].serialize(),{skipPreflight:x});A.push({txId:q,status:"sent",signedTx:b[B]}),m==null||m([...A]),B++,this.connection.onSignature(q,K=>{let D=A.findIndex(R=>R.txId===q);D>-1&&(A[D].status=K.err?"error":"success"),m==null||m([...A]),K.err||N()},"processed"),this.connection.getSignatureStatus(q)};return await N(),{txIds:A.map(q=>q.txId),signedTxs:b}}else{let B=[];for(let A=0;A<b.length;A+=1){let N=await this.connection.sendRawTransaction(b[A].serialize(),{skipPreflight:x});B.push(N)}return{txIds:B,signedTxs:b}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:r||{}}}async sizeCheckBuildV0(t){var T;let x=t||{},{computeBudgetConfig:n,lookupTableCache:r={},lookupTableAddress:o=[]}=x,i=me(x,["computeBudgetConfig","lookupTableCache","lookupTableAddress"]),s=v(v({},this.cluster==="devnet"?{}:Je),r),a=Array.from(new Set([...this.lookupTableAddress,...o])),c=[];for(let w of a)s[w]===void 0&&c.push(new Le(w));let u=await Tt({connection:this.connection,address:c});for(let[w,g]of Object.entries(u))s[w]=g;let l=n?Ze(n):{instructions:[],instructionTypes:[]},f=await ye(this.connection,this.blockhashCommitment),p=this.signers.reduce((w,g)=>oe(v({},w),{[g.publicKey.toBase58()]:g}),{}),m=[],y=[],h=[];if(this.allInstructions.forEach(w=>{let g=[...h,w],b=n?[...l.instructions,...g]:g;if(h.length<12&&Se({instructions:b,payer:this.feePayer,lookupTableAddressAccount:s})||Se({instructions:g,payer:this.feePayer,lookupTableAddressAccount:s}))h.push(w);else{if(h.length===0)throw Error("item ins too big");let B={};for(let A of[...new Set(a)])s[A]!==void 0&&(B[A]=s[A]);if(n&&Se({instructions:[...l.instructions,...h],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:f})){let A=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...l.instructions,...h]}).compileToV0Message(Object.values(s));m.push(new _e(A))}else{let A=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...h]}).compileToV0Message(Object.values(s));m.push(new _e(A))}y.push(Array.from(new Set(h.map(A=>A.keys.filter(N=>N.isSigner).map(N=>N.pubkey.toString())).flat())).map(A=>p[A]).filter(A=>A!==void 0)),h=[w]}}),h.length>0){let g=[...new Set(h.map(b=>b.keys.filter(B=>B.isSigner).map(B=>B.pubkey.toString())).flat()).values()].map(b=>p[b]).filter(b=>b!==void 0);if(n&&Se({instructions:[...l.instructions,...h],payer:this.feePayer,lookupTableAddressAccount:s,recentBlockhash:f})){let b=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...l.instructions,...h]}).compileToV0Message(Object.values(s));m.push(new _e(b))}else{let b=new Ne({payerKey:this.feePayer,recentBlockhash:f,instructions:[...h]}).compileToV0Message(Object.values(s));m.push(new _e(b))}y.push(g)}return(T=this.owner)!=null&&T.signer&&y.forEach(w=>{w.some(g=>g.publicKey.equals(this.owner.publicKey))||w.push(this.owner.signer)}),{builder:this,transactions:m,buildProps:t,signers:y,instructionTypes:this.instructionTypes,execute:async w=>{var q;let{sequentially:g,onTxUpdate:b,skipTxCount:B=0,recentBlockHash:A,skipPreflight:N=!0}=w||{};if(m.map(async(K,D)=>{y[D].length&&K.sign(y[D]),A&&(K.message.recentBlockhash=A)}),de(m),(q=this.owner)!=null&&q.isKeyPair){if(g){let K=0,D=[];for(let R of m){if(++K,K<=B){console.log("skip tx: ",K),D.push("tx skipped");continue}let F=await this.connection.sendTransaction(R,{skipPreflight:N});await Ye(this.connection,F),D.push(F)}return{txIds:D,signedTxs:m}}return{txIds:await Promise.all(m.map(async K=>await this.connection.sendTransaction(K,{skipPreflight:N}))),signedTxs:m}}if(this.signAllTransactions){let K=await this.signAllTransactions(m.slice(B,m.length)),D=[...m.slice(0,B),...K];if(g){let R=0,F=[],J=async()=>{if(!D[R])return;if(R<B){F.push({txId:"",status:"success",signedTx:D[R]}),b==null||b([...F]),R++,J();return}let re=await this.connection.sendTransaction(D[R],{skipPreflight:N});F.push({txId:re,status:"sent",signedTx:D[R]}),b==null||b([...F]),R++,this.connection.onSignature(re,V=>{let _=F.findIndex(Mn=>Mn.txId===re);_>-1&&(F[_].status=V.err?"error":"success"),b==null||b([...F]),V.err||J()},"processed"),this.connection.getSignatureStatus(re)};return J(),{txIds:[],signedTxs:D}}else{let R=[];for(let F=0;F<D.length;F+=1){let J=await this.connection.sendTransaction(D[F],{skipPreflight:N});R.push(J)}return{txIds:R,signedTxs:D}}}throw new Error("please provide owner in keypair format or signAllTransactions function")},extInfo:i||{}}}};import{AccountLayout as xe,createAssociatedTokenAccountInstruction as Ot,TOKEN_PROGRAM_ID as pe,TOKEN_2022_PROGRAM_ID as Io}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=H(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 Po,SystemProgram as Ao}from"@solana/web3.js";import ko from"bn.js";import{createCloseAccountInstruction as Bo,createInitializeAccountInstruction as Co,createTransferInstruction as So,TOKEN_PROGRAM_ID as we}from"@solana/spl-token";import{Keypair as yo,PublicKey as _n}from"@solana/web3.js";import wo from"bn.js";import{TOKEN_PROGRAM_ID as xo}from"@solana/spl-token";function co(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function kt(e,...t){if(!co(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 Bt(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Pn(e,t){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),Q=(e,t)=>e<<32-t|e>>>t;var Mc=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function uo(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Ct(e){return typeof e=="string"&&(e=uo(e)),kt(e),e}var et=class{clone(){return this._cloneInto()}},Dc={}.toString;function An(e){let t=r=>e().update(Ct(r)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function lo(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),c=r?4:0,u=r?0:4;e.setUint32(t+c,s,r),e.setUint32(t+u,a,r)}var kn=(e,t,n)=>e&t^~e&n,Bn=(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){Bt(this);let{view:n,buffer:r,blockLen:o}=this;t=Ct(t);let i=t.length;for(let s=0;s<i;){let a=Math.min(o-this.pos,i-s);if(a===o){let c=tt(t);for(;o<=i-s;s+=o)this.process(c,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){Bt(this),Pn(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;lo(r,o-8,BigInt(this.length*8),i),this.process(r,0);let a=tt(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;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 fo=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),St=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:c}=this;return[t,n,r,o,i,s,a,c]}set(t,n,r,o,i,s,a,c){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=c|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],y=Q(p,7)^Q(p,18)^p>>>3,h=Q(m,17)^Q(m,19)^m>>>10;fe[f]=h+fe[f-7]+y+fe[f-16]|0}let{A:r,B:o,C:i,D:s,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let p=Q(a,6)^Q(a,11)^Q(a,25),m=l+p+kn(a,c,u)+fo[f]+fe[f]|0,h=(Q(r,2)^Q(r,13)^Q(r,22))+Bn(r,o,i)|0;l=u,u=c,c=a,a=s+m|0,s=i,i=o,o=r,r=m+h|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,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(r,o,i,s,a,c,u,l)}roundClean(){fe.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Cn=An(()=>new St);import{PublicKey as bo}from"@solana/web3.js";import Ln,{isBN as qu}from"bn.js";import{bits as Gc,BitStructure as Hc,blob as po,Blob as jc,cstr as zc,f32 as Zc,f32be as Yc,f64 as Xc,f64be as Qc,greedy as Jc,Layout as mo,ns64 as $c,ns64be as eu,nu64 as tu,nu64be as nu,offset as ru,s16 as ou,s16be as iu,s24 as su,s24be as au,s32 as cu,s32be as uu,s40 as lu,s40be as fu,s48 as pu,s48be as mu,s8 as du,seq as hu,struct as gu,Structure as ho,u16 as bu,u16be as yu,u24 as wu,u24be as xu,u32 as Tu,u32be as Pu,u40 as Au,u40be as ku,u48 as Bu,u48be as Cu,u8 as Su,UInt as go,union as Lu,Union as Iu,unionLayoutDiscriminator as Nu,utf8 as _u}from"@solana/buffer-layout";var Lt=mo,Sn=ho;var It=go;var Nt=po;var _t=class extends Lt{constructor(n,r,o){super(n,o);this.blob=Nt(n),this.signed=r}decode(n,r=0){let o=new Ln(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 Ln(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function In(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 Lt{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 bo(t),t=>t.toBuffer(),e)}var Rt=class extends Sn{decode(t,n){return super.decode(t,n)}};function Nn(e,t,n){return new Rt(e,t,n)}var Me=Nn([Re("mint"),Re("owner"),ot("amount"),rt("delegateOption"),Re("delegate"),In("state"),rt("isNativeOption"),ot("isNative"),ot("delegatedAmount"),rt("closeAuthorityOption"),Re("closeAuthority")]);var ol=H("Raydium_Util");function En({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:c,amount:u}=a;r.push({publicKey:i,mint:c,amount:u,isAssociated:Xe(e,c,s.owner).publicKey.equals(i),isNative:!1,programId:s.owner}),o.push({pubkey:i,accountInfo:a,programId:s.owner})}return t&&r.push({mint:_n.default,amount:new wo(String(t.lamports)),isNative:!0,programId:t.owner}),{tokenAccounts:r,tokenAccountRawInfos:o}}function it({fromPublicKey:e,programId:t=xo,assignSeed:n}){let r=n?btoa(n).slice(0,32):yo.generate().publicKey.toBase58().slice(0,32);return{publicKey:To(e,r,t),seed:r}}function To(e,t,n){let r=Buffer.concat([e.toBuffer(),Buffer.from(t),n.toBuffer()]),o=Cn(r);return new _n(o)}function Mt(e){let{mint:t,tokenAccount:n,owner:r,programId:o=we}=e;return Co(n,t,r,o)}function De(e){let{tokenAccount:t,payer:n,multiSigners:r=[],owner:o,programId:i=we}=e;return Bo(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),c=X(n).add(new ko(a)),u=it({fromPublicKey:o,programId:we});return{addresses:{newAccount:u.publicKey},signers:[],instructions:[Ao.createAccountWithSeed({fromPubkey:o,basePubkey:o,seed:u.seed,newAccountPubkey:u.publicKey,lamports:c.toNumber(),space:Me.span,programId:we}),Mt({mint:new Po(te.address),tokenAccount:u.publicKey,owner:i,programId:we})],instructionTypes:[U.CreateAccount,U.InitAccount],endInstructionTypes:s?[]:[U.CloseAccount],endInstructions:s?[]:[De({tokenAccount:u.publicKey,payer:o,owner:i})]}}function Rn({source:e,destination:t,owner:n,amount:r,multiSigners:o=[],tokenProgram:i=we}){return So(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:!1,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<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:Io},o.commitment)]),{tokenAccounts:c,tokenAccountRawInfos:u}=En({owner:this.scope.ownerPubKey,solAccountResp:i,tokenAccountResp:{context:s.context,value:[...s.value,...a.value]}});return this._tokenAccounts=c,this._tokenAccountRawInfos=u,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:c,tokenAccountRawInfos:u}}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,c)=>a.amount.lt(c.amount)?1:-1),s=this.getAssociatedTokenAccount(n,r);for(let a of i){let{publicKey:c}=a;if(c&&(!o||o&&s.equals(c)))return c}}async getOrCreateTokenAccount(n){var y,h,x,T;await this.fetchWalletTokenAccounts();let{mint:r,createInfo:o,associatedOnly:i,owner:s,notUseTokenAccount:a=!1,skipCloseAccount:c=!1,checkCreateATAOwner:u=!1}=n,l=new st(n.tokenProgram||pe),f=this.getAssociatedTokenAccount(r,new st(l)),p=(a?[]:this.tokenAccountRawInfos).filter(w=>w.accountInfo.mint.equals(r)&&(!i||w.pubkey.equals(f))).sort((w,g)=>w.accountInfo.amount.lt(g.accountInfo.amount)?1:-1);if(o===void 0||p.length>0)return p.length>0?{account:p[0].pubkey}:{};let m={instructions:[],endInstructions:[],signers:[],instructionTypes:[],endInstructionTypes:[]};if(i){let w=Ot(s,f,s,r,l);if(u){let g=await this.scope.connection.getAccountInfo(f);if(g===null)(y=m.instructions)==null||y.push(w),m.instructionTypes.push(U.CreateATA);else if(!(g.owner.equals(l)&&xe.decode(g.data).mint.equals(r)&&xe.decode(g.data).owner.equals(s)))throw Error(`create ata check error -> mint: ${r.toString()}, ata: ${f.toString()}`)}else m.instructions.push(w),m.instructionTypes.push(U.CreateATA);if(r.equals(ie)&&o.amount){let g=await Dt({connection:this.scope.connection,owner:this.scope.ownerPubKey,payer:o.payer||this.scope.ownerPubKey,amount:(h=o.amount)!=null?h:0,skipCloseAccount:c});m.instructions.push(...g.instructions||[]),m.endInstructions.push(...g.endInstructions||[]),m.instructionTypes.push(...g.instructionTypes||[]),m.endInstructionTypes.push(...g.endInstructionTypes||[]),o.amount&&(m.instructions.push(Rn({source:g.addresses.newAccount,destination:f,owner:this.scope.ownerPubKey,amount:o.amount,tokenProgram:pe})),m.instructionTypes.push(U.TransferAmount))}return c||(m.endInstructions.push(De({owner:s,payer:o.payer||s,tokenAccount:f,programId:l})),m.endInstructionTypes.push(U.CloseAccount)),{account:f,instructionParams:m}}else{let w=it({fromPublicKey:s,programId:l}),g=await this.scope.connection.getMinimumBalanceForRentExemption(xe.span),b=Lo.createAccountWithSeed({fromPubkey:s,basePubkey:s,seed:w.seed,newAccountPubkey:w.publicKey,lamports:g+Number((T=(x=o.amount)==null?void 0:x.toString())!=null?T:0),space:xe.span,programId:l});return m.instructions.push(b,Mt({mint:r,tokenAccount:w.publicKey,owner:this.scope.ownerPubKey,programId:l})),m.instructionTypes.push(U.CreateAccount),m.instructionTypes.push(U.InitAccount),c||(m.endInstructions.push(De({owner:s,payer:o.payer||s,tokenAccount:w.publicKey,programId:l})),m.endInstructionTypes.push(U.CloseAccount)),{account:w.publicKey,instructionParams:m}}}async checkOrCreateAta({mint:n,programId:r=pe,autoUnwrapWSOLToSOL:o}){var c;await this.fetchWalletTokenAccounts();let i=(c=this.scope.account.tokenAccounts.find(({mint:u})=>(u==null?void 0:u.toBase58())===n.toBase58()))==null?void 0:c.publicKey,s=this.scope.ownerPubKey,a={};if(!i){let u=this.getAssociatedTokenAccount(n,r),l=await Ot(s,u,s,n,r);a.instructions=[l],a.instructionTypes=[U.CreateATA],i=u}return o&&ie.toBase58()===n.toBase58()&&(a.endInstructions=[De({owner:s,payer:s,tokenAccount:i,programId:r})],a.endInstructionTypes=[U.CloseAccount]),{pubKey:i,newInstructions:a}}async handleTokenAccount(n){let{side:r,amount:o,mint:i,programId:s=pe,tokenAccount:a,payer:c=this.scope.ownerPubKey,bypassAssociatedCheck:u,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:c,amount:o,skipCloseAccount:l});return v({tokenAccount:m.addresses.newAccount},m)}else if(!a||r==="out"&&!p.equals(a)&&!u){let m=[],y=Ot(this.scope.ownerPubKey,p,this.scope.ownerPubKey,i,s);if(f){let h=await this.scope.connection.getAccountInfo(p);if(h===null)m.push(y);else if(!(h.owner.equals(pe)&&xe.decode(h.data).mint.equals(i)&&xe.decode(h.data).owner.equals(this.scope.ownerPubKey)))throw Error(`create ata check error -> mint: ${i.toString()}, ata: ${p.toString()}`)}else m.push(y);return{tokenAccount:p,instructions:m,instructionTypes:[U.CreateATA]}}return{tokenAccount:a}}async processTokenAccount(n){let{mint:r,programId:o=pe,amount:i,useSOLBalance:s,handleTokenAccount:a}=n,c,u=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"]);c=p,u.addInstruction(m)}else if(c=await this.getCreatedTokenAccount({mint:r,associatedOnly:!1,programId:o}),!c&&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"]);c=p,u.addInstruction(m)}return v({tokenAccount:c},u.AllTxData)}};export{Kt as default};
|
|
2
2
|
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
3
|
//# sourceMappingURL=account.mjs.map
|