goosefx-amm-sdk
Version:
SDK for the GooseFx AMM
1 lines • 141 kB
JavaScript
"use strict";var zn=Object.create;var Je=Object.defineProperty;var Zn=Object.getOwnPropertyDescriptor;var jn=Object.getOwnPropertyNames;var Yn=Object.getPrototypeOf,Xn=Object.prototype.hasOwnProperty;var Jn=(e,n)=>{for(var t in n)Je(e,t,{get:n[t],enumerable:!0})},jt=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of jn(n))!Xn.call(e,o)&&o!==t&&Je(e,o,{get:()=>n[o],enumerable:!(i=Zn(n,o))||i.enumerable});return e};var V=(e,n,t)=>(t=e!=null?zn(Yn(e)):{},jt(n||!e||!e.__esModule?Je(t,"default",{value:e,enumerable:!0}):t,e)),Qn=e=>jt(Je({},"__esModule",{value:!0}),e);var Cr={};Jn(Cr,{default:()=>gt});module.exports=Qn(Cr);var S=require("@solana/web3.js"),oe=require("@solana/spl-token");var tn=V(require("big.js")),ri=V(require("bn.js"));var J=V(require("bn.js"));var Ne=require("lodash");var yt=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 t=n.map(i=>typeof i=="object"?JSON.stringify(i):i).join(", ");throw new Error(t)}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}},Yt={},$n={};function Z(e){let n=(0,Ne.get)(Yt,e);if(!n){let t=(0,Ne.get)($n,e);n=new yt({name:e,logLevel:t}),(0,Ne.set)(Yt,e,n)}return n}var Qe=new J.default(0),Kr=new J.default(1),Or=new J.default(2),Lr=new J.default(3),Dr=new J.default(5),Jt=new J.default(10),Er=new J.default(100),Fr=new J.default(1e3),qr=new J.default(1e4),Xt=9007199254740991;function le(e){let n=Z("Gfx_parseBigNumberish");if(e instanceof J.default)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new J.default(e);n.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&n.logWithError(`BigNumberish number underflow: ${e}`),(e>=Xt||e<=-Xt)&&n.logWithError(`BigNumberish number overflow: ${e}`),new J.default(String(e))):typeof e=="bigint"?new J.default(e.toString()):(n.error(`invalid BigNumberish value: ${e}`),new J.default(0))}var Qt=V(require("toformat")),ei=Qt.default,Re=ei;var Ke=V(require("big.js")),$t=V(require("bn.js")),en=V(require("decimal.js-light"));var $e=Z("module/fraction"),bt=Re(Ke.default),Oe=Re(en.default),ni={[0]:Oe.ROUND_DOWN,[1]:Oe.ROUND_HALF_UP,[2]:Oe.ROUND_UP},ii={[0]:Ke.default.roundDown,[1]:Ke.default.roundHalfUp,[2]:Ke.default.roundUp},U=class{constructor(n,t=new $t.default(1)){this.numerator=le(n),this.denominator=le(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new U(this.denominator,this.numerator)}add(n){let t=n instanceof U?n:new U(le(n));return this.denominator.eq(t.denominator)?new U(this.numerator.add(t.numerator),this.denominator):new U(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(n){let t=n instanceof U?n:new U(le(n));return this.denominator.eq(t.denominator)?new U(this.numerator.sub(t.numerator),this.denominator):new U(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(n){let t=n instanceof U?n:new U(le(n));return new U(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(n){let t=n instanceof U?n:new U(le(n));return new U(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(n,t={groupSeparator:""},i=1){Number.isInteger(n)||$e.logWithError(`${n} is not an integer.`),n<=0&&$e.logWithError(`${n} is not positive.`),Oe.set({precision:n+1,rounding:ni[i]});let o=new Oe(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(n);return o.toFormat(o.decimalPlaces(),t)}toFixed(n,t={groupSeparator:""},i=1){return Number.isInteger(n)||$e.logWithError(`${n} is not an integer.`),n<0&&$e.logWithError(`${n} is negative.`),bt.DP=n,bt.RM=ii[i]||1,new bt(this.numerator.toString()).div(this.denominator.toString()).toFormat(n,t)}isZero(){return this.numerator.isZero()}};var to=Z("Gfx_amount"),no=Re(tn.default);var wt=require("@solana/spl-token"),ke={address:"So11111111111111111111111111111111111111112",programId:wt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"",tags:[],priority:2,type:"goose-fx",extensions:{coingeckoId:"solana"}},me={address:"So11111111111111111111111111111111111111112",programId:wt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"",tags:[],priority:2,type:"goose-fx",extensions:{coingeckoId:"solana"}};var tt=require("@solana/web3.js");var nn=require("@solana/spl-token"),L=require("@solana/web3.js");function Tt({pubkey:e,isSigner:n=!1,isWritable:t=!0}){return{pubkey:e,isWritable:t,isSigner:n}}var so=[Tt({pubkey:nn.TOKEN_PROGRAM_ID,isWritable:!1}),Tt({pubkey:L.SystemProgram.programId,isWritable:!1}),Tt({pubkey:L.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Pt({publicKey:e,transformSol:n}){let t=rn(e.toString());if(t instanceof L.PublicKey)return n&&t.equals(Le)?te:t;if(n&&t.toString()===Le.toBase58())return te;if(typeof t=="string"){if(t===L.PublicKey.default.toBase58())return L.PublicKey.default;try{return new L.PublicKey(t)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function rn(e){try{return new L.PublicKey(e)}catch{return e}}var ao=new L.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),uo=new L.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),co=new L.PublicKey("SysvarRent111111111111111111111111111111111"),lo=new L.PublicKey("SysvarC1ock11111111111111111111111111111111"),mo=new L.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),fo=new L.PublicKey("Sysvar1nstructions1111111111111111111111111"),po=L.SystemProgram.programId,go=new L.PublicKey("4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R"),ho=new L.PublicKey("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),yo=new L.PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),bo=new L.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),wo=new L.PublicKey("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),To=new L.PublicKey("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Po=new L.PublicKey("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),So=new L.PublicKey("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ao=new L.PublicKey("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),ko=new L.PublicKey("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Bo=new L.PublicKey("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),te=new L.PublicKey("So11111111111111111111111111111111111111112"),Le=L.PublicKey.default;function et(e){return Pt({publicKey:e,transformSol:!0})}var St=class{constructor({mint:n,decimals:t,symbol:i,name:o,skipMint:r=!1,isToken2022:s=!1}){if(n===Le.toBase58()||n instanceof tt.PublicKey&&Le.equals(n)){this.decimals=me.decimals,this.symbol=me.symbol,this.name=me.name,this.mint=new tt.PublicKey(me.address),this.isToken2022=!1;return}this.decimals=t,this.symbol=i||n.toString().substring(0,6),this.name=o||n.toString().substring(0,6),this.mint=r?tt.PublicKey.default:Pt({publicKey:n}),this.isToken2022=s}equals(n){return this===n?!0:this.mint.equals(n.mint)}},we=St;we.WSOL=new St({...me,mint:me.address});var At=class{constructor({decimals:n,symbol:t="UNKNOWN",name:i="UNKNOWN"}){this.decimals=n,this.symbol=t,this.name=i}equals(n){return this===n}},nt=At;nt.SOL=new At(ke);var sn=V(require("bn.js"));var on=new U(new sn.default(100)),se=class extends U{toSignificant(n=5,t,i){return this.mul(on).toSignificant(n,t,i)}toFixed(n=2,t,i){return this.mul(on).toFixed(n,t,i)}};var Wo=Z("Ray_price");var ne={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"};var vt=V(require("bn.js"));var G=V(require("bn.js")),Te=V(require("decimal.js-light"));var it=V(require("bn.js")),De=new it.default(0);function kt(e,n){if(n.isZero())throw Error("divisor is zero");return e.mod(n)}function Ee(e,n){if(n.isZero())throw Error("rhs is zero");let t=e.div(n);return t.isZero()?[t,n]:e.sub(t.mul(n)).isZero()?[t,n]:[t.add(new it.default(1)),n]}function rt(e,n){return e.gt(n)?e.sub(n):new it.default(0)}var oi=new G.default(100),Fe=new G.default(1e6),si=100,ai=new G.default(3600),an=new G.default(1e5),ui=new G.default(3e5),qe=class{static calculateDynamicFee(n,t,i,o,r,s,a){let u=this.calculateDynamicFeeRate(t,i,o,r,s,a),[c,l]=Ee(n.mul(u),Fe);return c}static calculatePreDynamicFee(n,t,i,o,r,s,a){let u=this.calculateDynamicFeeRate(t,i,o,r,s,a);if(u.isZero())return n;let c=Fe.sub(u);if(c.isZero())throw new Error("Fee rate equals denominator, causing division by zero");return n.mul(Fe).add(c).sub(new G.default(1)).div(c)}static calculateDynamicFeeRate(n,t,i,o,r,s){switch(i){case"volatility":return this.calculateVolatileFee(n,t,o,r,s)}}static calculateVolatileFee(n,t,i,o,r){let{minPrice:s,maxPrice:a,twapPrice:u}=this.getPriceRange(t,n,ai);if(s.eqn(0)||a.eqn(0)||u.eqn(0)||u.eqn(1))return i;let c=new Te.default(a.toString()).ln(),l=new Te.default(s.toString()).ln(),m=new Te.default(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)?ui:o,w=new Te.default(p.toString()).mul(h),y=new Te.default(i.toString()).add(w),T=new G.default(y.lessThan(new Te.default(an.toString()))?y.toString():an.toString());if(r){let g=rt(T,oi);return i.gt(g)?i:g}else return T}static getPriceRange(n,t,i){let o=new G.default(1).ushln(128).subn(1),r=new G.default(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)&&t.sub(m.blockTimestamp)<=i}).map(({observation:m,idx:d})=>({index:d,observation:m}));if(s.length<2)return{minPrice:new G.default(0),maxPrice:new G.default(0),twapPrice:new G.default(0)};s.sort((m,d)=>d.observation.blockTimestamp.cmp(m.observation.blockTimestamp));let a=s[0],u=s[s.length-1],c=rt(a.observation.blockTimestamp,u.observation.blockTimestamp);if(c.eqn(0))return{minPrice:new G.default(0),maxPrice:new G.default(0),twapPrice:new G.default(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[si-1]:d=n.observations[m.index-1],d.blockTimestamp.eqn(0))continue;if(d.blockTimestamp>m.observation.blockTimestamp)break;let f=m.observation,h=rt(f.blockTimestamp,d.blockTimestamp);if(h.eqn(0))continue;let p=f.cumulativeToken0PriceX32.sub(d.cumulativeToken0PriceX32).div(h);o=G.default.min(o,p),r=G.default.max(r,p)}return{minPrice:o,maxPrice:r,twapPrice:l}}static calculatePreFeeAmount(n,t,i,o,r,s,a){let u=this.calculateDynamicFeeRate(n,i,o,r,s,a);if(u.eqn(0))return t;{let c=t.mul(Fe),l=Fe.sub(u);return c.add(l).subn(1).div(l)}}};var Bt=V(require("bn.js"));var Pe=class{static swapWithoutFees(n,t,i){let o=t.mul(i),r=t.add(n),[s,a]=Ee(o,r),u=a.sub(t),c=i.sub(s);if(c.isZero())throw Error("destinationAmountSwapped is zero");return{sourceAmountSwapped:u,destinationAmountSwapped:c}}static swapWithoutFeesBaseOut(n,t,i){if(n.isZero())throw new Error("destinationAmount is zero");if(n.gt(i))throw new Error("destinationAmount exceeds available destination reserve");let o=t.mul(n),r=i.sub(n);if(r.isZero())throw new Error("denominator is zero");let[s]=Ee(o,r);return{sourceAmountSwapped:s,destinationAmountSwapped:n}}static lpTokensToTradingTokens(n,t,i,o,r){let s=n.mul(i).div(t),a=n.mul(o).div(t);if(r===0)return{tokenAmount0:s,tokenAmount1:a};if(r===1)return kt(n.mul(i),t).gt(De)&&s.gt(De)&&(s=s.add(new Bt.default(1))),kt(n.mul(o),t).gt(De)&&a.gt(De)&&(a=a.add(new Bt.default(1))),{tokenAmount0:s,tokenAmount1:a};throw Error("roundDirection value error")}};var Ue=class{static validate_supply(n,t){if(n.isZero())throw Error("tokenAmount0 is zero");if(t.isZero())throw Error("tokenAmount1 is zero")}static swapBaseIn(n,t,i,o,r,s,a=!1){let u=qe.calculateDynamicFee(n,new vt.default(new Date().getTime()/1e3),r,"volatility",o,s,a),c=n.sub(u),{sourceAmountSwapped:l,destinationAmountSwapped:m}=Pe.swapWithoutFees(c,t,i),d=l.add(u);return{newSwapSourceAmount:t.add(d),newSwapDestinationAmount:i.sub(m),sourceAmountSwapped:d,destinationAmountSwapped:m,tradeFee:u}}static swapBaseOut(n,t,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}=Pe.swapWithoutFeesBaseOut(n,t,i),l=qe.calculatePreDynamicFee(u,new vt.default(new Date().getTime()/1e3),r,"volatility",o,s,a);return{newSwapSourceAmount:t.add(l),newSwapDestinationAmount:i.sub(c),sourceAmountSwapped:l,destinationAmountSwapped:c,tradeFee:l.sub(u)}}};var E=require("@solana/web3.js"),Mn=V(require("axios"));var j=require("@solana/web3.js"),cn=require("@solana/spl-token");var un=Z("Gfx_txUtil"),ln=1644;function ot(e){let n=[],t=[];return e.microLamports&&(n.push(j.ComputeBudgetProgram.setComputeUnitPrice({microLamports:e.microLamports})),t.push(ne.SetComputeUnitPrice)),e.units&&(n.push(j.ComputeBudgetProgram.setComputeUnitLimit({units:e.units})),t.push(ne.SetComputeUnitLimit)),{instructions:n,instructionTypes:t}}async function Be(e,n){var i,o;let t=n!=null?n:"confirmed";try{return((o=await((i=e.getLatestBlockhash)==null?void 0:i.call(e,{commitment:t})))==null?void 0:o.blockhash)||(await e.getRecentBlockhash(t)).blockhash}catch{return(await e.getRecentBlockhash(t)).blockhash}}function li(e,n){e.length<1&&un.logWithError(`no instructions provided: ${e.toString()}`),n.length<1&&un.logWithError(`no signers provided:, ${n.toString()}`);let t=new j.Transaction;t.recentBlockhash="11111111111111111111111111111111",t.feePayer=n[0],t.add(...e);try{return t.serialize({verifySignatures:!1}).toString("base64").length<ln}catch{return!1}}function de(e,n){let[t,i]=j.PublicKey.findProgramAddressSync(e,n);return{publicKey:t,nonce:i}}function _e({instructions:e,payer:n,signers:t}){return li(e,[n,...t])}function We({instructions:e,payer:n,lookupTableAddressAccount:t,recentBlockhash:i=j.Keypair.generate().publicKey.toString()}){let r=new j.TransactionMessage({payerKey:n,recentBlockhash:i,instructions:e}).compileToV0Message(Object.values(t!=null?t:{}));try{return Buffer.from(new j.VersionedTransaction(r).serialize()).toString("base64").length<ln}catch{return!1}}var mi=e=>Buffer.isBuffer(e)?e:e instanceof Uint8Array?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e);function Se(e){let n=[];return e.forEach(t=>{t instanceof j.Transaction&&(t.recentBlockhash||(t.recentBlockhash=cn.TOKEN_PROGRAM_ID.toBase58()),t.feePayer||(t.feePayer=j.Keypair.generate().publicKey));let i=t.serialize({requireAllSignatures:!1,verifySignatures:!1});t instanceof j.VersionedTransaction&&(i=mi(i));let o=i.toString("base64");n.push(o)}),console.log("simulate tx string:",n),n}var be=require("@solana/web3.js");var Et=require("@solana/web3.js"),ye=require("@solana/spl-token");var di=require("@solana/web3.js"),fi=V(require("bn.js"));var ar=V(require("bn.js"));var ve=9e15,he=1e9,xt="0123456789abcdef",at="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ut="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",Ct={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-ve,maxE:ve,crypto:!1},gn,ue,C=!0,lt="[DecimalError] ",ge=lt+"Invalid argument: ",hn=lt+"Precision limit exceeded",yn=lt+"crypto unavailable",bn="[object Decimal]",Y=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,wn=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,re=1e7,M=7,yi=9007199254740991,bi=at.length-1,It=ut.length-1,b={toStringTag:bn};b.absoluteValue=b.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),k(e)};b.ceil=function(){return k(new this.constructor(this),this.e+1,2)};b.clampedTo=b.clamp=function(e,n){var t,i=this,o=i.constructor;if(e=new o(e),n=new o(n),!e.s||!n.s)return new o(NaN);if(e.gt(n))throw Error(ge+n);return t=i.cmp(e),t<0?e:i.cmp(n)>0?n:new o(i)};b.comparedTo=b.cmp=function(e){var n,t,i,o,r=this,s=r.d,a=(e=new r.constructor(e)).d,u=r.s,c=e.s;if(!s||!a)return!u||!c?NaN:u!==c?u:s===a?0:!s^u<0?1:-1;if(!s[0]||!a[0])return s[0]?u:a[0]?-c:0;if(u!==c)return u;if(r.e!==e.e)return r.e>e.e^u<0?1:-1;for(i=s.length,o=a.length,n=0,t=i<o?i:o;n<t;++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 e,n,t=this,i=t.constructor;return t.d?t.d[0]?(e=i.precision,n=i.rounding,i.precision=e+Math.max(t.e,t.sd())+M,i.rounding=1,t=wi(i,kn(i,t)),i.precision=e,i.rounding=n,k(ue==2||ue==3?t.neg():t,e,n,!0)):new i(1):new i(NaN)};b.cubeRoot=b.cbrt=function(){var e,n,t,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?(t=H(l.d),e=l.e,(r=(e-t.length+1)%3)&&(t+=r==1||r==-2?"0":"00"),r=_(t,1/3),e=Y((e+1)/3)-(e%3==(e<0?-1:2)),r==1/0?t="5e"+e:(t=r.toExponential(),t=t.slice(0,t.indexOf("e")+1)+e),i=new m(t),i.s=l.s):i=new m(r.toString()),s=(e=m.precision)+3;;)if(a=i,u=a.times(a).times(a),c=u.plus(l),i=F(c.plus(l).times(a),c.plus(u),s+2,1),H(a.d).slice(0,s)===(t=H(i.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!o&&t=="4999"){if(!o&&(k(a,e+1,0),a.times(a).times(a).eq(l))){i=a;break}s+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(k(i,e+1,1),n=!i.times(i).times(i).eq(l));break}return C=!0,k(i,e,m.rounding,n)};b.decimalPlaces=b.dp=function(){var e,n=this.d,t=NaN;if(n){if(e=n.length-1,t=(e-Y(this.e/M))*M,e=n[e],e)for(;e%10==0;e/=10)t--;t<0&&(t=0)}return t};b.dividedBy=b.div=function(e){return F(this,new this.constructor(e))};b.dividedToIntegerBy=b.divToInt=function(e){var n=this,t=n.constructor;return k(F(n,new t(e),0,1,1),t.precision,t.rounding)};b.equals=b.eq=function(e){return this.cmp(e)===0};b.floor=function(){return k(new this.constructor(this),this.e+1,3)};b.greaterThan=b.gt=function(e){return this.cmp(e)>0};b.greaterThanOrEqualTo=b.gte=function(e){var n=this.cmp(e);return n==1||n===0};b.hyperbolicCosine=b.cosh=function(){var e,n,t,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;t=s.precision,i=s.rounding,s.precision=t+Math.max(r.e,r.sd())+4,s.rounding=1,o=r.d.length,o<32?(e=Math.ceil(o/3),n=(1/dt(4,e)).toString()):(e=16,n="2.3283064365386962890625e-10"),r=Me(s,1,r.times(n),new s(1),!0);for(var u,c=e,l=new s(8);c--;)u=r.times(r),r=a.minus(u.times(l.minus(u.times(l))));return k(r,s.precision=t,s.rounding=i,!0)};b.hyperbolicSine=b.sinh=function(){var e,n,t,i,o=this,r=o.constructor;if(!o.isFinite()||o.isZero())return new r(o);if(n=r.precision,t=r.rounding,r.precision=n+Math.max(o.e,o.sd())+4,r.rounding=1,i=o.d.length,i<3)o=Me(r,2,o,o,!0);else{e=1.4*Math.sqrt(i),e=e>16?16:e|0,o=o.times(1/dt(5,e)),o=Me(r,2,o,o,!0);for(var s,a=new r(5),u=new r(16),c=new r(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(u.times(s).plus(c))))}return r.precision=n,r.rounding=t,k(o,n,t,!0)};b.hyperbolicTangent=b.tanh=function(){var e,n,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(e=i.precision,n=i.rounding,i.precision=e+7,i.rounding=1,F(t.sinh(),t.cosh(),i.precision=e,i.rounding=n)):new i(t.s)};b.inverseCosine=b.acos=function(){var e,n=this,t=n.constructor,i=n.abs().cmp(1),o=t.precision,r=t.rounding;return i!==-1?i===0?n.isNeg()?ie(t,o,r):new t(0):new t(NaN):n.isZero()?ie(t,o+4,r).times(.5):(t.precision=o+6,t.rounding=1,n=n.asin(),e=ie(t,o+4,r).times(.5),t.precision=o,t.rounding=r,e.minus(n))};b.inverseHyperbolicCosine=b.acosh=function(){var e,n,t=this,i=t.constructor;return t.lte(1)?new i(t.eq(1)?0:NaN):t.isFinite()?(e=i.precision,n=i.rounding,i.precision=e+Math.max(Math.abs(t.e),t.sd())+4,i.rounding=1,C=!1,t=t.times(t).minus(1).sqrt().plus(t),C=!0,i.precision=e,i.rounding=n,t.ln()):new i(t)};b.inverseHyperbolicSine=b.asinh=function(){var e,n,t=this,i=t.constructor;return!t.isFinite()||t.isZero()?new i(t):(e=i.precision,n=i.rounding,i.precision=e+2*Math.max(Math.abs(t.e),t.sd())+6,i.rounding=1,C=!1,t=t.times(t).plus(1).sqrt().plus(t),C=!0,i.precision=e,i.rounding=n,t.ln())};b.inverseHyperbolicTangent=b.atanh=function(){var e,n,t,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):(e=r.precision,n=r.rounding,i=o.sd(),Math.max(i,e)<2*-o.e-1?k(new r(o),e,n,!0):(r.precision=t=i-o.e,o=F(o.plus(1),new r(1).minus(o),t+e,1),r.precision=e+4,r.rounding=1,o=o.ln(),r.precision=e,r.rounding=n,o.times(.5))):new r(NaN)};b.inverseSine=b.asin=function(){var e,n,t,i,o=this,r=o.constructor;return o.isZero()?new r(o):(n=o.abs().cmp(1),t=r.precision,i=r.rounding,n!==-1?n===0?(e=ie(r,t+4,i).times(.5),e.s=o.s,e):new r(NaN):(r.precision=t+6,r.rounding=1,o=o.div(new r(1).minus(o.times(o)).sqrt().plus(1)).atan(),r.precision=t,r.rounding=i,o.times(2)))};b.inverseTangent=b.atan=function(){var e,n,t,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<=It)return s=ie(l,m+4,d).times(.25),s.s=c.s,s}else{if(!c.s)return new l(NaN);if(m+4<=It)return s=ie(l,m+4,d).times(.5),s.s=c.s,s}for(l.precision=a=m+10,l.rounding=1,t=Math.min(28,a/M+2|0),e=t;e;--e)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;e!==-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(e=n;s.d[e]===r.d[e]&&e--;);return t&&(s=s.times(2<<t-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&&Y(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(e){return this.cmp(e)<0};b.lessThanOrEqualTo=b.lte=function(e){return this.cmp(e)<1};b.logarithm=b.log=function(e){var n,t,i,o,r,s,a,u,c=this,l=c.constructor,m=l.precision,d=l.rounding,f=5;if(e==null)e=new l(10),n=!0;else{if(e=new l(e),t=e.d,e.s<0||!t||!t[0]||e.eq(1))return new l(NaN);n=e.eq(10)}if(t=c.d,c.s<0||!t||!t[0]||c.eq(1))return new l(t&&!t[0]?-1/0:c.s!=1?NaN:t?0:1/0);if(n)if(t.length>1)r=!0;else{for(o=t[0];o%10===0;)o/=10;r=o!==1}if(C=!1,a=m+f,s=pe(c,a),i=n?ct(l,a+10):pe(e,a),u=F(s,i,a,1),Ve(u.d,o=m,d))do if(a+=10,s=pe(c,a),i=n?ct(l,a+10):pe(e,a),u=F(s,i,a,1),!r){+H(u.d).slice(o+1,o+15)+1==1e14&&(u=k(u,m+1,0));break}while(Ve(u.d,o+=10,d));return C=!0,k(u,m,d)};b.minus=b.sub=function(e){var n,t,i,o,r,s,a,u,c,l,m,d,f=this,h=f.constructor;if(e=new h(e),!f.d||!e.d)return!f.s||!e.s?e=new h(NaN):f.d?e.s=-e.s:e=new h(e.d||f.s!==e.s?f:NaN),e;if(f.s!=e.s)return e.s=-e.s,f.plus(e);if(c=f.d,d=e.d,a=h.precision,u=h.rounding,!c[0]||!d[0]){if(d[0])e.s=-e.s;else if(c[0])e=new h(f);else return new h(u===3?-0:0);return C?k(e,a,u):e}if(t=Y(e.e/M),l=Y(f.e/M),c=c.slice(),r=l-t,r){for(m=r<0,m?(n=c,r=-r,s=d.length):(n=d,t=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,e.s=-e.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]=re-1;--c[o],c[i]+=re}c[i]-=d[i]}for(;c[--s]===0;)c.pop();for(;c[0]===0;c.shift())--t;return c[0]?(e.d=c,e.e=mt(c,t),C?k(e,a,u):e):new h(u===3?-0:0)};b.modulo=b.mod=function(e){var n,t=this,i=t.constructor;return e=new i(e),!t.d||!e.s||e.d&&!e.d[0]?new i(NaN):!e.d||t.d&&!t.d[0]?k(new i(t),i.precision,i.rounding):(C=!1,i.modulo==9?(n=F(t,e.abs(),0,3,1),n.s*=e.s):n=F(t,e,0,i.modulo,1),n=n.times(e),C=!0,t.minus(n))};b.naturalExponential=b.exp=function(){return Nt(this)};b.naturalLogarithm=b.ln=function(){return pe(this)};b.negated=b.neg=function(){var e=new this.constructor(this);return e.s=-e.s,k(e)};b.plus=b.add=function(e){var n,t,i,o,r,s,a,u,c,l,m=this,d=m.constructor;if(e=new d(e),!m.d||!e.d)return!m.s||!e.s?e=new d(NaN):m.d||(e=new d(e.d||m.s===e.s?m:NaN)),e;if(m.s!=e.s)return e.s=-e.s,m.minus(e);if(c=m.d,l=e.d,a=d.precision,u=d.rounding,!c[0]||!l[0])return l[0]||(e=new d(m)),C?k(e,a,u):e;if(r=Y(m.e/M),i=Y(e.e/M),c=c.slice(),o=r-i,o){for(o<0?(t=c,o=-o,s=l.length):(t=l,i=r,s=c.length),r=Math.ceil(a/M),s=r>s?r+1:s+1,o>s&&(o=s,t.length=1),t.reverse();o--;)t.push(0);t.reverse()}for(s=c.length,o=l.length,s-o<0&&(o=s,t=l,l=c,c=t),n=0;o;)n=(c[--o]=c[o]+l[o]+n)/re|0,c[o]%=re;for(n&&(c.unshift(n),++i),s=c.length;c[--s]==0;)c.pop();return e.d=c,e.e=mt(c,i),C?k(e,a,u):e};b.precision=b.sd=function(e){var n,t=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ge+e);return t.d?(n=Tn(t.d),e&&t.e+1>n&&(n=t.e+1)):n=NaN,n};b.round=function(){var e=this,n=e.constructor;return k(new n(e),e.e+1,n.rounding)};b.sine=b.sin=function(){var e,n,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(e=i.precision,n=i.rounding,i.precision=e+Math.max(t.e,t.sd())+M,i.rounding=1,t=Pi(i,kn(i,t)),i.precision=e,i.rounding=n,k(ue>2?t.neg():t,e,n,!0)):new i(NaN)};b.squareRoot=b.sqrt=function(){var e,n,t,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=H(a),(n.length+u)%2==0&&(n+="0"),c=Math.sqrt(n),u=Y((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()),t=(u=l.precision)+3;;)if(r=i,i=r.plus(F(s,r,t+2,1)).times(.5),H(r.d).slice(0,t)===(n=H(i.d)).slice(0,t))if(n=n.slice(t-3,t+1),n=="9999"||!o&&n=="4999"){if(!o&&(k(r,u+1,0),r.times(r).eq(s))){i=r;break}t+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(k(i,u+1,1),e=!i.times(i).eq(s));break}return C=!0,k(i,u,l.rounding,e)};b.tangent=b.tan=function(){var e,n,t=this,i=t.constructor;return t.isFinite()?t.isZero()?new i(t):(e=i.precision,n=i.rounding,i.precision=e+10,i.rounding=1,t=t.sin(),t.s=1,t=F(t,new i(1).minus(t.times(t)).sqrt(),e+10,0),i.precision=e,i.rounding=n,k(ue==2||ue==4?t.neg():t,e,n,!0)):new i(NaN)};b.times=b.mul=function(e){var n,t,i,o,r,s,a,u,c,l=this,m=l.constructor,d=l.d,f=(e=new m(e)).d;if(e.s*=l.s,!d||!d[0]||!f||!f[0])return new m(!e.s||d&&!d[0]&&!f||f&&!f[0]&&!d?NaN:!d||!f?e.s/0:e.s*0);for(t=Y(l.e/M)+Y(e.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%re|0,n=a/re|0;r[o]=(r[o]+n)%re|0}for(;!r[--s];)r.pop();return n?++t:r.shift(),e.d=r,e.e=mt(r,t),C?k(e,m.precision,m.rounding):e};b.toBinary=function(e,n){return Kt(this,2,e,n)};b.toDecimalPlaces=b.toDP=function(e,n){var t=this,i=t.constructor;return t=new i(t),e===void 0?t:($(e,0,he),n===void 0?n=i.rounding:$(n,0,8),k(t,e+t.e+1,n))};b.toExponential=function(e,n){var t,i=this,o=i.constructor;return e===void 0?t=ae(i,!0):($(e,0,he),n===void 0?n=o.rounding:$(n,0,8),i=k(new o(i),e+1,n),t=ae(i,!0,e+1)),i.isNeg()&&!i.isZero()?"-"+t:t};b.toFixed=function(e,n){var t,i,o=this,r=o.constructor;return e===void 0?t=ae(o):($(e,0,he),n===void 0?n=r.rounding:$(n,0,8),i=k(new r(o),e+o.e+1,n),t=ae(i,!1,e+i.e+1)),o.isNeg()&&!o.isZero()?"-"+t:t};b.toFraction=function(e){var n,t,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=t=new p(1),i=u=new p(0),n=new p(i),r=n.e=Tn(h)-f.e-1,s=r%M,n.d[0]=_(10,s<0?M+s:s),e==null)e=r>0?n:c;else{if(a=new p(e),!a.isInt()||a.lt(c))throw Error(ge+a);e=a.gt(n)?r>0?n:c:a}for(C=!1,a=new p(H(h)),l=p.precision,p.precision=r=h.length*M*2;m=F(a,n,0,1,1),o=t.plus(m.times(i)),o.cmp(e)!=1;)t=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=F(e.minus(t),i,0,1,1),u=u.plus(o.times(c)),t=t.plus(o.times(i)),u.s=c.s=f.s,d=F(c,i,r,1).minus(f).abs().cmp(F(u,t,r,1).minus(f).abs())<1?[c,i]:[u,t],p.precision=l,C=!0,d};b.toHexadecimal=b.toHex=function(e,n){return Kt(this,16,e,n)};b.toNearest=function(e,n){var t=this,i=t.constructor;if(t=new i(t),e==null){if(!t.d)return t;e=new i(1),n=i.rounding}else{if(e=new i(e),n===void 0?n=i.rounding:$(n,0,8),!t.d)return e.s?t:e;if(!e.d)return e.s&&(e.s=t.s),e}return e.d[0]?(C=!1,t=F(t,e,0,n,1).times(e),C=!0,k(t)):(e.s=t.s,t=e),t};b.toNumber=function(){return+this};b.toOctal=function(e,n){return Kt(this,8,e,n)};b.toPower=b.pow=function(e){var n,t,i,o,r,s,a=this,u=a.constructor,c=+(e=new u(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new u(_(+a,c));if(a=new u(a),a.eq(1))return a;if(i=u.precision,r=u.rounding,e.eq(1))return k(a,i,r);if(n=Y(e.e/M),n>=e.d.length-1&&(t=c<0?-c:c)<=yi)return o=Pn(u,a,t,i),e.s<0?new u(1).div(o):k(o,i,r);if(s=a.s,s<0){if(n<e.d.length-1)return new u(NaN);if((e.d[n]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return t=_(+a,c),n=t==0||!isFinite(t)?Y(c*(Math.log("0."+H(a.d))/Math.LN10+a.e+1)):new u(t+"").e,n>u.maxE+1||n<u.minE-1?new u(n>0?s/0:0):(C=!1,u.rounding=a.s=1,t=Math.min(12,(n+"").length),o=Nt(e.times(pe(a,i+t)),i),o.d&&(o=k(o,i+5,1),Ve(o.d,i,r)&&(n=i+10,o=k(Nt(e.times(pe(a,n+t)),n),n+5,1),+H(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(e,n){var t,i=this,o=i.constructor;return e===void 0?t=ae(i,i.e<=o.toExpNeg||i.e>=o.toExpPos):($(e,1,he),n===void 0?n=o.rounding:$(n,0,8),i=k(new o(i),e,n),t=ae(i,e<=i.e||i.e<=o.toExpNeg,e)),i.isNeg()&&!i.isZero()?"-"+t:t};b.toSignificantDigits=b.toSD=function(e,n){var t=this,i=t.constructor;return e===void 0?(e=i.precision,n=i.rounding):($(e,1,he),n===void 0?n=i.rounding:$(n,0,8)),k(new i(t),e,n)};b.toString=function(){var e=this,n=e.constructor,t=ae(e,e.e<=n.toExpNeg||e.e>=n.toExpPos);return e.isNeg()&&!e.isZero()?"-"+t:t};b.truncated=b.trunc=function(){return k(new this.constructor(this),this.e+1,1)};b.valueOf=b.toJSON=function(){var e=this,n=e.constructor,t=ae(e,e.e<=n.toExpNeg||e.e>=n.toExpPos);return e.isNeg()?"-"+t:t};function H(e){var n,t,i,o=e.length-1,r="",s=e[0];if(o>0){for(r+=s,n=1;n<o;n++)i=e[n]+"",t=M-i.length,t&&(r+=fe(t)),r+=i;s=e[n],i=s+"",t=M-i.length,t&&(r+=fe(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return r+s}function $(e,n,t){if(e!==~~e||e<n||e>t)throw Error(ge+e)}function Ve(e,n,t,i){var o,r,s,a;for(r=e[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=e[o]%r|0,i==null?n<3?(n==0?a=a/100|0:n==1&&(a=a/10|0),s=t<4&&a==99999||t>3&&a==49999||a==5e4||a==0):s=(t<4&&a+1==r||t>3&&a+1==r/2)&&(e[o+1]/r/100|0)==_(10,n-2)-1||(a==r/2||a==0)&&(e[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||t<4)&&a==9999||!i&&t>3&&a==4999):s=((i||t<4)&&a+1==r||!i&&t>3&&a+1==r/2)&&(e[o+1]/r/1e3|0)==_(10,n-3)-1,s}function st(e,n,t){for(var i,o=[0],r,s=0,a=e.length;s<a;){for(r=o.length;r--;)o[r]*=n;for(o[0]+=xt.indexOf(e.charAt(s++)),i=0;i<o.length;i++)o[i]>t-1&&(o[i+1]===void 0&&(o[i+1]=0),o[i+1]+=o[i]/t|0,o[i]%=t)}return o.reverse()}function wi(e,n){var t,i,o;if(n.isZero())return n;i=n.d.length,i<32?(t=Math.ceil(i/3),o=(1/dt(4,t)).toString()):(t=16,o="2.3283064365386962890625e-10"),e.precision+=t,n=Me(e,1,n.times(o),new e(1));for(var r=t;r--;){var s=n.times(n);n=s.times(s).minus(s).times(8).plus(1)}return e.precision-=t,n}var F=function(){function e(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 t(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,N,q,O,z,W=i.constructor,X=i.s==o.s?1:-1,D=i.d,K=o.d;if(!D||!D[0]||!K||!K[0])return new W(!i.s||!o.s||(D?K&&D[0]==K[0]:!K)?NaN:D&&D[0]==0||!K?X*0:X/0);for(u?(f=1,l=i.e-o.e):(u=re,f=M,l=Y(i.e/f)-Y(o.e/f)),O=K.length,N=D.length,y=new W(X),T=y.d=[],m=0;K[m]==(D[m]||0);m++);if(K[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,O==1){for(d=0,K=K[0],B++;(m<N||d)&&B--;m++)v=d*u+(D[m]||0),T[m]=v/K|0,d=v%K|0;h=d||m<N}else{for(d=u/(K[0]+1)|0,d>1&&(K=e(K,d,u),D=e(D,d,u),O=K.length,N=D.length),x=O,g=D.slice(0,O),P=g.length;P<O;)g[P++]=0;z=K.slice(),z.unshift(0),q=K[0],K[1]>=u/2&&++q;do d=0,c=n(K,g,O,P),c<0?(A=g[0],O!=P&&(A=A*u+(g[1]||0)),d=A/q|0,d>1?(d>=u&&(d=u-1),p=e(K,d,u),w=p.length,P=g.length,c=n(p,g,w,P),c==1&&(d--,t(p,O<w?z:K,w,u))):(d==0&&(c=d=1),p=K.slice()),w=p.length,w<P&&p.unshift(0),t(g,p,P,u),c==-1&&(P=g.length,c=n(K,g,O,P),c<1&&(d++,t(g,O<P?z:K,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++<N||g[0]!==void 0)&&B--);h=g[0]!==void 0}T[0]||T.shift()}if(f==1)y.e=l,gn=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(e,n,t,i){var o,r,s,a,u,c,l,m,d,f=e.constructor;e:if(n!=null){if(m=e.d,!m)return e;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=t<4?(u||i)&&(t==0||t==(e.s<0?3:2)):u>5||u==5&&(t==4||i||t==6&&(r>0?s>0?l/_(10,o-s):0:m[d-1])%10&1||t==(e.s<0?8:7)),n<1||!m[0])return m.length=0,c?(n-=e.e+1,m[0]=_(10,(M-n%M)%M),e.e=-n||0):m[0]=e.e=0,e;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&&(e.e++,m[0]==re&&(m[0]=1));break}else{if(m[d]+=a,m[d]!=re)break;m[d--]=0,a=1}for(r=m.length;m[--r]===0;)m.pop()}return C&&(e.e>f.maxE?(e.d=null,e.e=NaN):e.e<f.minE&&(e.e=0,e.d=[0])),e}function ae(e,n,t){if(!e.isFinite())return An(e);var i,o=e.e,r=H(e.d),s=r.length;return n?(t&&(i=t-s)>0?r=r.charAt(0)+"."+r.slice(1)+fe(i):s>1&&(r=r.charAt(0)+"."+r.slice(1)),r=r+(e.e<0?"e":"e+")+e.e):o<0?(r="0."+fe(-o-1)+r,t&&(i=t-s)>0&&(r+=fe(i))):o>=s?(r+=fe(o+1-s),t&&(i=t-o-1)>0&&(r=r+"."+fe(i))):((i=o+1)<s&&(r=r.slice(0,i)+"."+r.slice(i)),t&&(i=t-s)>0&&(o+1===s&&(r+="."),r+=fe(i))),r}function mt(e,n){var t=e[0];for(n*=M;t>=10;t/=10)n++;return n}function ct(e,n,t){if(n>bi)throw C=!0,t&&(e.precision=t),Error(hn);return k(new e(at),n,1,!0)}function ie(e,n,t){if(n>It)throw Error(hn);return k(new e(ut),n,t,!0)}function Tn(e){var n=e.length-1,t=n*M+1;if(n=e[n],n){for(;n%10==0;n/=10)t--;for(n=e[0];n>=10;n/=10)t++}return t}function fe(e){for(var n="";e--;)n+="0";return n}function Pn(e,n,t,i){var o,r=new e(1),s=Math.ceil(i/M+4);for(C=!1;;){if(t%2&&(r=r.times(n),fn(r.d,s)&&(o=!0)),t=Y(t/2),t===0){t=r.d.length-1,o&&r.d[t]===0&&++r.d[t];break}n=n.times(n),fn(n.d,s)}return C=!0,r}function dn(e){return e.d[e.d.length-1]&1}function Sn(e,n,t){for(var i,o=new e(n[0]),r=0;++r<n.length;)if(i=new e(n[r]),i.s)o[t](i)&&(o=i);else{o=i;break}return o}function Nt(e,n){var t,i,o,r,s,a,u,c=0,l=0,m=0,d=e.constructor,f=d.rounding,h=d.precision;if(!e.d||!e.d[0]||e.e>17)return new d(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(n==null?(C=!1,u=h):u=n,a=new d(.03125);e.e>-2;)e=e.times(a),m+=5;for(i=Math.log(_(2,m))/Math.LN10*2+5|0,u+=i,t=r=s=new d(1),d.precision=u;;){if(r=k(r.times(e),u,1),t=t.times(++l),a=s.plus(F(r,t,u,1)),H(a.d).slice(0,u)===H(s.d).slice(0,u)){for(o=m;o--;)s=k(s.times(s),u,1);if(n==null)if(c<3&&Ve(s.d,u-i,f,c))d.precision=u+=10,t=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 pe(e,n){var t,i,o,r,s,a,u,c,l,m,d,f=1,h=10,p=e,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,t=H(w),i=t.charAt(0),Math.abs(r=p.e)<15e14){for(;i<7&&i!=1||i==1&&t.charAt(1)>3;)p=p.times(e),t=H(p.d),i=t.charAt(0),f++;r=p.e,i>1?(p=new y("0."+t),r++):p=new y(i+"."+t.slice(1))}else return c=ct(y,l+2,g).times(r+""),p=pe(new y(i+"."+t.slice(1)),l-h).plus(c),y.precision=g,n==null?k(p,g,T,C=!0):p;for(m=p,u=s=p=F(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(F(s,new y(o),l,1)),H(c.d).slice(0,l)===H(u.d).slice(0,l))if(u=u.times(2),r!==0&&(u=u.plus(ct(y,l+2,g).times(r+""))),u=F(u,new y(f),l,1),n==null)if(Ve(u.d,l-h,T,a))y.precision=l+=h,c=s=p=F(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 An(e){return String(e.s*e.s/0)}function Rt(e,n){var t,i,o;for((t=n.indexOf("."))>-1&&(n=n.replace(".","")),(i=n.search(/e/i))>0?(t<0&&(t=i),t+=+n.slice(i+1),n=n.substring(0,i)):t<0&&(t=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,e.e=t=t-i-1,e.d=[],i=(t+1)%M,t<0&&(i+=M),i<o){for(i&&e.d.push(+n.slice(0,i)),o-=M;i<o;)e.d.push(+n.slice(i,i+=M));n=n.slice(i),i=M-n.length}else i-=o;for(;i--;)n+="0";e.d.push(+n),C&&(e.e>e.constructor.maxE?(e.d=null,e.e=NaN):e.e<e.constructor.minE&&(e.e=0,e.d=[0]))}else e.e=0,e.d=[0];return e}function Ti(e,n){var t,i,o,r,s,a,u,c,l;if(n.indexOf("_")>-1){if(n=n.replace(/(\d)_(?=\d)/g,"$1"),wn.test(n))return Rt(e,n)}else if(n==="Infinity"||n==="NaN")return+n||(e.s=NaN),e.e=NaN,e.d=null,e;if(gi.test(n))t=16,n=n.toLowerCase();else if(pi.test(n))t=2;else if(hi.test(n))t=8;else throw Error(ge+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=e.constructor,s&&(n=n.replace(".",""),a=n.length,r=a-r,o=Pn(i,new i(t),r,r*2)),c=st(n,t,re),l=c.length-1,r=l;c[r]===0;--r)c.pop();return r<0?new i(e.s*0):(e.e=mt(c,l),e.d=c,C=!1,s&&(e=F(e,o,a*4)),u&&(e=e.times(Math.abs(u)<54?_(2,u):Ge.pow(2,u))),C=!0,e)}function Pi(e,n){var t,i=n.d.length;if(i<3)return n.isZero()?n:Me(e,2,n,n);t=1.4*Math.sqrt(i),t=t>16?16:t|0,n=n.times(1/dt(5,t)),n=Me(e,2,n,n);for(var o,r=new e(5),s=new e(16),a=new e(20);t--;)o=n.times(n),n=n.times(r.plus(o.times(s.times(o).minus(a))));return n}function Me(e,n,t,i,o){var r,s,a,u,c=1,l=e.precision,m=Math.ceil(l/M);for(C=!1,u=t.times(t),a=new e(i);;){if(s=F(a.times(u),new e(n++*n++),l,1),a=o?i.plus(s):i.minus(s),i=F(s.times(u),new e(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 dt(e,n){for(var t=e;--n;)t*=e;return t}function kn(e,n){var t,i=n.s<0,o=ie(e,e.precision,1),r=o.times(.5);if(n=n.abs(),n.lte(r))return ue=i?4:1,n;if(t=n.divToInt(o),t.isZero())ue=i?3:2;else{if(n=n.minus(t.times(o)),n.lte(r))return ue=dn(t)?i?2:3:i?4:1,n;ue=dn(t)?i?1:4:i?3:2}return n.minus(o).abs()}function Kt(e,n,t,i){var o,r,s,a,u,c,l,m,d,f=e.constructor,h=t!==void 0;if(h?($(t,1,he),i===void 0?i=f.rounding:$(i,0,8)):(t=f.precision,i=f.rounding),!e.isFinite())l=An(e);else{for(l=ae(e),s=l.indexOf("."),h?(o=2,n==16?t=t*4-3:n==8&&(t=t*3-2)):o=n,s>=0&&(l=l.replace(".",""),d=new f(1),d.e=l.length-s,d.d=st(ae(d),10,o),d.e=d.d.length),m=st(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--:(e=new f(e),e.d=m,e.e=r,e=F(e,d,t,i,0,o),m=e.d,r=e.e,c=gn),s=m[t],a=o/2,c=c||m[t+1]!==void 0,c=i<4?(s!==void 0||c)&&(i===0||i===(e.s<0?3:2)):s>a||s===a&&(i===4||c||i===6&&m[t-1]&1||i===(e.s<0?8:7)),m.length=t,c)for(;++m[--t]>o-1;)m[t]=0,t||(++r,m.unshift(1));for(u=m.length;!m[u-1];--u);for(s=0,l="";s<u;s++)l+=xt.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=st(l,o,n),u=m.length;!m[u-1];--u);for(s=1,l="1.";s<u;s++)l+=xt.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 e.s<0?"-"+l:l}function fn(e,n){if(e.length>n)return e.length=n,!0}function Si(e){return new this(e).abs()}function Ai(e){return new this(e).acos()}function ki(e){return new this(e).acosh()}function Bi(e,n){return new this(e).plus(n)}function vi(e){return new this(e).asin()}function Mi(e){return new this(e).asinh()}function xi(e){return new this(e).atan()}function Ci(e){return new this(e).atanh()}function Ii(e,n){e=new this(e),n=new this(n);var t,i=this.precision,o=this.rounding,r=i+4;return!e.s||!n.s?t=new this(NaN):!e.d&&!n.d?(t=ie(this,r,1).times(n.s>0?.25:.75),t.s=e.s):!n.d||e.isZero()?(t=n.s<0?ie(this,i,o):new this(0),t.s=e.s):!e.d||n.isZero()?(t=ie(this,r,1).times(.5),t.s=e.s):n.s<0?(this.precision=r,this.rounding=1,t=this.atan(F(e,n,r,1)),n=ie(this,r,1),this.precision=i,this.rounding=o,t=e.s<0?t.minus(n):t.plus(n)):t=this.atan(F(e,n,r,1)),t}function Ni(e){return new this(e).cbrt()}function Ri(e){return k(e=new this(e),e.e+1,2)}function Ki(e,n,t){return new this(e).clamp(n,t)}function Oi(e){if(!e||typeof e!="object")throw Error(lt+"Object expected");var n,t,i,o=e.defaults===!0,r=["precision",1,he,"rounding",0,8,"toExpNeg",-ve,0,"toExpPos",0,ve,"maxE",0,ve,"minE",-ve,0,"modulo",0,9];for(n=0;n<r.length;n+=3)if(t=r[n],o&&(this[t]=Ct[t]),(i=e[t])!==void 0)if(Y(i)===i&&i>=r[n+1]&&i<=r[n+2])this[t]=i;else throw Error(ge+t+": "+i);if(t="crypto",o&&(this[t]=Ct[t]),(i=e[t])!==void 0)if(i===!0||i===!1||i===0||i===1)if(i)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(yn);else this[t]=!1;else throw Error(ge+t+": "+i);return this}function Li(e){return new this(e).cos()}function Di(e){return new this(e).cosh()}function Bn(e){var n,t,i;function o(r){var s,a,u,c=this;if(!(c instanceof o))return new o(r);if(c.constructor=o,pn(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 Rt(c,r.toString())}else if(u!=="string")throw Error(ge+r);return(a=r.charCodeAt(0))===45?(r=r.slice(1),c.s=-1):(a===43&&(r=r.slice(1)),c.s=1),wn.test(r)?Rt(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=Bn,o.isDecimal=pn,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,e===void 0&&(e={}),e&&e.defaults!==!0)for(i=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],n=0;n<i.length;)e.hasOwnProperty(t=i[n++])||(e[t]=this[t]);return o.config(e),o}function Ei(e,n){return new this(e).div(n)}function Fi(e){return new this(e).exp()}function qi(e){return k(e=new this(e),e.e+1,3)}function Ui(){var e,n,t=new this(0);for(C=!1,e=0;e<arguments.length;)if(n=new this(arguments[e++]),n.d)t.d&&(t=t.plus(n.times(n)));else{if(n.s)return C=!0,new this(1/0);t=n}return C=!0,t.sqrt()}function pn(e){return e instanceof Ge||e&&e.toStringTag===bn||!1}function _i(e){return new this(e).ln()}function Wi(e,n){return new this(e).log(n)}function Vi(e){return new this(e).log(2)}function Gi(e){return new this(e).log(10)}function Hi(){return Sn(this,arguments,"lt")}function zi(){return Sn(this,arguments,"gt")}function Zi(e,n){return new this(e).mod(n)}function ji(e,n){return new this(e).mul(n)}function Yi(e,n){return new this(e).pow(n)}function Xi(e){var n,t,i,o,r=0,s=new this(1),a=[];if(e===void 0?e=this.precision:$(e,1,he),i=Math.ceil(e/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(yn);else for(;r<i;)a[r++]=Math.random()*1e7|0;for(i=a[--r],e%=M,i&&e&&(o=_(10,M-e),a[r]=(i/o|0)*o);a[r]===0;r--)a.pop();if(r<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=M)a.shift();for(i=1,o=a[0];o>=10;o/=10)i++;i<M&&(t-=M-i)}return s.e=t,s.d=a,s}function Ji(e){return k(e=new this(e),e.e+1,this.rounding)}function Qi(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function $i(e){return new this(e).sin()}function er(e){return new this(e).sinh()}function tr(e){return new this(e).sqrt()}function nr(e,n){return new this(e).sub(n)}function ir(){var e=0,n=arguments,t=new this(n[e]);for(C=!1;t.s&&++e<n.length;)t=t.plus(n[e]);return C=!0,k(t,this.precision,this.rounding)}function rr(e){return new this(e).tan()}function or(e){return new this(e).tanh()}function sr(e){return k(e=new this(e),e.e+1,1)}b[Symbol.for("nodejs.util.inspect.custom")]=b.toString;b[Symbol.toStringTag]="Decimal";var Ge=b.constructor=Bn(Ct);at=new Ge(at);ut=new Ge(ut);var Q=Ge;function Ot(e,n=1,t=[]){let i=[...e];if(n<=0)return t;for(;i.length;)t.push(i.splice(0,n));return t}var ce=require("@solana/web3.js"),zs=new ce.PublicKey("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Zs=new ce.PublicKey("CPMMoo8L3F4NbTegBCKVNunggL7H1ZpdTHKxQB5qKP1C"),js=new ce.PublicKey("GpMZbSM2GgvTKHJirzeGfMFoaZ8UR2X7F4v8vHTvxFbL"),Ys=new ce.PublicKey("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),ur=new ce.PublicKey("CPMDWBwJDtYax9qW7AyRuVC19Cc4L4Vcy4n2BHAbHkCW"),cr=new ce.PublicKey("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),lr=new ce.PublicKey("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2");var Xs={CREATE_CPMM_POOL_PROGRAM:ur,CREATE_CPMM_POOL_AUTH:cr,CREATE_CPMM_POOL_FEE_ACC:lr,FEE_DESTINATION_ID:new ce.PublicKey("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR")};var mr=require("@solana/web3.js");var dr=require("@solana/spl-token");var ee=V(require("bn.js")),He=1e4;function xe(e,n,t,i){if(n===void 0)return{amount:e,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=t.epoch<o.newerTransferFee.epoch?o.olderTransferFee:o.newerTransferFee,s=new ee.default(r.maximumFee.toString()),a=t.epoch<o.newerTransferFee.epoch?(Number(o.newerTransferFee.epoch)*t.slotsInEpoch-t.absoluteSlot)*400/1e3:void 0;if(i)if(r.transferFeeBasisPoints===He){let u=new ee.default(r.maximumFee.toString());return{amount:e.add(u),fee:u,expirationTime:a}}else{let u=Lt(e.mul(new ee.default(He)),new ee.default(He-r.transferFeeBasisPoints)),c=new ee.default(r.maximumFee.toString()),l=u.sub(e).gt(c)?e.add(c):u,m=Lt(l.mul(new ee.default(r.transferFeeBasisPoints)),new ee.default(He)),d=m.gt(s)?s:m;return{amount:l,fee:d,expirationTime:a}}else{let u=Lt(e.mul(new ee.default(r.transferFeeBasisPoints)),new ee.default(He)),c=u.gt(s)?s:u;return{amount:e,fee:c,expirationTime:a}}}function Lt(e,n){let{div:t,mod:i}=e.divmod(n);return i.gt(new ee.default(0))?t.add(new ee.default(1)):t}var Dt=Z("Gfx_accountInfo_util");