UNPKG

test-raydium-sdk-v2

Version:

An SDK for building applications on top of Raydium.

1 lines 65.6 kB
var dn=Object.defineProperty,bn=Object.defineProperties;var gn=Object.getOwnPropertyDescriptors;var Nt=Object.getOwnPropertySymbols;var yn=Object.prototype.hasOwnProperty,hn=Object.prototype.propertyIsEnumerable;var Lt=(e,t,n)=>t in e?dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ce=(e,t)=>{for(var n in t||(t={}))yn.call(t,n)&&Lt(e,n,t[n]);if(Nt)for(var n of Nt(t))hn.call(t,n)&&Lt(e,n,t[n]);return e},he=(e,t)=>bn(e,gn(t));import Tt from"bn.js";var bi=new Tt(25),gi=new Tt(1e4),wn={4:3,5:3};import{PublicKey as Ln}from"@solana/web3.js";import Et,{isBN as _t}from"bn.js";import{bits as wi,BitStructure as Pi,blob as Pn,Blob as xi,cstr as ki,f32 as Si,f32be as Ni,f64 as Li,f64be as Ti,greedy as Bi,Layout as xn,ns64 as Ai,ns64be as Ii,nu64 as Ei,nu64be as _i,offset as Ki,s16 as vi,s16be as Di,s24 as Wi,s24be as Ci,s32 as Oi,s32be as Ri,s40 as qi,s40be as Vi,s48 as Mi,s48be as Fi,s8 as Ui,seq as kn,struct as ji,Structure as Sn,u16 as Yi,u16be as Zi,u24 as Gi,u24be as Hi,u32 as Qi,u32be as zi,u40 as Xi,u40be as $i,u48 as Ji,u48be as eo,u8 as to,UInt as Nn,union as no,Union as ro,unionLayoutDiscriminator as io,utf8 as oo}from"@solana/buffer-layout";var Qe=xn,Bt=Sn;var At=Nn;var It=kn;var ze=Pn;var De=class extends Qe{constructor(n,r,o){super(n,o);this.blob=ze(n),this.signed=r}decode(n,r=0){let o=new Et(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 Et(n)),this.signed&&(n=n.toTwos(this.span*8)),this.blob.encode(n.toArrayLike(Buffer,"le",this.span),r,o)}};function q(e){return new At(1,e)}function b(e){return new De(8,!1,e)}function z(e){return new De(16,!1,e)}var Xe=class extends Qe{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 E(e){return new Xe(ze(32),t=>new Ln(t),t=>t.toBuffer(),e)}var $e=class extends Bt{decode(t,n){return super.decode(t,n)}};function C(e,t,n){return new $e(e,t,n)}function Ne(e,t,n){let r,o=typeof t=="number"?t:_t(t)?t.toNumber():new Proxy(t,{get(i,s){if(!r){let u=Reflect.get(i,"count");r=_t(u)?u.toNumber():u,Reflect.set(i,"count",r)}return Reflect.get(i,s)},set(i,s,u){return s==="count"&&(r=u),Reflect.set(i,s,u)}});return It(e,o,n)}var Je=C([q("instruction"),b("amountIn"),b("minAmountOut")]),et=C([q("instruction"),b("maxAmountIn"),b("amountOut")]),ko=C([q("instruction"),q("nonce")]),tt=C([q("instruction"),q("nonce"),b("startTime")]),Tn=C([b("status"),b("nonce"),b("maxOrder"),b("depth"),b("baseDecimal"),b("quoteDecimal"),b("state"),b("resetFlag"),b("minSize"),b("volMaxCutRatio"),b("amountWaveRatio"),b("baseLotSize"),b("quoteLotSize"),b("minPriceMultiplier"),b("maxPriceMultiplier"),b("systemDecimalValue"),b("minSeparateNumerator"),b("minSeparateDenominator"),b("tradeFeeNumerator"),b("tradeFeeDenominator"),b("pnlNumerator"),b("pnlDenominator"),b("swapFeeNumerator"),b("swapFeeDenominator"),b("baseNeedTakePnl"),b("quoteNeedTakePnl"),b("quoteTotalPnl"),b("baseTotalPnl"),b("poolOpenTime"),b("punishPcAmount"),b("punishCoinAmount"),b("orderbookToInitTime"),z("swapBaseInAmount"),z("swapQuoteOutAmount"),b("swapBase2QuoteFee"),z("swapQuoteInAmount"),z("swapBaseOutAmount"),b("swapQuote2BaseFee"),E("baseVault"),E("quoteVault"),E("baseMint"),E("quoteMint"),E("lpMint"),E("openOrders"),E("marketId"),E("marketProgramId"),E("targetOrders"),E("withdrawQueue"),E("lpVault"),E("owner"),b("lpReserve"),Ne(b(),3,"padding")]),Bn=C([b("accountType"),b("status"),b("nonce"),b("maxOrder"),b("depth"),b("baseDecimal"),b("quoteDecimal"),b("state"),b("resetFlag"),b("minSize"),b("volMaxCutRatio"),b("amountWaveRatio"),b("baseLotSize"),b("quoteLotSize"),b("minPriceMultiplier"),b("maxPriceMultiplier"),b("systemDecimalsValue"),b("abortTradeFactor"),b("priceTickMultiplier"),b("priceTick"),b("minSeparateNumerator"),b("minSeparateDenominator"),b("tradeFeeNumerator"),b("tradeFeeDenominator"),b("pnlNumerator"),b("pnlDenominator"),b("swapFeeNumerator"),b("swapFeeDenominator"),b("baseNeedTakePnl"),b("quoteNeedTakePnl"),b("quoteTotalPnl"),b("baseTotalPnl"),b("poolOpenTime"),b("punishPcAmount"),b("punishCoinAmount"),b("orderbookToInitTime"),z("swapBaseInAmount"),z("swapQuoteOutAmount"),z("swapQuoteInAmount"),z("swapBaseOutAmount"),b("swapQuote2BaseFee"),b("swapBase2QuoteFee"),E("baseVault"),E("quoteVault"),E("baseMint"),E("quoteMint"),E("lpMint"),E("modelDataAccount"),E("openOrders"),E("marketId"),E("marketProgramId"),E("targetOrders"),E("owner"),Ne(b(),64,"padding")]),nt=C([q("instruction"),b("baseAmountIn"),b("quoteAmountIn"),b("fixedSide")]),rt=C([q("instruction"),b("amountIn")]),So={4:Tn,5:Bn},No=C([b("fee")]);import{PublicKey as ci}from"@solana/web3.js";import{PublicKey as Wt,ComputeBudgetProgram as vo,Transaction as st,TransactionMessage as Co,Keypair as Oo,VersionedTransaction as qo}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Mo}from"@solana/spl-token";import{get as Kt,set as An}from"lodash";import Dt from"dayjs";import In from"dayjs/plugin/utc";Dt.extend(In);var it=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 Dt().utc().format("YYYY/MM/DD HH:mm:ss UTC")}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let 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}},vt={},En={};function F(e){let t=Kt(vt,e);if(!t){let n=Kt(En,e);t=new it({name:e,logLevel:n}),An(vt,e,t)}return t}var ot={CreateAccount:"CreateAccount",InitAccount:"InitAccount",CreateATA:"CreateATA",CloseAccount:"CloseAccount",TransferAmount:"TransferAmount",InitMint:"InitMint",MintTo:"MintTo",InitMarket:"InitMarket",Util1216OwnerClaim:"Util1216OwnerClaim",SetComputeUnitPrice:"SetComputeUnitPrice",SetComputeUnitLimit:"SetComputeUnitLimit",ClmmCreatePool:"ClmmCreatePool",ClmmOpenPosition:"ClmmOpenPosition",ClmmIncreasePosition:"ClmmIncreasePosition",ClmmDecreasePosition:"ClmmDecreasePosition",ClmmClosePosition:"ClmmClosePosition",ClmmSwapBaseIn:"ClmmSwapBaseIn",ClmmSwapBaseOut:"ClmmSwapBaseOut",ClmmInitReward:"ClmmInitReward",ClmmSetReward:"ClmmSetReward",ClmmCollectReward:"ClmmCollectReward",AmmV4Swap:"AmmV4Swap",AmmV4AddLiquidity:"AmmV4AddLiquidity",AmmV4RemoveLiquidity:"AmmV4RemoveLiquidity",AmmV4SimulatePoolInfo:"AmmV4SimulatePoolInfo",AmmV4SwapBaseIn:"AmmV4SwapBaseIn",AmmV4SwapBaseOut:"AmmV4SwapBaseOut",AmmV4CreatePool:"AmmV4CreatePool",AmmV4InitPool:"AmmV4InitPool",AmmV5AddLiquidity:"AmmV5AddLiquidity",AmmV5RemoveLiquidity:"AmmV5RemoveLiquidity",AmmV5SimulatePoolInfo:"AmmV5SimulatePoolInfo",AmmV5SwapBaseIn:"AmmV5SwapBaseIn",AmmV5SwapBaseOut:"AmmV5SwapBaseOut",RouteSwap:"RouteSwap",RouteSwap1:"RouteSwap1",RouteSwap2:"RouteSwap2",FarmV3Deposit:"FarmV3Deposit",FarmV3Withdraw:"FarmV3Withdraw",FarmV3CreateLedger:"FarmV3CreateLedger",FarmV5Deposit:"FarmV5Deposit",FarmV5Withdraw:"FarmV5Withdraw",FarmV5CreateLedger:"FarmV5CreateLedger",FarmV6Deposit:"FarmV6Deposit",FarmV6Withdraw:"FarmV6Withdraw",FarmV6Create:"FarmV6Create",FarmV6Restart:"FarmV6Restart",FarmV6CreatorAddReward:"FarmV6CreatorAddReward",FarmV6CreatorWithdraw:"FarmV6CreatorWithdraw"};var X=F("Raydium_txUtil"),_n=1644;function Kn(e,t){e.length<1&&X.logWithError(`no instructions provided: ${e.toString()}`),t.length<1&&X.logWithError(`no signers provided:, ${t.toString()}`);let n=new st;n.recentBlockhash="11111111111111111111111111111111",n.feePayer=t[0],n.add(...e);try{return Buffer.from(n.serialize({verifySignatures:!1})).toString("base64").length<_n}catch{return!1}}async function Ct(e,t,n,r=!0){let o=new Wt("RaydiumSimuLateTransaction11111111111111111"),i=[],s=new st;s.feePayer=o;for(let a of t)Kn([...s.instructions,a],[o])||(i.push(s),s=new st,s.feePayer=o),s.add(a);s.instructions.length>0&&i.push(s);let u=[];try{if(u=await vn(e,i,r),u.find(a=>a.err!==null))throw Error("rpc simulateTransaction error")}catch(a){a instanceof Error&&X.logWithError("failed to simulate for instructions","RPC_ERROR",{message:a.message})}let c=[];for(let a of u)if(X.debug("simulate result:",a),a.logs){let l=a.logs.filter(m=>m&&m.includes(n));X.debug("filteredLog:",c),l.length||X.logWithError("simulate log not match keyword","keyword",n),c.push(...l)}return c}function Ot(e,t){let n=e.match(/{["\w:,]+}/g);return!n||n.length!==1?X.logWithError(`simulate log fail to match json, keyword: ${t}`):n[0]}function $(e,t){let r=new RegExp(`"${t}":(\\d+)`,"g").exec(e);return!r||r.length!==2?X.logWithError(`simulate log fail to match key", key: ${t}`):r[1]}function Le(e,t){let[n,r]=Wt.findProgramAddressSync(e,t);return{publicKey:n,nonce:r}}async function vn(e,t,n){let r=[];if(n){let o=await e.getLatestBlockhash(),i=[];for(let a of t){a.recentBlockhash=o.blockhash,a.lastValidBlockHeight=o.lastValidBlockHeight;let m=a._compile().serialize(),g=a._serialize(m).toString("base64");i.push(g)}let s=i.map(a=>{let l=e._buildArgs([a],void 0,"base64");return{methodName:"simulateTransaction",args:l}}),u=[],c=20;for(let a=0;a<Math.ceil(s.length/c);a++)u.push(s.slice(a*c,(a+1)*c));r=await(await Promise.all(u.map(async a=>(await e._rpcBatchRequest(a)).map(l=>l.result.value)))).flat()}else try{r=await Promise.all(t.map(async o=>await(await e.simulateTransaction(o)).value))}catch(o){o instanceof Error&&X.logWithError("failed to get info for multiple accounts","RPC_ERROR",{message:o.message})}return r}import{PublicKey as Dn}from"@solana/web3.js";var Wn=F("Raydium_liquidity_serum");function Rt({programId:e,marketId:t}){let n=[t.toBuffer()],r=0,o;for(;r<100;){try{let i=n.concat(Buffer.from([r]),Buffer.alloc(7));o=Dn.createProgramAddressSync(i,e)}catch(i){if(i instanceof TypeError)throw i;r++;continue}return{publicKey:o,nonce:r}}throw Wn.logWithError("unable to find a viable program address nonce","params",{programId:e,marketId:t}),new Error("unable to find a viable program address nonce")}import{PublicKey as Cn}from"@solana/web3.js";var we=new Cn("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),me=5e4,On=C([b("x"),b("y"),b("price")]),Rn=C([b("accountType"),b("status"),b("multiplier"),b("validDataCount"),Ne(On,me,"DataElement")]);function qn(e,t){return[0,me-2]}function Vn(e){return[0,me-2]}function Mn(e){return[0,me-2]}function Fn(e,t,n){let[r,o]=qn(t,n),i=r,s=o,u=0,c=t*e.multiplier/n;for(;i<=s;){if(u=Math.floor((s+i)/2),u===0||u>=me-2)return[u,u,!1];let a=e.DataElement[u].x*e.multiplier/e.DataElement[u].y,l=e.DataElement[u-1].x*e.multiplier/e.DataElement[u-1].y,m=e.DataElement[u+1].x*e.multiplier/e.DataElement[u+1].y;if(c===a)return[u,u,!0];if(c===l)return[u-1,u-1,!0];if(c===m)return[u+1,u+1,!0];if(c<l)s=u-1;else{if(c>l&&c<a)return[u-1,u,!0];if(c>a&&c<m)return[u,u+1,!0];i=u+1}}return[u,u,!1]}function ut(e,t,n){let[r,o,i]=Fn(e,t,n);if(!i)return 0;if(r===o){let s=e.DataElement[r].x;return t*e.multiplier/s}else{let s=e.DataElement[r].x,u=e.DataElement[r].y,c=e.DataElement[o].x,a=e.DataElement[o].y,l=n*(c*u-s*a),m=s*l,p=(c-s)*(t*u-s*n)*a,g=m+p;return t*e.multiplier*l/g}}function le(e,t,n){return t*e.multiplier/n}function qt(e,t,n){return t*n/e.multiplier}function Un(e,t){let[n,r]=Vn(t),o=n,i=r,s=0,u=t;for(;o<i;){if(s=Math.floor((i+o)/2),s<=0||s>me-2)return[s,s,!1];let c=e.DataElement[s].x,a=e.DataElement[s-1].x,l=e.DataElement[s+1].x;if(u===c)return[s,s,!0];if(u===a)return[s-1,s-1,!0];if(u===l)return[s+1,s+1,!0];if(u<a)i=s-1;else{if(u>a&&u<c)return[s-1,s,!0];if(u>c&&u<l)return[s,s+1,!0];o=s+1}}return[s,s,!1]}function jn(e,t){let[n,r]=Mn(t),o=n,i=r,s=0,u=t;for(;o<=i;){if(s=Math.floor((i+o)/2),s<=0||s>=me-2)return[s,s,!1];let c=e.DataElement[s].y,a=e.DataElement[s-1].y,l=e.DataElement[s+1].y;if(u===c)return[s,s,!0];if(u===a)return[s-1,s-1,!0];if(u===l)return[s+1,s+1,!0];if(u<l)o=s+1;else{if(u<a&&u>c)return[s-1,s,!0];if(u<c&&u>l)return[s,s+1,!0];i=s-1}}return[s,s,!1]}function Vt(e,t,n,r){let o=r?t+n:t-n,[i,s,u]=Un(e,o);if(!u)return[0,0,!1,u];if(i===s)return[e.DataElement[s].price,e.DataElement[s].y,!1,u];{let c=e.DataElement[i].x,a=e.DataElement[s].x,l=e.DataElement[i].price,m=e.DataElement[s].price,p=e.DataElement[i].y,g=e.DataElement[s].y;if(t>=c&&t<=a)return r?[m,g,!0,u]:[l,p,!0,u];{let P,y;return r?(P=l+(m-l)*(t-c)/(a-c),y=p-(o-c)*e.multiplier/m):(P=l+(m-l)*(t-c)/(a-c),y=g+(a-o)*e.multiplier/l),[P,y,!1,u]}}}function Yn(e,t,n,r){let o=r?t-n:t+n,[i,s,u]=jn(e,o);if(!u)return[0,0,!1,u];if(i===s)return[e.DataElement[s].price,e.DataElement[s].x,!1,u];{let c=e.DataElement[i].x,a=e.DataElement[s].x,l=e.DataElement[i].price,m=e.DataElement[s].price,p=e.DataElement[i].y,g=e.DataElement[s].y;if(t>=g&&t<=p)return r?[m,a,!0,u]:[l,c,!0,u];{let P,y;return r?(P=l+(m-l)*(p-t)/(p-g),y=c+m*(p-o)/e.multiplier):(P=l+(m-l)*(p-t)/(p-g),y=a-l*(o-g)/e.multiplier),[P,y,!1,u]}}}function Zn(e,t){let n=Vt(e,t,0,!1);return n[3]?n[0]:0}function $o(e,t,n,r){let o=ut(e,t,n),i=le(e,t,o),s=le(e,n,o),u=le(e,r,o),c=!0,[a,l,m,p]=Vt(e,i,u,c);if(!p)return 0;if(m)return r*e.multiplier/a;{let g=s-l;return qt(e,g,o)}}function Jo(e,t,n,r){let o=ut(e,t,n),i=le(e,t,o),s=le(e,n,o),u=le(e,r,o),c=!1,[a,l,m,p]=Yn(e,s,u,c);if(!p)return 0;if(m)return r*a/e.multiplier;{let g=i-l;return qt(e,g,o)}}function Gn(e){let t=Rn.decode(e);return{accountType:t.accountType.toNumber(),status:t.status.toNumber(),multiplier:t.multiplier.toNumber(),validDataCount:t.validDataCount.toNumber(),DataElement:t.DataElement.map(n=>({x:n.x.toNumber(),y:n.y.toNumber(),price:n.price.toNumber()}))}}function es(e,t,n,r){let o=Zn(e,le(e,t,ut(e,t,n)))/e.multiplier;return r?o:1/o}var We=class{constructor({connection:t}){this._layoutData={accountType:0,status:0,multiplier:0,validDataCount:0,DataElement:[]};this.connection=t}get stableModelData(){return this._layoutData}async initStableModelLayout(){if(this._layoutData.validDataCount===0&&this.connection){let t=await this.connection.getAccountInfo(we);t&&(this._layoutData=Gn(t==null?void 0:t.data))}}};import{TOKEN_PROGRAM_ID as Ee,ASSOCIATED_TOKEN_PROGRAM_ID as oi}from"@solana/spl-token";import{PublicKey as N,TransactionInstruction as ne,SystemProgram as kt,SYSVAR_RENT_PUBKEY as si}from"@solana/web3.js";import j from"bn.js";var Pe=9e15,se=1e9,at="0123456789abcdef",Oe="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Re="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ct={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Pe,maxE:Pe,crypto:!1},jt,J,x=!0,Ve="[DecimalError] ",oe=Ve+"Invalid argument: ",Yt=Ve+"Precision limit exceeded",Zt=Ve+"crypto unavailable",Gt="[object Decimal]",V=Math.floor,D=Math.pow,Hn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,Qn=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,zn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ht=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,H=1e7,w=7,Xn=9007199254740991,$n=Oe.length-1,lt=Re.length-1,d={toStringTag:Gt};d.absoluteValue=d.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),h(e)};d.ceil=function(){return h(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(oe+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,u=(e=new i.constructor(e)).d,c=i.s,a=e.s;if(!s||!u)return!c||!a?NaN:c!==a?c:s===u?0:!s^c<0?1:-1;if(!s[0]||!u[0])return s[0]?c:u[0]?-a:0;if(c!==a)return c;if(i.e!==e.e)return i.e>e.e^c<0?1:-1;for(r=s.length,o=u.length,t=0,n=r<o?r:o;t<n;++t)if(s[t]!==u[t])return s[t]>u[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())+w,r.rounding=1,n=Jn(r,Jt(r,n)),r.precision=e,r.rounding=t,h(J==2||J==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,u,c,a,l=this,m=l.constructor;if(!l.isFinite()||l.isZero())return new m(l);for(x=!1,i=l.s*D(l.s*l,1/3),!i||Math.abs(i)==1/0?(n=O(l.d),e=l.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=D(n,1/3),e=V((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 m(n),r.s=l.s):r=new m(i.toString()),s=(e=m.precision)+3;;)if(u=r,c=u.times(u).times(u),a=c.plus(l),r=T(a.plus(l).times(u),a.plus(c),s+2,1),O(u.d).slice(0,s)===(n=O(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(h(u,e+1,0),u.times(u).times(u).eq(l))){r=u;break}s+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(h(r,e+1,1),t=!r.times(r).times(r).eq(l));break}return x=!0,h(r,e,m.rounding,t)};d.decimalPlaces=d.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-V(this.e/w))*w,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};d.dividedBy=d.div=function(e){return T(this,new this.constructor(e))};d.dividedToIntegerBy=d.divToInt=function(e){var t=this,n=t.constructor;return h(T(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 h(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,u=new s(1);if(!i.isFinite())return new s(i.s?1/0:NaN);if(i.isZero())return u;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/Fe(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=xe(s,1,i.times(t),new s(1),!0);for(var c,a=e,l=new s(8);a--;)c=i.times(i),i=u.minus(c.times(l.minus(c.times(l))));return h(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=xe(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/Fe(5,e)),o=xe(i,2,o,o,!0);for(var s,u=new i(5),c=new i(16),a=new i(20);e--;)s=o.times(o),o=o.times(u.plus(s.times(c.times(s).plus(a))))}return i.precision=t,i.rounding=n,h(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,T(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()?G(n,o,i):new n(0):new n(NaN):t.isZero()?G(n,o+4,i).times(.5):(n.precision=o+6,n.rounding=1,t=t.asin(),e=G(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,x=!1,n=n.times(n).minus(1).sqrt().plus(n),x=!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,x=!1,n=n.times(n).plus(1).sqrt().plus(n),x=!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?h(new i(o),e,t,!0):(i.precision=n=r-o.e,o=T(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=G(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,u,c,a=this,l=a.constructor,m=l.precision,p=l.rounding;if(a.isFinite()){if(a.isZero())return new l(a);if(a.abs().eq(1)&&m+4<=lt)return s=G(l,m+4,p).times(.25),s.s=a.s,s}else{if(!a.s)return new l(NaN);if(m+4<=lt)return s=G(l,m+4,p).times(.5),s.s=a.s,s}for(l.precision=u=m+10,l.rounding=1,n=Math.min(28,u/w+2|0),e=n;e;--e)a=a.div(a.times(a).plus(1).sqrt().plus(1));for(x=!1,t=Math.ceil(u/w),r=1,c=a.times(a),s=new l(a),o=a;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)),x=!0,h(s,l.precision=m,l.rounding=p,!0)};d.isFinite=function(){return!!this.d};d.isInteger=d.isInt=function(){return!!this.d&&V(this.e/w)>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,u,c,a=this,l=a.constructor,m=l.precision,p=l.rounding,g=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(n=a.d,a.s<0||!n||!n[0]||a.eq(1))return new l(n&&!n[0]?-1/0:a.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)i=!0;else{for(o=n[0];o%10===0;)o/=10;i=o!==1}if(x=!1,u=m+g,s=ie(a,u),r=t?qe(l,u+10):ie(e,u),c=T(s,r,u,1),Te(c.d,o=m,p))do if(u+=10,s=ie(a,u),r=t?qe(l,u+10):ie(e,u),c=T(s,r,u,1),!i){+O(c.d).slice(o+1,o+15)+1==1e14&&(c=h(c,m+1,0));break}while(Te(c.d,o+=10,p));return x=!0,h(c,m,p)};d.minus=d.sub=function(e){var t,n,r,o,i,s,u,c,a,l,m,p,g=this,P=g.constructor;if(e=new P(e),!g.d||!e.d)return!g.s||!e.s?e=new P(NaN):g.d?e.s=-e.s:e=new P(e.d||g.s!==e.s?g:NaN),e;if(g.s!=e.s)return e.s=-e.s,g.plus(e);if(a=g.d,p=e.d,u=P.precision,c=P.rounding,!a[0]||!p[0]){if(p[0])e.s=-e.s;else if(a[0])e=new P(g);else return new P(c===3?-0:0);return x?h(e,u,c):e}if(n=V(e.e/w),l=V(g.e/w),a=a.slice(),i=l-n,i){for(m=i<0,m?(t=a,i=-i,s=p.length):(t=p,n=l,s=a.length),r=Math.max(Math.ceil(u/w),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=a.length,s=p.length,m=r<s,m&&(s=r),r=0;r<s;r++)if(a[r]!=p[r]){m=a[r]<p[r];break}i=0}for(m&&(t=a,a=p,p=t,e.s=-e.s),s=a.length,r=p.length-s;r>0;--r)a[s++]=0;for(r=p.length;r>i;){if(a[--r]<p[r]){for(o=r;o&&a[--o]===0;)a[o]=H-1;--a[o],a[r]+=H}a[r]-=p[r]}for(;a[--s]===0;)a.pop();for(;a[0]===0;a.shift())--n;return a[0]?(e.d=a,e.e=Me(a,n),x?h(e,u,c):e):new P(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]?h(new r(n),r.precision,r.rounding):(x=!1,r.modulo==9?(t=T(n,e.abs(),0,3,1),t.s*=e.s):t=T(n,e,0,r.modulo,1),t=t.times(e),x=!0,n.minus(t))};d.naturalExponential=d.exp=function(){return mt(this)};d.naturalLogarithm=d.ln=function(){return ie(this)};d.negated=d.neg=function(){var e=new this.constructor(this);return e.s=-e.s,h(e)};d.plus=d.add=function(e){var t,n,r,o,i,s,u,c,a,l,m=this,p=m.constructor;if(e=new p(e),!m.d||!e.d)return!m.s||!e.s?e=new p(NaN):m.d||(e=new p(e.d||m.s===e.s?m:NaN)),e;if(m.s!=e.s)return e.s=-e.s,m.minus(e);if(a=m.d,l=e.d,u=p.precision,c=p.rounding,!a[0]||!l[0])return l[0]||(e=new p(m)),x?h(e,u,c):e;if(i=V(m.e/w),r=V(e.e/w),a=a.slice(),o=i-r,o){for(o<0?(n=a,o=-o,s=l.length):(n=l,r=i,s=a.length),i=Math.ceil(u/w),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=a.length,o=l.length,s-o<0&&(o=s,n=l,l=a,a=n),t=0;o;)t=(a[--o]=a[o]+l[o]+t)/H|0,a[o]%=H;for(t&&(a.unshift(t),++r),s=a.length;a[--s]==0;)a.pop();return e.d=a,e.e=Me(a,r),x?h(e,u,c):e};d.precision=d.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(oe+e);return n.d?(t=Qt(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};d.round=function(){var e=this,t=e.constructor;return h(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())+w,r.rounding=1,n=tr(r,Jt(r,n)),r.precision=e,r.rounding=t,h(J>2?n.neg():n,e,t,!0)):new r(NaN)};d.squareRoot=d.sqrt=function(){var e,t,n,r,o,i,s=this,u=s.d,c=s.e,a=s.s,l=s.constructor;if(a!==1||!u||!u[0])return new l(!a||a<0&&(!u||u[0])?NaN:u?s:1/0);for(x=!1,a=Math.sqrt(+s),a==0||a==1/0?(t=O(u),(t.length+c)%2==0&&(t+="0"),a=Math.sqrt(t),c=V((c+1)/2)-(c<0||c%2),a==1/0?t="5e"+c:(t=a.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),r=new l(t)):r=new l(a.toString()),n=(c=l.precision)+3;;)if(i=r,r=i.plus(T(s,i,n+2,1)).times(.5),O(i.d).slice(0,n)===(t=O(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(h(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")&&(h(r,c+1,1),e=!r.times(r).eq(s));break}return x=!0,h(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=T(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,h(J==2||J==4?n.neg():n,e,t,!0)):new r(NaN)};d.times=d.mul=function(e){var t,n,r,o,i,s,u,c,a,l=this,m=l.constructor,p=l.d,g=(e=new m(e)).d;if(e.s*=l.s,!p||!p[0]||!g||!g[0])return new m(!e.s||p&&!p[0]&&!g||g&&!g[0]&&!p?NaN:!p||!g?e.s/0:e.s*0);for(n=V(l.e/w)+V(e.e/w),c=p.length,a=g.length,c<a&&(i=p,p=g,g=i,s=c,c=a,a=s),i=[],s=c+a,r=s;r--;)i.push(0);for(r=a;--r>=0;){for(t=0,o=c+r;o>r;)u=i[o]+g[r]*p[o-r-1]+t,i[o--]=u%H|0,t=u/H|0;i[o]=(i[o]+t)%H|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=Me(i,n),x?h(e,m.precision,m.rounding):e};d.toBinary=function(e,t){return ft(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:(U(e,0,se),t===void 0?t=r.rounding:U(t,0,8),h(n,e+n.e+1,t))};d.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=Q(r,!0):(U(e,0,se),t===void 0?t=o.rounding:U(t,0,8),r=h(new o(r),e+1,t),n=Q(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=Q(o):(U(e,0,se),t===void 0?t=i.rounding:U(t,0,8),r=h(new i(o),e+o.e+1,t),n=Q(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};d.toFraction=function(e){var t,n,r,o,i,s,u,c,a,l,m,p,g=this,P=g.d,y=g.constructor;if(!P)return new y(g);if(a=n=new y(1),r=c=new y(0),t=new y(r),i=t.e=Qt(P)-g.e-1,s=i%w,t.d[0]=D(10,s<0?w+s:s),e==null)e=i>0?t:a;else{if(u=new y(e),!u.isInt()||u.lt(a))throw Error(oe+u);e=u.gt(t)?i>0?t:a:u}for(x=!1,u=new y(O(P)),l=y.precision,y.precision=i=P.length*w*2;m=T(u,t,0,1,1),o=n.plus(m.times(r)),o.cmp(e)!=1;)n=r,r=o,o=a,a=c.plus(m.times(o)),c=o,o=t,t=u.minus(m.times(o)),u=o;return o=T(e.minus(n),r,0,1,1),c=c.plus(o.times(a)),n=n.plus(o.times(r)),c.s=a.s=g.s,p=T(a,r,i,1).minus(g).abs().cmp(T(c,n,i,1).minus(g).abs())<1?[a,r]:[c,n],y.precision=l,x=!0,p};d.toHexadecimal=d.toHex=function(e,t){return ft(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:U(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]?(x=!1,n=T(n,e,0,t,1).times(e),x=!0,h(n)):(e.s=n.s,n=e),n};d.toNumber=function(){return+this};d.toOctal=function(e,t){return ft(this,8,e,t)};d.toPower=d.pow=function(e){var t,n,r,o,i,s,u=this,c=u.constructor,a=+(e=new c(e));if(!u.d||!e.d||!u.d[0]||!e.d[0])return new c(D(+u,a));if(u=new c(u),u.eq(1))return u;if(r=c.precision,i=c.rounding,e.eq(1))return h(u,r,i);if(t=V(e.e/w),t>=e.d.length-1&&(n=a<0?-a:a)<=Xn)return o=zt(c,u,n,r),e.s<0?new c(1).div(o):h(o,r,i);if(s=u.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),u.e==0&&u.d[0]==1&&u.d.length==1)return u.s=s,u}return n=D(+u,a),t=n==0||!isFinite(n)?V(a*(Math.log("0."+O(u.d))/Math.LN10+u.e+1)):new c(n+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(x=!1,c.rounding=u.s=1,n=Math.min(12,(t+"").length),o=mt(e.times(ie(u,r+n)),r),o.d&&(o=h(o,r+5,1),Te(o.d,r,i)&&(t=r+10,o=h(mt(e.times(ie(u,t+n)),t),t+5,1),+O(o.d).slice(r+1,r+15)+1==1e14&&(o=h(o,r+1,0)))),o.s=s,x=!0,c.rounding=i,h(o,r,i))};d.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=Q(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(U(e,1,se),t===void 0?t=o.rounding:U(t,0,8),r=h(new o(r),e,t),n=Q(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):(U(e,1,se),t===void 0?t=r.rounding:U(t,0,8)),h(new r(n),e,t)};d.toString=function(){var e=this,t=e.constructor,n=Q(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};d.truncated=d.trunc=function(){return h(new this.constructor(this),this.e+1,1)};d.valueOf=d.toJSON=function(){var e=this,t=e.constructor,n=Q(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function O(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=w-r.length,n&&(i+=re(n)),i+=r;s=e[t],r=s+"",n=w-r.length,n&&(i+=re(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function U(e,t,n){if(e!==~~e||e<t||e>n)throw Error(oe+e)}function Te(e,t,n,r){var o,i,s,u;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=w,o=0):(o=Math.ceil((t+1)/w),t%=w),i=D(10,w-t),u=e[o]%i|0,r==null?t<3?(t==0?u=u/100|0:t==1&&(u=u/10|0),s=n<4&&u==99999||n>3&&u==49999||u==5e4||u==0):s=(n<4&&u+1==i||n>3&&u+1==i/2)&&(e[o+1]/i/100|0)==D(10,t-2)-1||(u==i/2||u==0)&&(e[o+1]/i/100|0)==0:t<4?(t==0?u=u/1e3|0:t==1?u=u/100|0:t==2&&(u=u/10|0),s=(r||n<4)&&u==9999||!r&&n>3&&u==4999):s=((r||n<4)&&u+1==i||!r&&n>3&&u+1==i/2)&&(e[o+1]/i/1e3|0)==D(10,t-3)-1,s}function Ce(e,t,n){for(var r,o=[0],i,s=0,u=e.length;s<u;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=at.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/Fe(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=xe(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 T=function(){function e(r,o,i){var s,u=0,c=r.length;for(r=r.slice();c--;)s=r[c]*o+u,r[c]=s%i|0,u=s/i|0;return u&&r.unshift(u),r}function t(r,o,i,s){var u,c;if(i!=s)c=i>s?1:-1;else for(u=c=0;u<i;u++)if(r[u]!=o[u]){c=r[u]>o[u]?1:-1;break}return c}function n(r,o,i,s){for(var u=0;i--;)r[i]-=u,u=r[i]<o[i]?1:0,r[i]=u*s+r[i]-o[i];for(;!r[0]&&r.length>1;)r.shift()}return function(r,o,i,s,u,c){var a,l,m,p,g,P,y,v,L,M,k,W,ge,Y,Se,ue,ae,ye,Z,Ke,ve=r.constructor,He=r.s==o.s?1:-1,R=r.d,B=o.d;if(!R||!R[0]||!B||!B[0])return new ve(!r.s||!o.s||(R?B&&R[0]==B[0]:!B)?NaN:R&&R[0]==0||!B?He*0:He/0);for(c?(g=1,l=r.e-o.e):(c=H,g=w,l=V(r.e/g)-V(o.e/g)),Z=B.length,ae=R.length,L=new ve(He),M=L.d=[],m=0;B[m]==(R[m]||0);m++);if(B[m]>(R[m]||0)&&l--,i==null?(Y=i=ve.precision,s=ve.rounding):u?Y=i+(r.e-o.e)+1:Y=i,Y<0)M.push(1),P=!0;else{if(Y=Y/g+2|0,m=0,Z==1){for(p=0,B=B[0],Y++;(m<ae||p)&&Y--;m++)Se=p*c+(R[m]||0),M[m]=Se/B|0,p=Se%B|0;P=p||m<ae}else{for(p=c/(B[0]+1)|0,p>1&&(B=e(B,p,c),R=e(R,p,c),Z=B.length,ae=R.length),ue=Z,k=R.slice(0,Z),W=k.length;W<Z;)k[W++]=0;Ke=B.slice(),Ke.unshift(0),ye=B[0],B[1]>=c/2&&++ye;do p=0,a=t(B,k,Z,W),a<0?(ge=k[0],Z!=W&&(ge=ge*c+(k[1]||0)),p=ge/ye|0,p>1?(p>=c&&(p=c-1),y=e(B,p,c),v=y.length,W=k.length,a=t(y,k,v,W),a==1&&(p--,n(y,Z<v?Ke:B,v,c))):(p==0&&(a=p=1),y=B.slice()),v=y.length,v<W&&y.unshift(0),n(k,y,W,c),a==-1&&(W=k.length,a=t(B,k,Z,W),a<1&&(p++,n(k,Z<W?Ke:B,W,c))),W=k.length):a===0&&(p++,k=[0]),M[m++]=p,a&&k[0]?k[W++]=R[ue]||0:(k=[R[ue]],W=1);while((ue++<ae||k[0]!==void 0)&&Y--);P=k[0]!==void 0}M[0]||M.shift()}if(g==1)L.e=l,jt=P;else{for(m=1,p=M[0];p>=10;p/=10)m++;L.e=m+l*g-1,h(L,u?i+L.e+1:i,s,P)}return L}}();function h(e,t,n,r){var o,i,s,u,c,a,l,m,p,g=e.constructor;e:if(t!=null){if(m=e.d,!m)return e;for(o=1,u=m[0];u>=10;u/=10)o++;if(i=t-o,i<0)i+=w,s=t,l=m[p=0],c=l/D(10,o-s-1)%10|0;else if(p=Math.ceil((i+1)/w),u=m.length,p>=u)if(r){for(;u++<=p;)m.push(0);l=c=0,o=1,i%=w,s=i-w+1}else break e;else{for(l=u=m[p],o=1;u>=10;u/=10)o++;i%=w,s=i-w+o,c=s<0?0:l/D(10,o-s-1)%10|0}if(r=r||t<0||m[p+1]!==void 0||(s<0?l:l%D(10,o-s-1)),a=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/D(10,o-s):0:m[p-1])%10&1||n==(e.s<0?8:7)),t<1||!m[0])return m.length=0,a?(t-=e.e+1,m[0]=D(10,(w-t%w)%w),e.e=-t||0):m[0]=e.e=0,e;if(i==0?(m.length=p,u=1,p--):(m.length=p+1,u=D(10,w-i),m[p]=s>0?(l/D(10,o-s)%D(10,s)|0)*u:0),a)for(;;)if(p==0){for(i=1,s=m[0];s>=10;s/=10)i++;for(s=m[0]+=u,u=1;s>=10;s/=10)u++;i!=u&&(e.e++,m[0]==H&&(m[0]=1));break}else{if(m[p]+=u,m[p]!=H)break;m[p--]=0,u=1}for(i=m.length;m[--i]===0;)m.pop()}return x&&(e.e>g.maxE?(e.d=null,e.e=NaN):e.e<g.minE&&(e.e=0,e.d=[0])),e}function Q(e,t,n){if(!e.isFinite())return $t(e);var r,o=e.e,i=O(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+re(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+re(-o-1)+i,n&&(r=n-s)>0&&(i+=re(r))):o>=s?(i+=re(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+re(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=re(r))),i}function Me(e,t){var n=e[0];for(t*=w;n>=10;n/=10)t++;return t}function qe(e,t,n){if(t>$n)throw x=!0,n&&(e.precision=n),Error(Yt);return h(new e(Oe),t,1,!0)}function G(e,t,n){if(t>lt)throw Error(Yt);return h(new e(Re),t,n,!0)}function Qt(e){var t=e.length-1,n=t*w+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 re(e){for(var t="";e--;)t+="0";return t}function zt(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/w+4);for(x=!1;;){if(n%2&&(i=i.times(t),Ft(i.d,s)&&(o=!0)),n=V(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),Ft(t.d,s)}return x=!0,i}function Mt(e){return e.d[e.d.length-1]&1}function Xt(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,u,c,a=0,l=0,m=0,p=e.constructor,g=p.rounding,P=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?(x=!1,c=P):c=t,u=new p(.03125);e.e>-2;)e=e.times(u),m+=5;for(r=Math.log(D(2,m))/Math.LN10*2+5|0,c+=r,n=i=s=new p(1),p.precision=c;;){if(i=h(i.times(e),c,1),n=n.times(++l),u=s.plus(T(i,n,c,1)),O(u.d).slice(0,c)===O(s.d).slice(0,c)){for(o=m;o--;)s=h(s.times(s),c,1);if(t==null)if(a<3&&Te(s.d,c-r,g,a))p.precision=c+=10,n=i=u=new p(1),l=0,a++;else return h(s,p.precision=P,g,x=!0);else return p.precision=P,s}s=u}}function ie(e,t){var n,r,o,i,s,u,c,a,l,m,p,g=1,P=10,y=e,v=y.d,L=y.constructor,M=L.rounding,k=L.precision;if(y.s<0||!v||!v[0]||!y.e&&v[0]==1&&v.length==1)return new L(v&&!v[0]?-1/0:y.s!=1?NaN:v?0:y);if(t==null?(x=!1,l=k):l=t,L.precision=l+=P,n=O(v),r=n.charAt(0),Math.abs(i=y.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)y=y.times(e),n=O(y.d),r=n.charAt(0),g++;i=y.e,r>1?(y=new L("0."+n),i++):y=new L(r+"."+n.slice(1))}else return a=qe(L,l+2,k).times(i+""),y=ie(new L(r+"."+n.slice(1)),l-P).plus(a),L.precision=k,t==null?h(y,k,M,x=!0):y;for(m=y,c=s=y=T(y.minus(1),y.plus(1),l,1),p=h(y.times(y),l,1),o=3;;){if(s=h(s.times(p),l,1),a=c.plus(T(s,new L(o),l,1)),O(a.d).slice(0,l)===O(c.d).slice(0,l))if(c=c.times(2),i!==0&&(c=c.plus(qe(L,l+2,k).times(i+""))),c=T(c,new L(g),l,1),t==null)if(Te(c.d,l-P,M,u))L.precision=l+=P,a=s=y=T(m.minus(1),m.plus(1),l,1),p=h(y.times(y),l,1),o=u=1;else return h(c,L.precision=k,M,x=!0);else return L.precision=k,c;c=a,o+=2}}function $t(e){return String(e.s*e.s/0)}function pt(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)%w,n<0&&(r+=w),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=w;r<o;)e.d.push(+t.slice(r,r+=w));t=t.slice(r),r=w-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),x&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function er(e,t){var n,r,o,i,s,u,c,a,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),Ht.test(t))return pt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(Qn.test(t))n=16,t=t.toLowerCase();else if(Hn.test(t))n=2;else if(zn.test(t))n=8;else throw Error(oe+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(".",""),u=t.length,i=u-i,o=zt(r,new r(n),i,i*2)),a=Ce(t,n,H),l=a.length-1,i=l;a[i]===0;--i)a.pop();return i<0?new r(e.s*0):(e.e=Me(a,l),e.d=a,x=!1,s&&(e=T(e,o,u*4)),c&&(e=e.times(Math.abs(c)<54?D(2,c):Ue.pow(2,c))),x=!0,e)}function tr(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:xe(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/Fe(5,n)),t=xe(e,2,t,t);for(var o,i=new e(5),s=new e(16),u=new e(20);n--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(u))));return t}function xe(e,t,n,r,o){var i,s,u,c,a=1,l=e.precision,m=Math.ceil(l/w);for(x=!1,c=n.times(n),u=new e(r);;){if(s=T(u.times(c),new e(t++*t++),l,1),u=o?r.plus(s):r.minus(s),r=T(s.times(c),new e(t++*t++),l,1),s=u.plus(r),s.d[m]!==void 0){for(i=m;s.d[i]===u.d[i]&&i--;);if(i==-1)break}i=u,u=r,r=s,s=i,a++}return x=!0,s.d.length=m+1,s}function Fe(e,t){for(var n=e;--t;)n*=e;return n}function Jt(e,t){var n,r=t.s<0,o=G(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return J=r?4:1,t;if(n=t.divToInt(o),n.isZero())J=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return J=Mt(n)?r?2:3:r?4:1,t;J=Mt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function ft(e,t,n,r){var o,i,s,u,c,a,l,m,p,g=e.constructor,P=n!==void 0;if(P?(U(n,1,se),r===void 0?r=g.rounding:U(r,0,8)):(n=g.precision,r=g.rounding),!e.isFinite())l=$t(e);else{for(l=Q(e),s=l.indexOf("."),P?(o=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):o=t,s>=0&&(l=l.replace(".",""),p=new g(1),p.e=l.length-s,p.d=Ce(Q(p),10,o),p.e=p.d.length),m=Ce(l,10,o),i=c=m.length;m[--c]==0;)m.pop();if(!m[0])l=P?"0p+0":"0";else{if(s<0?i--:(e=new g(e),e.d=m,e.e=i,e=T(e,p,n,r,0,o),m=e.d,i=e.e,a=jt),s=m[n],u=o/2,a=a||m[n+1]!==void 0,a=r<4?(s!==void 0||a)&&(r===0||r===(e.s<0?3:2)):s>u||s===u&&(r===4||a||r===6&&m[n-1]&1||r===(e.s<0?8:7)),m.length=n,a)for(;++m[--n]>o-1;)m[n]=0,n||(++i,m.unshift(1));for(c=m.length;!m[c-1];--c);for(s=0,l="";s<c;s++)l+=at.charAt(m[s]);if(P){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(m=Ce(l,o,t),c=m.length;!m[c-1];--c);for(s=1,l="1.";s<c;s++)l+=at.charAt(m[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 Ft(e,t){if(e.length>t)return e.length=t,!0}function nr(e){return new this(e).abs()}function rr(e){return new this(e).acos()}function ir(e){return new this(e).acosh()}function or(e,t){return new this(e).plus(t)}function sr(e){return new this(e).asin()}function ur(e){return new this(e).asinh()}function ar(e){return new this(e).atan()}function cr(e){return new this(e).atanh()}function lr(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=G(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?G(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=G(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(T(e,t,i,1)),t=G(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(T(e,t,i,1)),n}function mr(e){return new this(e).cbrt()}function pr(e){return h(e=new this(e),e.e+1,2)}function fr(e,t,n){return new this(e).clamp(t,n)}function dr(e){if(!e||typeof e!="object")throw Error(Ve+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,se,"rounding",0,8,"toExpNeg",-Pe,0,"toExpPos",0,Pe,"maxE",0,Pe,"minE",-Pe,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=ct[n]),(r=e[n])!==void 0)if(V(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(oe+n+": "+r);if(n="crypto",o&&(this[n]=ct[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(Zt);else this[n]=!1;else throw Error(oe+n+": "+r);return this}function br(e){return new this(e).cos()}function gr(e){return new this(e).cosh()}function en(e){var t,n,r;function o(i){var s,u,c,a=this;if(!(a instanceof o))return new o(i);if(a.constructor=o,Ut(i)){a.s=i.s,x?!i.d||i.e>o.maxE?(a.e=NaN,a.d=null):i.e<o.minE?(a.e=0,a.d=[0]):(a.e=i.e,a.d=i.d.slice()):(a.e=i.e,a.d=i.d?i.d.slice():i.d);return}if(c=typeof i,c==="number"){if(i===0){a.s=1/i<0?-1:1,a.e=0,a.d=[0];return}if(i<0?(i=-i,a.s=-1):a.s=1,i===~~i&&i<1e7){for(s=0,u=i;u>=10;u/=10)s++;x?s>o.maxE?(a.e=NaN,a.d=null):s<o.minE?(a.e=0,a.d=[0]):(a.e=s,a.d=[i]):(a.e=s,a.d=[i]);return}else if(i*0!==0){i||(a.s=NaN),a.e=NaN,a.d=null;return}return pt(a,i.toString())}else if(c!=="string")throw Error(oe+i);return(u=i.charCodeAt(0))===45?(i=i.slice(1),a.s=-1):(u===43&&(i=i.slice(1)),a.s=1),Ht.test(i)?pt(a,i):er(a,i)}if(o.prototype=d,o.ROUND_UP=0,o.ROUND_DOWN=1,o.ROUND_CEIL=2,o.ROUND_FLOOR=3,o.ROUND_HALF_UP=4,o.ROUND_HALF_DOWN=5,o.ROUND_HALF_EVEN=6,o.ROUND_HALF_CEIL=7,o.ROUND_HALF_FLOOR=8,o.EUCLID=9,o.config=o.set=dr,o.clone=en,o.isDecimal=Ut,o.abs=nr,o.acos=rr,o.acosh=ir,o.add=or,o.asin=sr,o.asinh=ur,o.atan=ar,o.atanh=cr,o.atan2=lr,o.cbrt=mr,o.ceil=pr,o.clamp=fr,o.cos=br,o.cosh=gr,o.div=yr,o.exp=hr,o.floor=wr,o.hypot=Pr,o.ln=xr,o.log=kr,o.log10=Nr,o.log2=Sr,o.max=Lr,o.min=Tr,o.mod=Br,o.mul=Ar,o.pow=Ir,o.random=Er,o.round=_r,o.sign=Kr,o.sin=vr,o.sinh=Dr,o.sqrt=Wr,o.sub=Cr,o.sum=Or,o.tan=Rr,o.tanh=qr,o.trunc=Vr,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 yr(e,t){return new this(e).div(t)}function hr(e){return new this(e).exp()}function wr(e){return h(e=new this(e),e.e+1,3)}function Pr(){var e,t,n=new this(0);for(x=!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 x=!0,new this(1/0);n=t}return x=!0,n.sqrt()}function Ut(e){return e instanceof Ue||e&&e.toStringTag===Gt||!1}function xr(e){return new this(e).ln()}function kr(e,t){return new this(e).log(t)}function Sr(e){return new this(e).log(2)}function Nr(e){return new this(e).log(10)}function Lr(){return Xt(this,arguments,"lt")}function Tr(){return Xt(this,arguments,"gt")}function Br(e,t){return new this(e).mod(t)}function Ar(e,t){return new this(e).mul(t)}function Ir(e,t){return new this(e).pow(t)}function Er(e){var t,n,r,o,i=0,s=new this(1),u=[];if(e===void 0?e=this.precision:U(e,1,se),r=Math.ceil(e/w),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]:u[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):(u.push(o%1e7),i+=4);i=r/4}else throw Error(Zt);else for(;i<r;)u[i++]=Math.random()*1e7|0;for(r=u[--i],e%=w,r&&e&&(o=D(10,w-e),u[i]=(r/o|0)*o);u[i]===0;i--)u.pop();if(i<0)n=0,u=[0];else{for(n=-1;u[0]===0;n-=w)u.shift();for(r=1,o=u[0];o>=10;o/=10)r++;r<w&&(n-=w-r)}return s.e=n,s.d=u,s}function _r(e){return h(e=new this(e),e.e+1,this.rounding)}function Kr(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function vr(e){return new this(e).sin()}function Dr(e){return new this(e).sinh()}function Wr(e){return new this(e).sqrt()}function Cr(e,t){return new this(e).sub(t)}function Or(){var e=0,t=arguments,n=new this(t[e]);for(x=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return x=!0,h(n,this.precision,this.rounding)}function Rr(e){return new this(e).tan()}function qr(e){return new this(e).tanh()}function Vr(e){return h(e=new this(e),e.e+1,1)}d[Symbol.for("nodejs.util.inspect.custom")]=d.toString;d[Symbol.toStringTag]="Decimal";var Ue=d.constructor=en(ct);Oe=new Ue(Oe);Re=new Ue(Re);import{PublicKey as bt}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Mr}from"@solana/spl-token";import{PublicKey as _,SystemProgram as Fr,SYSVAR_RENT_PUBKEY as Ur}from"@solana/web3.js";function f({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var ss=[f({pubkey:Mr,isWritable:!1}),f({pubkey:Fr.programId,isWritable:!1}),f({pubkey:Ur,isWritable:!1})];function nn({publicKey:e,transformSol:t}){let n=dt(e.toString());if(n instanceof _)return t&&n.equals(Be)?tn:n;if(t&&n.toString()===Be.toBase58())return tn;if(typeof n=="string"){if(n===_.default.toBase58())return _.default;try{return new _(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function dt(e){try{return new _(e)}catch{return e}}var us=new _("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),rn=new _("SysvarRent111111111111111111111111111111111"),as=new _("SysvarC1ock11111111111111111111111111111111"),cs=new _("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),ls=new _("Sysvar1nstructions1111111111111111111111111"),ms=new _("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),ps=new _("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),fs=new _("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),ds=new _("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),bs=new _("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),gs=new _("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),ys=new _("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),hs=new _("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),ws=new _("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Ps=new _("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),xs=new _("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),tn=new _("So11111111111111111111111111111111111111112"),Be=_.default;import{PublicKey as jr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as on}from"@solana/spl-token";var sn={chainId:101,address:jr.default.toBase58(),programId:on.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},pe={chainId:101,address:"So11111111111111111111111111111111111111112",programId:on.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};var gt=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1}){if(t===Be.toBase58()||t instanceof bt&&Be.equals(t)){this.decimals=pe.decimals,this.symbol=pe.symbol,this.name=pe.name,this.mint=new bt(pe.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?bt.default:nn({publicKey:t}),this.isToken2022=s}equals(t){return this===t?!0:this.mint.equals(t.mint)}},fe=gt;fe.WSOL=new gt(he(ce({},pe),{mint:pe.address}));import Ye from"big.js";import Gr from"bn.js";import Hr from"decimal.js-light";import Yr from"toformat";var Zr=Yr,Ae=Zr;var je=F("module/fraction"),yt=Ae(Ye),Ie=Ae(Hr),Qr={[0]:Ie.ROUND_DOWN,[1]:Ie.ROUND_HALF_UP,[2]:Ie.ROUND_UP},zr={[0]:Ye.roundDown,[1]:Ye.roundHalfUp,[2]:Ye.roundUp},S=class{constructor(t,n=new Gr(1)){this.numerator=K(t),this.denominator=K(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new S(this.denominator,t