goosefx-amm-sdk
Version:
SDK for the GooseFx AMM
1 lines • 138 kB
JavaScript
import{PublicKey as S,SystemProgram as _n}from"@solana/web3.js";import{NATIVE_MINT as lt,TOKEN_PROGRAM_ID as Wn,createSyncNativeInstruction as Vn}from"@solana/spl-token";import ei from"big.js";import oo from"bn.js";import X from"bn.js";import{get as Vt,set as Hn}from"lodash";var dt=class{constructor(n){this.logLevel=n.logLevel!==void 0?n.logLevel:0,this.name=n.name}set level(n){this.logLevel=n}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(n){return n<=this.logLevel}error(...n){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...n),this):this}logWithError(...n){let e=n.map(i=>typeof i=="object"?JSON.stringify(i):i).join(", ");throw new Error(e)}warning(...n){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...n),this):this}info(...n){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...n),this):this}debug(...n){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...n),this):this}},Gt={},zn={};function z(t){let n=Vt(Gt,t);if(!n){let e=Vt(zn,t);n=new dt({name:t,logLevel:e}),Hn(Gt,t,n)}return n}var ze=new X(0),Fr=new X(1),qr=new X(2),Ur=new X(3),_r=new X(5),zt=new X(10),Wr=new X(100),Vr=new X(1e3),Gr=new X(1e4),Ht=9007199254740991;function se(t){let n=z("Gfx_parseBigNumberish");if(t instanceof X)return t;if(typeof t=="string"){if(t.match(/^-?[0-9]+$/))return new X(t);n.logWithError(`invalid BigNumberish string: ${t}`)}return typeof t=="number"?(t%1&&n.logWithError(`BigNumberish number underflow: ${t}`),(t>=Ht||t<=-Ht)&&n.logWithError(`BigNumberish number overflow: ${t}`),new X(String(t))):typeof t=="bigint"?new X(t.toString()):(n.error(`invalid BigNumberish value: ${t}`),new X(0))}import Zn from"toformat";var jn=Zn,ke=jn;import je from"big.js";import Xn from"bn.js";import Jn from"decimal.js-light";var Ze=z("module/fraction"),ft=ke(je),Be=ke(Jn),Qn={[0]:Be.ROUND_DOWN,[1]:Be.ROUND_HALF_UP,[2]:Be.ROUND_UP},$n={[0]:je.roundDown,[1]:je.roundHalfUp,[2]:je.roundUp},q=class{constructor(n,e=new Xn(1)){this.numerator=se(n),this.denominator=se(e)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new q(this.denominator,this.numerator)}add(n){let e=n instanceof q?n:new q(se(n));return this.denominator.eq(e.denominator)?new q(this.numerator.add(e.numerator),this.denominator):new q(this.numerator.mul(e.denominator).add(e.numerator.mul(this.denominator)),this.denominator.mul(e.denominator))}sub(n){let e=n instanceof q?n:new q(se(n));return this.denominator.eq(e.denominator)?new q(this.numerator.sub(e.numerator),this.denominator):new q(this.numerator.mul(e.denominator).sub(e.numerator.mul(this.denominator)),this.denominator.mul(e.denominator))}mul(n){let e=n instanceof q?n:new q(se(n));return new q(this.numerator.mul(e.numerator),this.denominator.mul(e.denominator))}div(n){let e=n instanceof q?n:new q(se(n));return new q(this.numerator.mul(e.denominator),this.denominator.mul(e.numerator))}toSignificant(n,e={groupSeparator:""},i=1){Number.isInteger(n)||Ze.logWithError(`${n} is not an integer.`),n<=0&&Ze.logWithError(`${n} is not positive.`),Be.set({precision:n+1,rounding:Qn[i]});let o=new Be(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(n);return o.toFormat(o.decimalPlaces(),e)}toFixed(n,e={groupSeparator:""},i=1){return Number.isInteger(n)||Ze.logWithError(`${n} is not an integer.`),n<0&&Ze.logWithError(`${n} is negative.`),ft.DP=n,ft.RM=$n[i]||1,new ft(this.numerator.toString()).div(this.denominator.toString()).toFormat(n,e)}isZero(){return this.numerator.isZero()}};var po=z("Gfx_amount"),go=ke(ei);import{TOKEN_PROGRAM_ID as Zt}from"@solana/spl-token";var ye={address:"So11111111111111111111111111111111111111112",programId:Zt.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"",tags:[],priority:2,type:"goose-fx",extensions:{coingeckoId:"solana"}},ae={address:"So11111111111111111111111111111111111111112",programId:Zt.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"",tags:[],priority:2,type:"goose-fx",extensions:{coingeckoId:"solana"}};import{PublicKey as ht}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as ti}from"@solana/spl-token";import{PublicKey as U,SystemProgram as jt,SYSVAR_RENT_PUBKEY as ni}from"@solana/web3.js";function pt({pubkey:t,isSigner:n=!1,isWritable:e=!0}){return{pubkey:t,isWritable:e,isSigner:n}}var So=[pt({pubkey:ti,isWritable:!1}),pt({pubkey:jt.programId,isWritable:!1}),pt({pubkey:ni,isWritable:!1})];function gt({publicKey:t,transformSol:n}){let e=Yt(t.toString());if(e instanceof U)return n&&e.equals(ve)?Q:e;if(n&&e.toString()===ve.toBase58())return Q;if(typeof e=="string"){if(e===U.default.toBase58())return U.default;try{return new U(e)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Yt(t){try{return new U(t)}catch{return t}}var Ao=new U("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),ko=new U("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Bo=new U("SysvarRent111111111111111111111111111111111"),vo=new U("SysvarC1ock11111111111111111111111111111111"),Mo=new U("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),xo=new U("Sysvar1nstructions1111111111111111111111111"),Co=jt.programId,Io=new U("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),No=new U("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Ro=new U("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),Ko=new U("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Oo=new U("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Lo=new U("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Do=new U("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Eo=new U("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Fo=new U("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),qo=new U("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Uo=new U("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),Q=new U("So11111111111111111111111111111111111111112"),ve=U.default;function Ye(t){return gt({publicKey:t,transformSol:!0})}var yt=class{constructor({mint:n,decimals:e,symbol:i,name:o,skipMint:r=!1,isToken2022:s=!1}){if(n===ve.toBase58()||n instanceof ht&&ve.equals(n)){this.decimals=ae.decimals,this.symbol=ae.symbol,this.name=ae.name,this.mint=new ht(ae.address),this.isToken2022=!1;return}this.decimals=e,this.symbol=i||n.toString().substring(0,6),this.name=o||n.toString().substring(0,6),this.mint=r?ht.default:gt({publicKey:n}),this.isToken2022=s}equals(n){return this===n?!0:this.mint.equals(n.mint)}},pe=yt;pe.WSOL=new yt({...ae,mint:ae.address});var bt=class{constructor({decimals:n,symbol:e="UNKNOWN",name:i="UNKNOWN"}){this.decimals=n,this.symbol=e,this.name=i}equals(n){return this===n}},Xe=bt;Xe.SOL=new bt(ye);import ii from"bn.js";var Xt=new q(new ii(100)),ie=class extends q{toSignificant(n=5,e,i){return this.mul(Xt).toSignificant(n,e,i)}toFixed(n=2,e,i){return this.mul(Xt).toFixed(n,e,i)}};var os=z("Ray_price");var $={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",CpmmInitUserLiquidity:"CpmmInitUserLiquidity",CpmmCreatePool:"CpmmCreatePool",CpmmAddLiquidity:"CpmmAddLiquidity",CpmmWithdrawLiquidity:"CpmmWithdrawLiquidity",CpmmSwapBaseIn:"CpmmSwapBaseIn",CpmmSwapBaseOut:"CpmmSwapBaseOut",CpmmOracleSwapBaseIn:"CpmmOracleSwapBaseIn"};import $t from"bn.js";import V from"bn.js";import be from"decimal.js-light";import wt from"bn.js";var Me=new wt(0);function Tt(t,n){if(n.isZero())throw Error("divisor is zero");return t.mod(n)}function xe(t,n){if(n.isZero())throw Error("rhs is zero");let e=t.div(n);return e.isZero()?[e,n]:t.sub(e.mul(n)).isZero()?[e,n]:[e.add(new wt(1)),n]}function Je(t,n){return t.gt(n)?t.sub(n):new wt(0)}var ri=new V(100),Ce=new V(1e6),oi=100,si=new V(3600),Jt=new V(1e5),ai=new V(3e5),Ie=class{static calculateDynamicFee(n,e,i,o,r,s,a){let u=this.calculateDynamicFeeRate(e,i,o,r,s,a),[c,l]=xe(n.mul(u),Ce);return c}static calculatePreDynamicFee(n,e,i,o,r,s,a){let u=this.calculateDynamicFeeRate(e,i,o,r,s,a);if(u.isZero())return n;let c=Ce.sub(u);if(c.isZero())throw new Error("Fee rate equals denominator, causing division by zero");return n.mul(Ce).add(c).sub(new V(1)).div(c)}static calculateDynamicFeeRate(n,e,i,o,r,s){switch(i){case"volatility":return this.calculateVolatileFee(n,e,o,r,s)}}static calculateVolatileFee(n,e,i,o,r){let{minPrice:s,maxPrice:a,twapPrice:u}=this.getPriceRange(e,n,si);if(s.eqn(0)||a.eqn(0)||u.eqn(0)||u.eqn(1))return i;let c=new be(a.toString()).ln(),l=new be(s.toString()).ln(),m=new be(u.toString()).ln(),d=c.sub(l),f=m.abs();if(f.eq(0))return i;let h=d.div(f),p=o.eqn(0)?ai:o,w=new be(p.toString()).mul(h),y=new be(i.toString()).add(w),T=new V(y.lessThan(new be(Jt.toString()))?y.toString():Jt.toString());if(r){let g=Je(T,ri);return i.gt(g)?i:g}else return T}static getPriceRange(n,e,i){let o=new V(1).ushln(128).subn(1),r=new V(0),s=n.observations.map((m,d)=>({observation:m,idx:d})).filter(({observation:m})=>{m.blockTimestamp.eqn(0)&&!m.cumulativeToken0PriceX32.eqn(0)&&!m.cumulativeToken1PriceX32.eqn(0)&&e.sub(m.blockTimestamp)<=i}).map(({observation:m,idx:d})=>({index:d,observation:m}));if(s.length<2)return{minPrice:new V(0),maxPrice:new V(0),twapPrice:new V(0)};s.sort((m,d)=>d.observation.blockTimestamp.cmp(m.observation.blockTimestamp));let a=s[0],u=s[s.length-1],c=Je(a.observation.blockTimestamp,u.observation.blockTimestamp);if(c.eqn(0))return{minPrice:new V(0),maxPrice:new V(0),twapPrice:new V(0)};let l=a.observation.cumulativeToken0PriceX32.sub(u.observation.cumulativeToken0PriceX32).div(c);for(let m of s){let d;if(m.index==0?d=n.observations[oi-1]:d=n.observations[m.index-1],d.blockTimestamp.eqn(0))continue;if(d.blockTimestamp>m.observation.blockTimestamp)break;let f=m.observation,h=Je(f.blockTimestamp,d.blockTimestamp);if(h.eqn(0))continue;let p=f.cumulativeToken0PriceX32.sub(d.cumulativeToken0PriceX32).div(h);o=V.min(o,p),r=V.max(r,p)}return{minPrice:o,maxPrice:r,twapPrice:l}}static calculatePreFeeAmount(n,e,i,o,r,s,a){let u=this.calculateDynamicFeeRate(n,i,o,r,s,a);if(u.eqn(0))return e;{let c=e.mul(Ce),l=Ce.sub(u);return c.add(l).subn(1).div(l)}}};import Qt from"bn.js";var ge=class{static swapWithoutFees(n,e,i){let o=e.mul(i),r=e.add(n),[s,a]=xe(o,r),u=a.sub(e),c=i.sub(s);if(c.isZero())throw Error("destinationAmountSwapped is zero");return{sourceAmountSwapped:u,destinationAmountSwapped:c}}static swapWithoutFeesBaseOut(n,e,i){if(n.isZero())throw new Error("destinationAmount is zero");if(n.gt(i))throw new Error("destinationAmount exceeds available destination reserve");let o=e.mul(n),r=i.sub(n);if(r.isZero())throw new Error("denominator is zero");let[s]=xe(o,r);return{sourceAmountSwapped:s,destinationAmountSwapped:n}}static lpTokensToTradingTokens(n,e,i,o,r){let s=n.mul(i).div(e),a=n.mul(o).div(e);if(r===0)return{tokenAmount0:s,tokenAmount1:a};if(r===1)return Tt(n.mul(i),e).gt(Me)&&s.gt(Me)&&(s=s.add(new Qt(1))),Tt(n.mul(o),e).gt(Me)&&a.gt(Me)&&(a=a.add(new Qt(1))),{tokenAmount0:s,tokenAmount1:a};throw Error("roundDirection value error")}};var Ne=class{static validate_supply(n,e){if(n.isZero())throw Error("tokenAmount0 is zero");if(e.isZero())throw Error("tokenAmount1 is zero")}static swapBaseIn(n,e,i,o,r,s,a=!1){let u=Ie.calculateDynamicFee(n,new $t(new Date().getTime()/1e3),r,"volatility",o,s,a),c=n.sub(u),{sourceAmountSwapped:l,destinationAmountSwapped:m}=ge.swapWithoutFees(c,e,i),d=l.add(u);return{newSwapSourceAmount:e.add(d),newSwapDestinationAmount:i.sub(m),sourceAmountSwapped:d,destinationAmountSwapped:m,tradeFee:u}}static swapBaseOut(n,e,i,o,r,s,a=!1){if(n.isZero())throw new Error("destinationAmount is zero");if(n.gt(i))throw new Error("destinationAmount exceeds available destination reserve");let{sourceAmountSwapped:u,destinationAmountSwapped:c}=ge.swapWithoutFeesBaseOut(n,e,i),l=Ie.calculatePreDynamicFee(u,new $t(new Date().getTime()/1e3),r,"volatility",o,s,a);return{newSwapSourceAmount:e.add(l),newSwapDestinationAmount:i.sub(c),sourceAmountSwapped:l,destinationAmountSwapped:c,tradeFee:l.sub(u)}}};import{PublicKey as Ee,sendAndConfirmTransaction as Kt,Transaction as Fe,TransactionMessage as qe,VersionedTransaction as Ue}from"@solana/web3.js";import gr from"axios";import{PublicKey as ci,ComputeBudgetProgram as en,Transaction as nn,TransactionMessage as li,Keypair as rn,VersionedTransaction as on}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as mi}from"@solana/spl-token";var tn=z("Gfx_txUtil"),sn=1644;function Qe(t){let n=[],e=[];return t.microLamports&&(n.push(en.setComputeUnitPrice({microLamports:t.microLamports})),e.push($.SetComputeUnitPrice)),t.units&&(n.push(en.setComputeUnitLimit({units:t.units})),e.push($.SetComputeUnitLimit)),{instructions:n,instructionTypes:e}}async function we(t,n){var i,o;let e=n!=null?n:"confirmed";try{return((o=await((i=t.getLatestBlockhash)==null?void 0:i.call(t,{commitment:e})))==null?void 0:o.blockhash)||(await t.getRecentBlockhash(e)).blockhash}catch{return(await t.getRecentBlockhash(e)).blockhash}}function di(t,n){t.length<1&&tn.logWithError(`no instructions provided: ${t.toString()}`),n.length<1&&tn.logWithError(`no signers provided:, ${n.toString()}`);let e=new nn;e.recentBlockhash="11111111111111111111111111111111",e.feePayer=n[0],e.add(...t);try{return e.serialize({verifySignatures:!1}).toString("base64").length<sn}catch{return!1}}function ue(t,n){let[e,i]=ci.findProgramAddressSync(t,n);return{publicKey:e,nonce:i}}function Re({instructions:t,payer:n,signers:e}){return di(t,[n,...e])}function Ke({instructions:t,payer:n,lookupTableAddressAccount:e,recentBlockhash:i=rn.generate().publicKey.toString()}){let r=new li({payerKey:n,recentBlockhash:i,instructions:t}).compileToV0Message(Object.values(e!=null?e:{}));try{return Buffer.from(new on(r).serialize()).toString("base64").length<sn}catch{return!1}}var fi=t=>Buffer.isBuffer(t)?t:t instanceof Uint8Array?Buffer.from(t.buffer,t.byteOffset,t.byteLength):Buffer.from(t);function he(t){let n=[];return t.forEach(e=>{e instanceof nn&&(e.recentBlockhash||(e.recentBlockhash=mi.toBase58()),e.feePayer||(e.feePayer=rn.generate().publicKey));let i=e.serialize({requireAllSignatures:!1,verifySignatures:!1});e instanceof on&&(i=fi(i));let o=i.toString("base64");n.push(o)}),console.log("simulate tx string:",n),n}import{PublicKey as kn,AddressLookupTableAccount as st}from"@solana/web3.js";import{PublicKey as Sn}from"@solana/web3.js";import{MINT_SIZE as lr,TOKEN_PROGRAM_ID as mr,getTransferFeeConfig as dr,unpackMint as fr}from"@solana/spl-token";import{PublicKey as Vs}from"@solana/web3.js";import Hs from"bn.js";import sa from"bn.js";var Te=9e15,de=1e9,St="0123456789abcdef",et="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",tt="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",At={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Te,maxE:Te,crypto:!1},mn,oe,C=!0,it="[DecimalError] ",me=it+"Invalid argument: ",dn=it+"Precision limit exceeded",fn=it+"crypto unavailable",pn="[object Decimal]",Z=Math.floor,_=Math.pow,pi=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,gi=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,hi=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,gn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,te=1e7,M=7,yi=9007199254740991,bi=et.length-1,kt=tt.length-1,b={toStringTag:pn};b.absoluteValue=b.abs=function(){var t=new this.constructor(this);return t.s<0&&(t.s=1),k(t)};b.ceil=function(){return k(new this.constructor(this),this.e+1,2)};b.clampedTo=b.clamp=function(t,n){var e,i=this,o=i.constructor;if(t=new o(t),n=new o(n),!t.s||!n.s)return new o(NaN);if(t.gt(n))throw Error(me+n);return e=i.cmp(t),e<0?t:i.cmp(n)>0?n:new o(i)};b.comparedTo=b.cmp=function(t){var n,e,i,o,r=this,s=r.d,a=(t=new r.constructor(t)).d,u=r.s,c=t.s;if(!s||!a)return!u||!c?NaN:u!==c?u:s===a?0:!s^u<0?1:-1;if(!s[0]||!a[0])return s[0]?u:a[0]?-c:0;if(u!==c)return u;if(r.e!==t.e)return r.e>t.e^u<0?1:-1;for(i=s.length,o=a.length,n=0,e=i<o?i:o;n<e;++n)if(s[n]!==a[n])return s[n]>a[n]^u<0?1:-1;return i===o?0:i>o^u<0?1:-1};b.cosine=b.cos=function(){var t,n,e=this,i=e.constructor;return e.d?e.d[0]?(t=i.precision,n=i.rounding,i.precision=t+Math.max(e.e,e.sd())+M,i.rounding=1,e=wi(i,Tn(i,e)),i.precision=t,i.rounding=n,k(oe==2||oe==3?e.neg():e,t,n,!0)):new i(1):new i(NaN)};b.cubeRoot=b.cbrt=function(){var t,n,e,i,o,r,s,a,u,c,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(C=!1,r=l.s*_(l.s*l,1/3),!r||Math.abs(r)==1/0?(e=G(l.d),t=l.e,(r=(t-e.length+1)%3)&&(e+=r==1||r==-2?"0":"00"),r=_(e,1/3),t=Z((t+1)/3)-(t%3==(t<0?-1:2)),r==1/0?e="5e"+t:(e=r.toExponential(),e=e.slice(0,e.indexOf("e")+1)+t),i=new m(e),i.s=l.s):i=new m(r.toString()),s=(t=m.precision)+3;;)if(a=i,u=a.times(a).times(a),c=u.plus(l),i=E(c.plus(l).times(a),c.plus(u),s+2,1),G(a.d).slice(0,s)===(e=G(i.d)).slice(0,s))if(e=e.slice(s-3,s+1),e=="9999"||!o&&e=="4999"){if(!o&&(k(a,t+1,0),a.times(a).times(a).eq(l))){i=a;break}s+=4,o=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(k(i,t+1,1),n=!i.times(i).times(i).eq(l));break}return C=!0,k(i,t,m.rounding,n)};b.decimalPlaces=b.dp=function(){var t,n=this.d,e=NaN;if(n){if(t=n.length-1,e=(t-Z(this.e/M))*M,t=n[t],t)for(;t%10==0;t/=10)e--;e<0&&(e=0)}return e};b.dividedBy=b.div=function(t){return E(this,new this.constructor(t))};b.dividedToIntegerBy=b.divToInt=function(t){var n=this,e=n.constructor;return k(E(n,new e(t),0,1,1),e.precision,e.rounding)};b.equals=b.eq=function(t){return this.cmp(t)===0};b.floor=function(){return k(new this.constructor(this),this.e+1,3)};b.greaterThan=b.gt=function(t){return this.cmp(t)>0};b.greaterThanOrEqualTo=b.gte=function(t){var n=this.cmp(t);return n==1||n===0};b.hyperbolicCosine=b.cosh=function(){var t,n,e,i,o,r=this,s=r.constructor,a=new s(1);if(!r.isFinite())return new s(r.s?1/0:NaN);if(r.isZero())return a;e=s.precision,i=s.rounding,s.precision=e+Math.max(r.e,r.sd())+4,s.rounding=1,o=r.d.length,o<32?(t=Math.ceil(o/3),n=(1/ot(4,t)).toString()):(t=16,n="2.3283064365386962890625e-10"),r=Pe(s,1,r.times(n),new s(1),!0);for(var u,c=t,l=new s(8);c--;)u=r.times(r),r=a.minus(u.times(l.minus(u.times(l))));return k(r,s.precision=e,s.rounding=i,!0)};b.hyperbolicSine=b.sinh=function(){var t,n,e,i,o=this,r=o.constructor;if(!o.isFinite()||o.isZero())return new r(o);if(n=r.precision,e=r.rounding,r.precision=n+Math.max(o.e,o.sd())+4,r.rounding=1,i=o.d.length,i<3)o=Pe(r,2,o,o,!0);else{t=1.4*Math.sqrt(i),t=t>16?16:t|0,o=o.times(1/ot(5,t)),o=Pe(r,2,o,o,!0);for(var s,a=new r(5),u=new r(16),c=new r(20);t--;)s=o.times(o),o=o.times(a.plus(s.times(u.times(s).plus(c))))}return r.precision=n,r.rounding=e,k(o,n,e,!0)};b.hyperbolicTangent=b.tanh=function(){var t,n,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(t=i.precision,n=i.rounding,i.precision=t+7,i.rounding=1,E(e.sinh(),e.cosh(),i.precision=t,i.rounding=n)):new i(e.s)};b.inverseCosine=b.acos=function(){var t,n=this,e=n.constructor,i=n.abs().cmp(1),o=e.precision,r=e.rounding;return i!==-1?i===0?n.isNeg()?ee(e,o,r):new e(0):new e(NaN):n.isZero()?ee(e,o+4,r).times(.5):(e.precision=o+6,e.rounding=1,n=n.asin(),t=ee(e,o+4,r).times(.5),e.precision=o,e.rounding=r,t.minus(n))};b.inverseHyperbolicCosine=b.acosh=function(){var t,n,e=this,i=e.constructor;return e.lte(1)?new i(e.eq(1)?0:NaN):e.isFinite()?(t=i.precision,n=i.rounding,i.precision=t+Math.max(Math.abs(e.e),e.sd())+4,i.rounding=1,C=!1,e=e.times(e).minus(1).sqrt().plus(e),C=!0,i.precision=t,i.rounding=n,e.ln()):new i(e)};b.inverseHyperbolicSine=b.asinh=function(){var t,n,e=this,i=e.constructor;return!e.isFinite()||e.isZero()?new i(e):(t=i.precision,n=i.rounding,i.precision=t+2*Math.max(Math.abs(e.e),e.sd())+6,i.rounding=1,C=!1,e=e.times(e).plus(1).sqrt().plus(e),C=!0,i.precision=t,i.rounding=n,e.ln())};b.inverseHyperbolicTangent=b.atanh=function(){var t,n,e,i,o=this,r=o.constructor;return o.isFinite()?o.e>=0?new r(o.abs().eq(1)?o.s/0:o.isZero()?o:NaN):(t=r.precision,n=r.rounding,i=o.sd(),Math.max(i,t)<2*-o.e-1?k(new r(o),t,n,!0):(r.precision=e=i-o.e,o=E(o.plus(1),new r(1).minus(o),e+t,1),r.precision=t+4,r.rounding=1,o=o.ln(),r.precision=t,r.rounding=n,o.times(.5))):new r(NaN)};b.inverseSine=b.asin=function(){var t,n,e,i,o=this,r=o.constructor;return o.isZero()?new r(o):(n=o.abs().cmp(1),e=r.precision,i=r.rounding,n!==-1?n===0?(t=ee(r,e+4,i).times(.5),t.s=o.s,t):new r(NaN):(r.precision=e+6,r.rounding=1,o=o.div(new r(1).minus(o.times(o)).sqrt().plus(1)).atan(),r.precision=e,r.rounding=i,o.times(2)))};b.inverseTangent=b.atan=function(){var t,n,e,i,o,r,s,a,u,c=this,l=c.constructor,m=l.precision,d=l.rounding;if(c.isFinite()){if(c.isZero())return new l(c);if(c.abs().eq(1)&&m+4<=kt)return s=ee(l,m+4,d).times(.25),s.s=c.s,s}else{if(!c.s)return new l(NaN);if(m+4<=kt)return s=ee(l,m+4,d).times(.5),s.s=c.s,s}for(l.precision=a=m+10,l.rounding=1,e=Math.min(28,a/M+2|0),t=e;t;--t)c=c.div(c.times(c).plus(1).sqrt().plus(1));for(C=!1,n=Math.ceil(a/M),i=1,u=c.times(c),s=new l(c),o=c;t!==-1;)if(o=o.times(u),r=s.minus(o.div(i+=2)),o=o.times(u),s=r.plus(o.div(i+=2)),s.d[n]!==void 0)for(t=n;s.d[t]===r.d[t]&&t--;);return e&&(s=s.times(2<<e-1)),C=!0,k(s,l.precision=m,l.rounding=d,!0)};b.isFinite=function(){return!!this.d};b.isInteger=b.isInt=function(){return!!this.d&&Z(this.e/M)>this.d.length-2};b.isNaN=function(){return!this.s};b.isNegative=b.isNeg=function(){return this.s<0};b.isPositive=b.isPos=function(){return this.s>0};b.isZero=function(){return!!this.d&&this.d[0]===0};b.lessThan=b.lt=function(t){return this.cmp(t)<0};b.lessThanOrEqualTo=b.lte=function(t){return this.cmp(t)<1};b.logarithm=b.log=function(t){var n,e,i,o,r,s,a,u,c=this,l=c.constructor,m=l.precision,d=l.rounding,f=5;if(t==null)t=new l(10),n=!0;else{if(t=new l(t),e=t.d,t.s<0||!e||!e[0]||t.eq(1))return new l(NaN);n=t.eq(10)}if(e=c.d,c.s<0||!e||!e[0]||c.eq(1))return new l(e&&!e[0]?-1/0:c.s!=1?NaN:e?0:1/0);if(n)if(e.length>1)r=!0;else{for(o=e[0];o%10===0;)o/=10;r=o!==1}if(C=!1,a=m+f,s=le(c,a),i=n?nt(l,a+10):le(t,a),u=E(s,i,a,1),Oe(u.d,o=m,d))do if(a+=10,s=le(c,a),i=n?nt(l,a+10):le(t,a),u=E(s,i,a,1),!r){+G(u.d).slice(o+1,o+15)+1==1e14&&(u=k(u,m+1,0));break}while(Oe(u.d,o+=10,d));return C=!0,k(u,m,d)};b.minus=b.sub=function(t){var n,e,i,o,r,s,a,u,c,l,m,d,f=this,h=f.constructor;if(t=new h(t),!f.d||!t.d)return!f.s||!t.s?t=new h(NaN):f.d?t.s=-t.s:t=new h(t.d||f.s!==t.s?f:NaN),t;if(f.s!=t.s)return t.s=-t.s,f.plus(t);if(c=f.d,d=t.d,a=h.precision,u=h.rounding,!c[0]||!d[0]){if(d[0])t.s=-t.s;else if(c[0])t=new h(f);else return new h(u===3?-0:0);return C?k(t,a,u):t}if(e=Z(t.e/M),l=Z(f.e/M),c=c.slice(),r=l-e,r){for(m=r<0,m?(n=c,r=-r,s=d.length):(n=d,e=l,s=c.length),i=Math.max(Math.ceil(a/M),s)+2,r>i&&(r=i,n.length=1),n.reverse(),i=r;i--;)n.push(0);n.reverse()}else{for(i=c.length,s=d.length,m=i<s,m&&(s=i),i=0;i<s;i++)if(c[i]!=d[i]){m=c[i]<d[i];break}r=0}for(m&&(n=c,c=d,d=n,t.s=-t.s),s=c.length,i=d.length-s;i>0;--i)c[s++]=0;for(i=d.length;i>r;){if(c[--i]<d[i]){for(o=i;o&&c[--o]===0;)c[o]=te-1;--c[o],c[i]+=te}c[i]-=d[i]}for(;c[--s]===0;)c.pop();for(;c[0]===0;c.shift())--e;return c[0]?(t.d=c,t.e=rt(c,e),C?k(t,a,u):t):new h(u===3?-0:0)};b.modulo=b.mod=function(t){var n,e=this,i=e.constructor;return t=new i(t),!e.d||!t.s||t.d&&!t.d[0]?new i(NaN):!t.d||e.d&&!e.d[0]?k(new i(e),i.precision,i.rounding):(C=!1,i.modulo==9?(n=E(e,t.abs(),0,3,1),n.s*=t.s):n=E(e,t,0,i.modulo,1),n=n.times(t),C=!0,e.minus(n))};b.naturalExponential=b.exp=function(){return Bt(this)};b.naturalLogarithm=b.ln=function(){return le(this)};b.negated=b.neg=function(){var t=new this.constructor(this);return t.s=-t.s,k(t)};b.plus=b.add=function(t){var n,e,i,o,r,s,a,u,c,l,m=this,d=m.constructor;if(t=new d(t),!m.d||!t.d)return!m.s||!t.s?t=new d(NaN):m.d||(t=new d(t.d||m.s===t.s?m:NaN)),t;if(m.s!=t.s)return t.s=-t.s,m.minus(t);if(c=m.d,l=t.d,a=d.precision,u=d.rounding,!c[0]||!l[0])return l[0]||(t=new d(m)),C?k(t,a,u):t;if(r=Z(m.e/M),i=Z(t.e/M),c=c.slice(),o=r-i,o){for(o<0?(e=c,o=-o,s=l.length):(e=l,i=r,s=c.length),r=Math.ceil(a/M),s=r>s?r+1:s+1,o>s&&(o=s,e.length=1),e.reverse();o--;)e.push(0);e.reverse()}for(s=c.length,o=l.length,s-o<0&&(o=s,e=l,l=c,c=e),n=0;o;)n=(c[--o]=c[o]+l[o]+n)/te|0,c[o]%=te;for(n&&(c.unshift(n),++i),s=c.length;c[--s]==0;)c.pop();return t.d=c,t.e=rt(c,i),C?k(t,a,u):t};b.precision=b.sd=function(t){var n,e=this;if(t!==void 0&&t!==!!t&&t!==1&&t!==0)throw Error(me+t);return e.d?(n=hn(e.d),t&&e.e+1>n&&(n=e.e+1)):n=NaN,n};b.round=function(){var t=this,n=t.constructor;return k(new n(t),t.e+1,n.rounding)};b.sine=b.sin=function(){var t,n,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(t=i.precision,n=i.rounding,i.precision=t+Math.max(e.e,e.sd())+M,i.rounding=1,e=Pi(i,Tn(i,e)),i.precision=t,i.rounding=n,k(oe>2?e.neg():e,t,n,!0)):new i(NaN)};b.squareRoot=b.sqrt=function(){var t,n,e,i,o,r,s=this,a=s.d,u=s.e,c=s.s,l=s.constructor;if(c!==1||!a||!a[0])return new l(!c||c<0&&(!a||a[0])?NaN:a?s:1/0);for(C=!1,c=Math.sqrt(+s),c==0||c==1/0?(n=G(a),(n.length+u)%2==0&&(n+="0"),c=Math.sqrt(n),u=Z((u+1)/2)-(u<0||u%2),c==1/0?n="5e"+u:(n=c.toExponential(),n=n.slice(0,n.indexOf("e")+1)+u),i=new l(n)):i=new l(c.toString()),e=(u=l.precision)+3;;)if(r=i,i=r.plus(E(s,r,e+2,1)).times(.5),G(r.d).slice(0,e)===(n=G(i.d)).slice(0,e))if(n=n.slice(e-3,e+1),n=="9999"||!o&&n=="4999"){if(!o&&(k(r,u+1,0),r.times(r).eq(s))){i=r;break}e+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(k(i,u+1,1),t=!i.times(i).eq(s));break}return C=!0,k(i,u,l.rounding,t)};b.tangent=b.tan=function(){var t,n,e=this,i=e.constructor;return e.isFinite()?e.isZero()?new i(e):(t=i.precision,n=i.rounding,i.precision=t+10,i.rounding=1,e=e.sin(),e.s=1,e=E(e,new i(1).minus(e.times(e)).sqrt(),t+10,0),i.precision=t,i.rounding=n,k(oe==2||oe==4?e.neg():e,t,n,!0)):new i(NaN)};b.times=b.mul=function(t){var n,e,i,o,r,s,a,u,c,l=this,m=l.constructor,d=l.d,f=(t=new m(t)).d;if(t.s*=l.s,!d||!d[0]||!f||!f[0])return new m(!t.s||d&&!d[0]&&!f||f&&!f[0]&&!d?NaN:!d||!f?t.s/0:t.s*0);for(e=Z(l.e/M)+Z(t.e/M),u=d.length,c=f.length,u<c&&(r=d,d=f,f=r,s=u,u=c,c=s),r=[],s=u+c,i=s;i--;)r.push(0);for(i=c;--i>=0;){for(n=0,o=u+i;o>i;)a=r[o]+f[i]*d[o-i-1]+n,r[o--]=a%te|0,n=a/te|0;r[o]=(r[o]+n)%te|0}for(;!r[--s];)r.pop();return n?++e:r.shift(),t.d=r,t.e=rt(r,e),C?k(t,m.precision,m.rounding):t};b.toBinary=function(t,n){return Mt(this,2,t,n)};b.toDecimalPlaces=b.toDP=function(t,n){var e=this,i=e.constructor;return e=new i(e),t===void 0?e:(J(t,0,de),n===void 0?n=i.rounding:J(n,0,8),k(e,t+e.e+1,n))};b.toExponential=function(t,n){var e,i=this,o=i.constructor;return t===void 0?e=re(i,!0):(J(t,0,de),n===void 0?n=o.rounding:J(n,0,8),i=k(new o(i),t+1,n),e=re(i,!0,t+1)),i.isNeg()&&!i.isZero()?"-"+e:e};b.toFixed=function(t,n){var e,i,o=this,r=o.constructor;return t===void 0?e=re(o):(J(t,0,de),n===void 0?n=r.rounding:J(n,0,8),i=k(new r(o),t+o.e+1,n),e=re(i,!1,t+i.e+1)),o.isNeg()&&!o.isZero()?"-"+e:e};b.toFraction=function(t){var n,e,i,o,r,s,a,u,c,l,m,d,f=this,h=f.d,p=f.constructor;if(!h)return new p(f);if(c=e=new p(1),i=u=new p(0),n=new p(i),r=n.e=hn(h)-f.e-1,s=r%M,n.d[0]=_(10,s<0?M+s:s),t==null)t=r>0?n:c;else{if(a=new p(t),!a.isInt()||a.lt(c))throw Error(me+a);t=a.gt(n)?r>0?n:c:a}for(C=!1,a=new p(G(h)),l=p.precision,p.precision=r=h.length*M*2;m=E(a,n,0,1,1),o=e.plus(m.times(i)),o.cmp(t)!=1;)e=i,i=o,o=c,c=u.plus(m.times(o)),u=o,o=n,n=a.minus(m.times(o)),a=o;return o=E(t.minus(e),i,0,1,1),u=u.plus(o.times(c)),e=e.plus(o.times(i)),u.s=c.s=f.s,d=E(c,i,r,1).minus(f).abs().cmp(E(u,e,r,1).minus(f).abs())<1?[c,i]:[u,e],p.precision=l,C=!0,d};b.toHexadecimal=b.toHex=function(t,n){return Mt(this,16,t,n)};b.toNearest=function(t,n){var e=this,i=e.constructor;if(e=new i(e),t==null){if(!e.d)return e;t=new i(1),n=i.rounding}else{if(t=new i(t),n===void 0?n=i.rounding:J(n,0,8),!e.d)return t.s?e:t;if(!t.d)return t.s&&(t.s=e.s),t}return t.d[0]?(C=!1,e=E(e,t,0,n,1).times(t),C=!0,k(e)):(t.s=e.s,e=t),e};b.toNumber=function(){return+this};b.toOctal=function(t,n){return Mt(this,8,t,n)};b.toPower=b.pow=function(t){var n,e,i,o,r,s,a=this,u=a.constructor,c=+(t=new u(t));if(!a.d||!t.d||!a.d[0]||!t.d[0])return new u(_(+a,c));if(a=new u(a),a.eq(1))return a;if(i=u.precision,r=u.rounding,t.eq(1))return k(a,i,r);if(n=Z(t.e/M),n>=t.d.length-1&&(e=c<0?-c:c)<=yi)return o=yn(u,a,e,i),t.s<0?new u(1).div(o):k(o,i,r);if(s=a.s,s<0){if(n<t.d.length-1)return new u(NaN);if((t.d[n]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return e=_(+a,c),n=e==0||!isFinite(e)?Z(c*(Math.log("0."+G(a.d))/Math.LN10+a.e+1)):new u(e+"").e,n>u.maxE+1||n<u.minE-1?new u(n>0?s/0:0):(C=!1,u.rounding=a.s=1,e=Math.min(12,(n+"").length),o=Bt(t.times(le(a,i+e)),i),o.d&&(o=k(o,i+5,1),Oe(o.d,i,r)&&(n=i+10,o=k(Bt(t.times(le(a,n+e)),n),n+5,1),+G(o.d).slice(i+1,i+15)+1==1e14&&(o=k(o,i+1,0)))),o.s=s,C=!0,u.rounding=r,k(o,i,r))};b.toPrecision=function(t,n){var e,i=this,o=i.constructor;return t===void 0?e=re(i,i.e<=o.toExpNeg||i.e>=o.toExpPos):(J(t,1,de),n===void 0?n=o.rounding:J(n,0,8),i=k(new o(i),t,n),e=re(i,t<=i.e||i.e<=o.toExpNeg,t)),i.isNeg()&&!i.isZero()?"-"+e:e};b.toSignificantDigits=b.toSD=function(t,n){var e=this,i=e.constructor;return t===void 0?(t=i.precision,n=i.rounding):(J(t,1,de),n===void 0?n=i.rounding:J(n,0,8)),k(new i(e),t,n)};b.toString=function(){var t=this,n=t.constructor,e=re(t,t.e<=n.toExpNeg||t.e>=n.toExpPos);return t.isNeg()&&!t.isZero()?"-"+e:e};b.truncated=b.trunc=function(){return k(new this.constructor(this),this.e+1,1)};b.valueOf=b.toJSON=function(){var t=this,n=t.constructor,e=re(t,t.e<=n.toExpNeg||t.e>=n.toExpPos);return t.isNeg()?"-"+e:e};function G(t){var n,e,i,o=t.length-1,r="",s=t[0];if(o>0){for(r+=s,n=1;n<o;n++)i=t[n]+"",e=M-i.length,e&&(r+=ce(e)),r+=i;s=t[n],i=s+"",e=M-i.length,e&&(r+=ce(e))}else if(s===0)return"0";for(;s%10===0;)s/=10;return r+s}function J(t,n,e){if(t!==~~t||t<n||t>e)throw Error(me+t)}function Oe(t,n,e,i){var o,r,s,a;for(r=t[0];r>=10;r/=10)--n;return--n<0?(n+=M,o=0):(o=Math.ceil((n+1)/M),n%=M),r=_(10,M-n),a=t[o]%r|0,i==null?n<3?(n==0?a=a/100|0:n==1&&(a=a/10|0),s=e<4&&a==99999||e>3&&a==49999||a==5e4||a==0):s=(e<4&&a+1==r||e>3&&a+1==r/2)&&(t[o+1]/r/100|0)==_(10,n-2)-1||(a==r/2||a==0)&&(t[o+1]/r/100|0)==0:n<4?(n==0?a=a/1e3|0:n==1?a=a/100|0:n==2&&(a=a/10|0),s=(i||e<4)&&a==9999||!i&&e>3&&a==4999):s=((i||e<4)&&a+1==r||!i&&e>3&&a+1==r/2)&&(t[o+1]/r/1e3|0)==_(10,n-3)-1,s}function $e(t,n,e){for(var i,o=[0],r,s=0,a=t.length;s<a;){for(r=o.length;r--;)o[r]*=n;for(o[0]+=St.indexOf(t.charAt(s++)),i=0;i<o.length;i++)o[i]>e-1&&(o[i+1]===void 0&&(o[i+1]=0),o[i+1]+=o[i]/e|0,o[i]%=e)}return o.reverse()}function wi(t,n){var e,i,o;if(n.isZero())return n;i=n.d.length,i<32?(e=Math.ceil(i/3),o=(1/ot(4,e)).toString()):(e=16,o="2.3283064365386962890625e-10"),t.precision+=e,n=Pe(t,1,n.times(o),new t(1));for(var r=e;r--;){var s=n.times(n);n=s.times(s).minus(s).times(8).plus(1)}return t.precision-=e,n}var E=function(){function t(i,o,r){var s,a=0,u=i.length;for(i=i.slice();u--;)s=i[u]*o+a,i[u]=s%r|0,a=s/r|0;return a&&i.unshift(a),i}function n(i,o,r,s){var a,u;if(r!=s)u=r>s?1:-1;else for(a=u=0;a<r;a++)if(i[a]!=o[a]){u=i[a]>o[a]?1:-1;break}return u}function e(i,o,r,s){for(var a=0;r--;)i[r]-=a,a=i[r]<o[r]?1:0,i[r]=a*s+i[r]-o[r];for(;!i[0]&&i.length>1;)i.shift()}return function(i,o,r,s,a,u){var c,l,m,d,f,h,p,w,y,T,g,P,A,B,v,x,R,F,L,H,W=i.constructor,j=i.s==o.s?1:-1,D=i.d,O=o.d;if(!D||!D[0]||!O||!O[0])return new W(!i.s||!o.s||(D?O&&D[0]==O[0]:!O)?NaN:D&&D[0]==0||!O?j*0:j/0);for(u?(f=1,l=i.e-o.e):(u=te,f=M,l=Z(i.e/f)-Z(o.e/f)),L=O.length,R=D.length,y=new W(j),T=y.d=[],m=0;O[m]==(D[m]||0);m++);if(O[m]>(D[m]||0)&&l--,r==null?(B=r=W.precision,s=W.rounding):a?B=r+(i.e-o.e)+1:B=r,B<0)T.push(1),h=!0;else{if(B=B/f+2|0,m=0,L==1){for(d=0,O=O[0],B++;(m<R||d)&&B--;m++)v=d*u+(D[m]||0),T[m]=v/O|0,d=v%O|0;h=d||m<R}else{for(d=u/(O[0]+1)|0,d>1&&(O=t(O,d,u),D=t(D,d,u),L=O.length,R=D.length),x=L,g=D.slice(0,L),P=g.length;P<L;)g[P++]=0;H=O.slice(),H.unshift(0),F=O[0],O[1]>=u/2&&++F;do d=0,c=n(O,g,L,P),c<0?(A=g[0],L!=P&&(A=A*u+(g[1]||0)),d=A/F|0,d>1?(d>=u&&(d=u-1),p=t(O,d,u),w=p.length,P=g.length,c=n(p,g,w,P),c==1&&(d--,e(p,L<w?H:O,w,u))):(d==0&&(c=d=1),p=O.slice()),w=p.length,w<P&&p.unshift(0),e(g,p,P,u),c==-1&&(P=g.length,c=n(O,g,L,P),c<1&&(d++,e(g,L<P?H:O,P,u))),P=g.length):c===0&&(d++,g=[0]),T[m++]=d,c&&g[0]?g[P++]=D[x]||0:(g=[D[x]],P=1);while((x++<R||g[0]!==void 0)&&B--);h=g[0]!==void 0}T[0]||T.shift()}if(f==1)y.e=l,mn=h;else{for(m=1,d=T[0];d>=10;d/=10)m++;y.e=m+l*f-1,k(y,a?r+y.e+1:r,s,h)}return y}}();function k(t,n,e,i){var o,r,s,a,u,c,l,m,d,f=t.constructor;e:if(n!=null){if(m=t.d,!m)return t;for(o=1,a=m[0];a>=10;a/=10)o++;if(r=n-o,r<0)r+=M,s=n,l=m[d=0],u=l/_(10,o-s-1)%10|0;else if(d=Math.ceil((r+1)/M),a=m.length,d>=a)if(i){for(;a++<=d;)m.push(0);l=u=0,o=1,r%=M,s=r-M+1}else break e;else{for(l=a=m[d],o=1;a>=10;a/=10)o++;r%=M,s=r-M+o,u=s<0?0:l/_(10,o-s-1)%10|0}if(i=i||n<0||m[d+1]!==void 0||(s<0?l:l%_(10,o-s-1)),c=e<4?(u||i)&&(e==0||e==(t.s<0?3:2)):u>5||u==5&&(e==4||i||e==6&&(r>0?s>0?l/_(10,o-s):0:m[d-1])%10&1||e==(t.s<0?8:7)),n<1||!m[0])return m.length=0,c?(n-=t.e+1,m[0]=_(10,(M-n%M)%M),t.e=-n||0):m[0]=t.e=0,t;if(r==0?(m.length=d,a=1,d--):(m.length=d+1,a=_(10,M-r),m[d]=s>0?(l/_(10,o-s)%_(10,s)|0)*a:0),c)for(;;)if(d==0){for(r=1,s=m[0];s>=10;s/=10)r++;for(s=m[0]+=a,a=1;s>=10;s/=10)a++;r!=a&&(t.e++,m[0]==te&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=te)break;m[d--]=0,a=1}for(r=m.length;m[--r]===0;)m.pop()}return C&&(t.e>f.maxE?(t.d=null,t.e=NaN):t.e<f.minE&&(t.e=0,t.d=[0])),t}function re(t,n,e){if(!t.isFinite())return wn(t);var i,o=t.e,r=G(t.d),s=r.length;return n?(e&&(i=e-s)>0?r=r.charAt(0)+"."+r.slice(1)+ce(i):s>1&&(r=r.charAt(0)+"."+r.slice(1)),r=r+(t.e<0?"e":"e+")+t.e):o<0?(r="0."+ce(-o-1)+r,e&&(i=e-s)>0&&(r+=ce(i))):o>=s?(r+=ce(o+1-s),e&&(i=e-o-1)>0&&(r=r+"."+ce(i))):((i=o+1)<s&&(r=r.slice(0,i)+"."+r.slice(i)),e&&(i=e-s)>0&&(o+1===s&&(r+="."),r+=ce(i))),r}function rt(t,n){var e=t[0];for(n*=M;e>=10;e/=10)n++;return n}function nt(t,n,e){if(n>bi)throw C=!0,e&&(t.precision=e),Error(dn);return k(new t(et),n,1,!0)}function ee(t,n,e){if(n>kt)throw Error(dn);return k(new t(tt),n,e,!0)}function hn(t){var n=t.length-1,e=n*M+1;if(n=t[n],n){for(;n%10==0;n/=10)e--;for(n=t[0];n>=10;n/=10)e++}return e}function ce(t){for(var n="";t--;)n+="0";return n}function yn(t,n,e,i){var o,r=new t(1),s=Math.ceil(i/M+4);for(C=!1;;){if(e%2&&(r=r.times(n),cn(r.d,s)&&(o=!0)),e=Z(e/2),e===0){e=r.d.length-1,o&&r.d[e]===0&&++r.d[e];break}n=n.times(n),cn(n.d,s)}return C=!0,r}function un(t){return t.d[t.d.length-1]&1}function bn(t,n,e){for(var i,o=new t(n[0]),r=0;++r<n.length;)if(i=new t(n[r]),i.s)o[e](i)&&(o=i);else{o=i;break}return o}function Bt(t,n){var e,i,o,r,s,a,u,c=0,l=0,m=0,d=t.constructor,f=d.rounding,h=d.precision;if(!t.d||!t.d[0]||t.e>17)return new d(t.d?t.d[0]?t.s<0?0:1/0:1:t.s?t.s<0?0:t:0/0);for(n==null?(C=!1,u=h):u=n,a=new d(.03125);t.e>-2;)t=t.times(a),m+=5;for(i=Math.log(_(2,m))/Math.LN10*2+5|0,u+=i,e=r=s=new d(1),d.precision=u;;){if(r=k(r.times(t),u,1),e=e.times(++l),a=s.plus(E(r,e,u,1)),G(a.d).slice(0,u)===G(s.d).slice(0,u)){for(o=m;o--;)s=k(s.times(s),u,1);if(n==null)if(c<3&&Oe(s.d,u-i,f,c))d.precision=u+=10,e=r=a=new d(1),l=0,c++;else return k(s,d.precision=h,f,C=!0);else return d.precision=h,s}s=a}}function le(t,n){var e,i,o,r,s,a,u,c,l,m,d,f=1,h=10,p=t,w=p.d,y=p.constructor,T=y.rounding,g=y.precision;if(p.s<0||!w||!w[0]||!p.e&&w[0]==1&&w.length==1)return new y(w&&!w[0]?-1/0:p.s!=1?NaN:w?0:p);if(n==null?(C=!1,l=g):l=n,y.precision=l+=h,e=G(w),i=e.charAt(0),Math.abs(r=p.e)<15e14){for(;i<7&&i!=1||i==1&&e.charAt(1)>3;)p=p.times(t),e=G(p.d),i=e.charAt(0),f++;r=p.e,i>1?(p=new y("0."+e),r++):p=new y(i+"."+e.slice(1))}else return c=nt(y,l+2,g).times(r+""),p=le(new y(i+"."+e.slice(1)),l-h).plus(c),y.precision=g,n==null?k(p,g,T,C=!0):p;for(m=p,u=s=p=E(p.minus(1),p.plus(1),l,1),d=k(p.times(p),l,1),o=3;;){if(s=k(s.times(d),l,1),c=u.plus(E(s,new y(o),l,1)),G(c.d).slice(0,l)===G(u.d).slice(0,l))if(u=u.times(2),r!==0&&(u=u.plus(nt(y,l+2,g).times(r+""))),u=E(u,new y(f),l,1),n==null)if(Oe(u.d,l-h,T,a))y.precision=l+=h,c=s=p=E(m.minus(1),m.plus(1),l,1),d=k(p.times(p),l,1),o=a=1;else return k(u,y.precision=g,T,C=!0);else return y.precision=g,u;u=c,o+=2}}function wn(t){return String(t.s*t.s/0)}function vt(t,n){var e,i,o;for((e=n.indexOf("."))>-1&&(n=n.replace(".","")),(i=n.search(/e/i))>0?(e<0&&(e=i),e+=+n.slice(i+1),n=n.substring(0,i)):e<0&&(e=n.length),i=0;n.charCodeAt(i)===48;i++);for(o=n.length;n.charCodeAt(o-1)===48;--o);if(n=n.slice(i,o),n){if(o-=i,t.e=e=e-i-1,t.d=[],i=(e+1)%M,e<0&&(i+=M),i<o){for(i&&t.d.push(+n.slice(0,i)),o-=M;i<o;)t.d.push(+n.slice(i,i+=M));n=n.slice(i),i=M-n.length}else i-=o;for(;i--;)n+="0";t.d.push(+n),C&&(t.e>t.constructor.maxE?(t.d=null,t.e=NaN):t.e<t.constructor.minE&&(t.e=0,t.d=[0]))}else t.e=0,t.d=[0];return t}function Ti(t,n){var e,i,o,r,s,a,u,c,l;if(n.indexOf("_")>-1){if(n=n.replace(/(\d)_(?=\d)/g,"$1"),gn.test(n))return vt(t,n)}else if(n==="Infinity"||n==="NaN")return+n||(t.s=NaN),t.e=NaN,t.d=null,t;if(gi.test(n))e=16,n=n.toLowerCase();else if(pi.test(n))e=2;else if(hi.test(n))e=8;else throw Error(me+n);for(r=n.search(/p/i),r>0?(u=+n.slice(r+1),n=n.substring(2,r)):n=n.slice(2),r=n.indexOf("."),s=r>=0,i=t.constructor,s&&(n=n.replace(".",""),a=n.length,r=a-r,o=yn(i,new i(e),r,r*2)),c=$e(n,e,te),l=c.length-1,r=l;c[r]===0;--r)c.pop();return r<0?new i(t.s*0):(t.e=rt(c,l),t.d=c,C=!1,s&&(t=E(t,o,a*4)),u&&(t=t.times(Math.abs(u)<54?_(2,u):Le.pow(2,u))),C=!0,t)}function Pi(t,n){var e,i=n.d.length;if(i<3)return n.isZero()?n:Pe(t,2,n,n);e=1.4*Math.sqrt(i),e=e>16?16:e|0,n=n.times(1/ot(5,e)),n=Pe(t,2,n,n);for(var o,r=new t(5),s=new t(16),a=new t(20);e--;)o=n.times(n),n=n.times(r.plus(o.times(s.times(o).minus(a))));return n}function Pe(t,n,e,i,o){var r,s,a,u,c=1,l=t.precision,m=Math.ceil(l/M);for(C=!1,u=e.times(e),a=new t(i);;){if(s=E(a.times(u),new t(n++*n++),l,1),a=o?i.plus(s):i.minus(s),i=E(s.times(u),new t(n++*n++),l,1),s=a.plus(i),s.d[m]!==void 0){for(r=m;s.d[r]===a.d[r]&&r--;);if(r==-1)break}r=a,a=i,i=s,s=r,c++}return C=!0,s.d.length=m+1,s}function ot(t,n){for(var e=t;--n;)e*=t;return e}function Tn(t,n){var e,i=n.s<0,o=ee(t,t.precision,1),r=o.times(.5);if(n=n.abs(),n.lte(r))return oe=i?4:1,n;if(e=n.divToInt(o),e.isZero())oe=i?3:2;else{if(n=n.minus(e.times(o)),n.lte(r))return oe=un(e)?i?2:3:i?4:1,n;oe=un(e)?i?1:4:i?3:2}return n.minus(o).abs()}function Mt(t,n,e,i){var o,r,s,a,u,c,l,m,d,f=t.constructor,h=e!==void 0;if(h?(J(e,1,de),i===void 0?i=f.rounding:J(i,0,8)):(e=f.precision,i=f.rounding),!t.isFinite())l=wn(t);else{for(l=re(t),s=l.indexOf("."),h?(o=2,n==16?e=e*4-3:n==8&&(e=e*3-2)):o=n,s>=0&&(l=l.replace(".",""),d=new f(1),d.e=l.length-s,d.d=$e(re(d),10,o),d.e=d.d.length),m=$e(l,10,o),r=u=m.length;m[--u]==0;)m.pop();if(!m[0])l=h?"0p+0":"0";else{if(s<0?r--:(t=new f(t),t.d=m,t.e=r,t=E(t,d,e,i,0,o),m=t.d,r=t.e,c=mn),s=m[e],a=o/2,c=c||m[e+1]!==void 0,c=i<4?(s!==void 0||c)&&(i===0||i===(t.s<0?3:2)):s>a||s===a&&(i===4||c||i===6&&m[e-1]&1||i===(t.s<0?8:7)),m.length=e,c)for(;++m[--e]>o-1;)m[e]=0,e||(++r,m.unshift(1));for(u=m.length;!m[u-1];--u);for(s=0,l="";s<u;s++)l+=St.charAt(m[s]);if(h){if(u>1)if(n==16||n==8){for(s=n==16?4:3,--u;u%s;u++)l+="0";for(m=$e(l,o,n),u=m.length;!m[u-1];--u);for(s=1,l="1.";s<u;s++)l+=St.charAt(m[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(r<0?"p":"p+")+r}else if(r<0){for(;++r;)l="0"+l;l="0."+l}else if(++r>u)for(r-=u;r--;)l+="0";else r<u&&(l=l.slice(0,r)+"."+l.slice(r))}l=(n==16?"0x":n==2?"0b":n==8?"0o":"")+l}return t.s<0?"-"+l:l}function cn(t,n){if(t.length>n)return t.length=n,!0}function Si(t){return new this(t).abs()}function Ai(t){return new this(t).acos()}function ki(t){return new this(t).acosh()}function Bi(t,n){return new this(t).plus(n)}function vi(t){return new this(t).asin()}function Mi(t){return new this(t).asinh()}function xi(t){return new this(t).atan()}function Ci(t){return new this(t).atanh()}function Ii(t,n){t=new this(t),n=new this(n);var e,i=this.precision,o=this.rounding,r=i+4;return!t.s||!n.s?e=new this(NaN):!t.d&&!n.d?(e=ee(this,r,1).times(n.s>0?.25:.75),e.s=t.s):!n.d||t.isZero()?(e=n.s<0?ee(this,i,o):new this(0),e.s=t.s):!t.d||n.isZero()?(e=ee(this,r,1).times(.5),e.s=t.s):n.s<0?(this.precision=r,this.rounding=1,e=this.atan(E(t,n,r,1)),n=ee(this,r,1),this.precision=i,this.rounding=o,e=t.s<0?e.minus(n):e.plus(n)):e=this.atan(E(t,n,r,1)),e}function Ni(t){return new this(t).cbrt()}function Ri(t){return k(t=new this(t),t.e+1,2)}function Ki(t,n,e){return new this(t).clamp(n,e)}function Oi(t){if(!t||typeof t!="object")throw Error(it+"Object expected");var n,e,i,o=t.defaults===!0,r=["precision",1,de,"rounding",0,8,"toExpNeg",-Te,0,"toExpPos",0,Te,"maxE",0,Te,"minE",-Te,0,"modulo",0,9];for(n=0;n<r.length;n+=3)if(e=r[n],o&&(this[e]=At[e]),(i=t[e])!==void 0)if(Z(i)===i&&i>=r[n+1]&&i<=r[n+2])this[e]=i;else throw Error(me+e+": "+i);if(e="crypto",o&&(this[e]=At[e]),(i=t[e])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[e]=!0;else throw Error(fn);else this[e]=!1;else throw Error(me+e+": "+i);return this}function Li(t){return new this(t).cos()}function Di(t){return new this(t).cosh()}function Pn(t){var n,e,i;function o(r){var s,a,u,c=this;if(!(c instanceof o))return new o(r);if(c.constructor=o,ln(r)){c.s=r.s,C?!r.d||r.e>o.maxE?(c.e=NaN,c.d=null):r.e<o.minE?(c.e=0,c.d=[0]):(c.e=r.e,c.d=r.d.slice()):(c.e=r.e,c.d=r.d?r.d.slice():r.d);return}if(u=typeof r,u==="number"){if(r===0){c.s=1/r<0?-1:1,c.e=0,c.d=[0];return}if(r<0?(r=-r,c.s=-1):c.s=1,r===~~r&&r<1e7){for(s=0,a=r;a>=10;a/=10)s++;C?s>o.maxE?(c.e=NaN,c.d=null):s<o.minE?(c.e=0,c.d=[0]):(c.e=s,c.d=[r]):(c.e=s,c.d=[r]);return}else if(r*0!==0){r||(c.s=NaN),c.e=NaN,c.d=null;return}return vt(c,r.toString())}else if(u!=="string")throw Error(me+r);return(a=r.charCodeAt(0))===45?(r=r.slice(1),c.s=-1):(a===43&&(r=r.slice(1)),c.s=1),gn.test(r)?vt(c,r):Ti(c,r)}if(o.prototype=b,o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.EUCLID=9,o.config=o.set=Oi,o.clone=Pn,o.isDecimal=ln,o.abs=Si,o.acos=Ai,o.acosh=ki,o.add=Bi,o.asin=vi,o.asinh=Mi,o.atan=xi,o.atanh=Ci,o.atan2=Ii,o.cbrt=Ni,o.ceil=Ri,o.clamp=Ki,o.cos=Li,o.cosh=Di,o.div=Ei,o.exp=Fi,o.floor=qi,o.hypot=Ui,o.ln=_i,o.log=Wi,o.log10=Gi,o.log2=Vi,o.max=Hi,o.min=zi,o.mod=Zi,o.mul=ji,o.pow=Yi,o.random=Xi,o.round=Ji,o.sign=Qi,o.sin=$i,o.sinh=er,o.sqrt=tr,o.sub=nr,o.sum=ir,o.tan=rr,o.tanh=or,o.trunc=sr,t===void 0&&(t={}),t&&t.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],n=0;n<i.length;)t.hasOwnProperty(e=i[n++])||(t[e]=this[e]);return o.config(t),o}function Ei(t,n){return new this(t).div(n)}function Fi(t){return new this(t).exp()}function qi(t){return k(t=new this(t),t.e+1,3)}function Ui(){var t,n,e=new this(0);for(C=!1,t=0;t<arguments.length;)if(n=new this(arguments[t++]),n.d)e.d&&(e=e.plus(n.times(n)));else{if(n.s)return C=!0,new this(1/0);e=n}return C=!0,e.sqrt()}function ln(t){return t instanceof Le||t&&t.toStringTag===pn||!1}function _i(t){return new this(t).ln()}function Wi(t,n){return new this(t).log(n)}function Vi(t){return new this(t).log(2)}function Gi(t){return new this(t).log(10)}function Hi(){return bn(this,arguments,"lt")}function zi(){return bn(this,arguments,"gt")}function Zi(t,n){return new this(t).mod(n)}function ji(t,n){return new this(t).mul(n)}function Yi(t,n){return new this(t).pow(n)}function Xi(t){var n,e,i,o,r=0,s=new this(1),a=[];if(t===void 0?t=this.precision:J(t,1,de),i=Math.ceil(t/M),this.crypto)if(crypto.getRandomValues)for(n=crypto.getRandomValues(new Uint32Array(i));r<i;)o=n[r],o>=429e7?n[r]=crypto.getRandomValues(new Uint32Array(1))[0]:a[r++]=o%1e7;else if(crypto.randomBytes){for(n=crypto.randomBytes(i*=4);r<i;)o=n[r]+(n[r+1]<<8)+(n[r+2]<<16)+((n[r+3]&127)<<24),o>=214e7?crypto.randomBytes(4).copy(n,r):(a.push(o%1e7),r+=4);r=i/4}else throw Error(fn);else for(;r<i;)a[r++]=Math.random()*1e7|0;for(i=a[--r],t%=M,i&&t&&(o=_(10,M-t),a[r]=(i/o|0)*o);a[r]===0;r--)a.pop();if(r<0)e=0,a=[0];else{for(e=-1;a[0]===0;e-=M)a.shift();for(i=1,o=a[0];o>=10;o/=10)i++;i<M&&(e-=M-i)}return s.e=e,s.d=a,s}function Ji(t){return k(t=new this(t),t.e+1,this.rounding)}function Qi(t){return t=new this(t),t.d?t.d[0]?t.s:0*t.s:t.s||NaN}function $i(t){return new this(t).sin()}function er(t){return new this(t).sinh()}function tr(t){return new this(t).sqrt()}function nr(t,n){return new this(t).sub(n)}function ir(){var t=0,n=arguments,e=new this(n[t]);for(C=!1;e.s&&++t<n.length;)e=e.plus(n[t]);return C=!0,k(e,this.precision,this.rounding)}function rr(t){return new this(t).tan()}function or(t){return new this(t).tanh()}function sr(t){return k(t=new this(t),t.e+1,1)}b[Symbol.for("nodejs.util.inspect.custom")]=b.toString;b[Symbol.toStringTag]="Decimal";var Le=b.constructor=Pn(At);et=new Le(et);tt=new Le(tt);var Y=Le;function xt(t,n=1,e=[]){let i=[...t];if(n<=0)return e;for(;i.length;)e.push(i.splice(0,n));return e}import{PublicKey as fe}from"@solana/web3.js";var Aa=new fe("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),ka=new fe("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),Ba=new fe("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),va=new fe("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ar=new fe("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),ur=new fe("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),cr=new fe("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2");var Ma={CREATE_CPMM_POOL_PROGRAM:ar,CREATE_CPMM_POOL_AUTH:ur,CREATE_CPMM_POOL_FEE_ACC:cr,FEE_DESTINATION_ID:new fe("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR")};import{PublicKey as Ia}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ka}from"@solana/spl-token";import ne from"bn.js";var De=1e4;function Se(t,n,e,i){if(n===void 0)return{amount:t,fee:void 0,expirationTime:void 0};let o={...n,olderTransferFee:{epoch:BigInt(n.olderTransferFee.epoch),maximumFee:BigInt(n.olderTransferFee.maximumFee),transferFeeBasisPoints:n.olderTransferFee.transferFeeBasisPoints},newerTransferFee:{epoch:BigInt(n.newerTransferFee.epoch),maximumFee:BigInt(n.newerTransferFee.maximumFee),transferFeeBasisPoints:n.newerTransferFee.transferFeeBasisPoints}},r=e.epoch<o.newerTransferFee.epoch?o.olderTransferFee:o.newerTransferFee,s=new ne(r.maximumFee.toString()),a=e.epoch<o.newerTransferFee.epoch?(Number(o.newerTransferFee.epoch)*e.slotsInEpoch-e.absoluteSlot)*400/1e3:void 0;if(i)if(r.transferFeeBasisPoints===De){let u=new ne(r.maximumFee.toString());return{amount:t.add(u),fee:u,expirationTime:a}}else{let u=Ct(t.mul(new ne(De)),new ne(De-r.transferFeeBasisPoints)),c=new ne(r.maximumFee.toString()),l=u.sub(t).gt(c)?t.add(c):u,m=Ct(l.mul(new ne(r.transferFeeBasisPoints)),new ne(De)),d=m.gt(s)?s:m;return{amount:l,fee:d,expirationTime:a}}else{let u=Ct(t.mul(new ne(r.transferFeeBasisPoints)),new ne(De)),c=u.gt(s)?s:u;return{amount:t,fee:c,expirationTime:a}}}function Ct(t,n){let{div:e,mod:i}=t.divmod(n);return i.gt(new ne(0))?e.add(new ne(1)):e}var It=z("Gfx_accountInfo_util");async function Nt(t,n,e){let{batchRequest:i,commitment:o="confirmed",chunkCount:r=100}={batchRequest:!1,...e},s=xt(n,r),a=new Array(s.length).fill([]);if(i){let u=s.map(m=>{let d=t._buildArgs([m.map(f=>f.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:d}}),c=xt(u,10);a=(await(await Promise.all(c.map(async m=>await t._rpcBatchRequest(m)))).flat()).map(m=>(m.error&&It.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${m.error.message}`),m.result.value.map(d=>{if(d){let{data:f,executable:h,lamports:p,owner:w,rentEpoch:y}=d;return f.length!==2&&f[1]!=="base64"&&It.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(f[0],"base64"),executable:h,lamports:p,owner:new Sn(w),rentEpoch:y}}return null})))}else try{a=await Promise.all(s.map(u=>t.getMultipleAccountsInfo(u,o)))}catch(u){u instanceof Error&&It.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${u.message}`)}return a.flat()}async function pr(t,n,e){let i=await Nt(t,n.map(o=>o.pubkey),e);return n.map((o,r)=>({...o,accountInfo:i[r]}))}async function An({connection:t,mints:n,config:e}){var r,s,a;if(n.length===0)return{}