UNPKG

snapper-sdk

Version:

An SDK for building applications on top of Snapper.

1 lines 77 kB
import{PublicKey as Or}from"@solana/web3.js";import qt,{isBN as Gt}from"bn.js";import{bits as Mi,BitStructure as vi,blob as Fr,Blob as Di,cstr as Wi,f32 as Oi,f32be as Ui,f64 as qi,f64be as Gi,greedy as Hi,Layout as _r,ns64 as ji,ns64be as zi,nu64 as Yi,nu64be as Zi,offset as Xi,s16 as Qi,s16be as Ji,s24 as $i,s24be as eo,s32 as to,s32be as ro,s40 as no,s40be as io,s48 as oo,s48be as so,s8 as ao,seq as Mr,struct as uo,Structure as vr,u16 as co,u16be as lo,u24 as fo,u24be as po,u32 as mo,u32be as go,u40 as yo,u40be as bo,u48 as ho,u48be as wo,u8 as Dr,UInt as Wr,union as Po,Union as To,unionLayoutDiscriminator as xo,utf8 as So}from"@solana/buffer-layout";var ot=_r,Wt=vr;var st=Wr;var Ot=Dr;var Ut=Mr;var me=Fr;var xe=class extends ot{constructor(r,n,i){super(r,i);this.blob=me(r),this.signed=n}decode(r,n=0){let i=new qt(this.blob.decode(r,n),10,"le");return this.signed?i.fromTwos(this.span*8).clone():i}encode(r,n,i=0){return typeof r=="number"&&(r=new qt(r)),this.signed&&(r=r.toTwos(this.span*8)),this.blob.encode(r.toArrayLike(Buffer,"le",this.span),n,i)}};function V(e){return new st(1,e)}function Se(e){return new st(4,e)}function y(e){return new xe(8,!1,e)}function ne(e){return new xe(16,!1,e)}function Ht(e){return new xe(1,!0,e)}function Ue(e){return new xe(8,!0,e)}var Oe=class extends ot{constructor(r,n,i,o){super(r.span,o);this.layout=r,this.decoder=n,this.encoder=i}decode(r,n){return this.decoder(this.layout.decode(r,n))}encode(r,n,i){return this.layout.encode(this.encoder(r),n,i)}getSpan(r,n){return this.layout.getSpan(r,n)}};function L(e){return new Oe(me(32),t=>new Or(t),t=>t.toBuffer(),e)}function Re(e){return new Oe(Ot(),Ur,qr,e)}function Ur(e){if(e===0)return!1;if(e===1)return!0;throw new Error("Invalid bool: "+e)}function qr(e){return e?1:0}var at=class extends Wt{decode(t,r){return super.decode(t,r)}};function K(e,t,r){return new at(e,t,r)}function M(e,t,r){let n,i=typeof t=="number"?t:Gt(t)?t.toNumber():new Proxy(t,{get(o,s){if(!n){let a=Reflect.get(o,"count");n=Gt(a)?a.toNumber():a,Reflect.set(o,"count",n)}return Reflect.get(o,s)},set(o,s,a){return s==="count"&&(n=a),Reflect.set(o,s,a)}});return Ut(e,i,r)}import{PublicKey as Qt}from"@solana/web3.js";import{get as jt,set as Gr}from"lodash";var ut=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let r=t.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(r)}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}},zt={},Hr={};function W(e){let t=jt(zt,e);if(!t){let r=jt(Hr,e);t=new ut({name:e,logLevel:r}),Gr(zt,e,t)}return t}import{PublicKey as k}from"@solana/web3.js";var Yt=new k("EhhTKczWMGQt46ynNeRX1WfeagwwJd7ufHvCDjRxjo5Q"),Zt=new k("9KEPoZmtHUrBbhWN1v1KWLMkkvwY6WLtAVUCPRtRjP4z"),Xt=new k("FarmqiPv5eAj3j1GMdMCMUGXqPUvmquZtMy86QH6rzhG"),Do=new k("CLaimxFqjHzgTJtAGHU47NPhg6qrc5sCnpC4tBLyABQS"),Wo=new k("srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"),Oo=new k("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin"),Uo=new k("675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8"),qo=new k("5quBtoiQqxF9Jv6KYKctB59NT3gtJD2Y65kdnB1Uev3h"),Go=new k("CDSr3ssLcRB6XYPJwAfFt18MZvEZp4LjHcvzBVZ45duo"),Ho=new k("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"),jo=new k("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),zo=new k("kN1kEznaF5Xbd8LYuqtEFcxzWSBk5Fv6ygX6SqEGJVy"),Yo=new k("routeUGWgWzqBWFcrCfv8tritsqukccJPu3q5GPP3xS"),Zo=new k("7YttLkHDoNj9wyDur5pM1ejNaAvT9X4eqaYcHQqtj2G5"),Xo=new k("6FJon3QE27qgPVggARueB22hLvoh22VzJpXv4rBEoSLF"),Qo=new k("CC12se5To1CdEuw7fDS27B7Geo5jJyL7t5UK2B44NgiH"),Jo=new k("9HzJyW1qZsEiSfMUf6L2jo3CcTKAyBmSyKdwQeYisHrC"),$o=new k("DropEU8AvevN3UrXWXTMuz3rqnMczQVNjq3kcSdW2SQi"),es=new k("SNaPnpKUY656VPwbKmKT8FG4T85g4VWhRH1B4TQUfKs"),ts=new k("9pR79Lqe6wDNjag3v8MeVYUostoXjY2ognTydor6AtEZ"),rs=new k("DNXgeM9EiiaAbaWvwjHj9fQQLAX5ZsfHyvmYUNRAdNC8"),jr=new k("4AscABy58S62owbByjUUkQfZsP7fxYH1rDYb69V58HPM"),zr=new k("7rQ1QFNosMkUCuh7Z7fPbTHvh73b68sQYdirycEzJVuw"),Yr=new k("G11FKBRaAkHAKuLCgLM6K6NUc9rTjPAznRCjZifrTQe2"),ns=new k("LockrWmn6K5twhz3y9w1dQERbmgSaRkfnTeTKbpofwE"),Zr=new k("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),is=new k("3f7GcQFG397GAaEnv51zR6tsTVihYRydnydDD1cXekxH"),Xr=new k("7AFUeLVRjBfzqK3tTGw8hN48KLQWSk6DTE8xprWdPqix");var os={SERUM_MARKET:k.default,OPENBOOK_MARKET:new k("EoTcMgcDRTJVZDMZWBoU6rhYHZfkNTVEAfz3uUJRcYGj"),UTIL1216:k.default,FarmV3:new k("85BFyr98MbCUU9MVTEgzx1nbhWACbJqLzho6zd6DZcWL"),FarmV5:new k("EcLzTrNg9V7qhcdyXDe2qjtPkiGzDM2UbdRaeaadU5r2"),FarmV6:new k("Farm2hJLcqPtPg8M4rR6DMrsRNc5TPm5Cs4bVQrMe2T7"),AmmV4:new k("HWy1jotHpo6UqeQxx49dpYYdQB8wj9Qk9MdxwjLvDHB8"),AmmStable:new k("DDg4VmQaJV9ogWce7LpcjBA9bv22wRp5uaTPa5pGjijF"),CLMM:new k("devi51mZmdwUJGU9hjN27vEz64Gps7uUefqxg27EAtH"),CLMM_LOCK_PROGRAM_ID:new k("DLockwT7X7sxtLmGH9g5kmfcjaBtncdbUmi738m5bvQC"),CLMM_LOCK_AUTH_ID:new k("8qmHNvu2Kr2C7U8mJL4Vz1vTDxMhVuXKREwU7TNoaVEo"),Router:new k("BVChZ3XFEwTMUk1o9i3HAf91H6mFxSwa5X2wFAWhYPhU"),CREATE_CPMM_POOL_PROGRAM:jr,CREATE_CPMM_POOL_AUTH:zr,CREATE_CPMM_POOL_FEE_ACC:Yr,FEE_DESTINATION_ID:new k("3XMrhbv989VxAMi3DErLV9eJht1pHppW5LbKxe9fkEFR"),LOCK_CPMM_PROGRAM:Zr,LCOK_CPMM_AUTH:Xr};var ps=W("Raydium_farm_config"),ms=new Qt("2cpMA1jNS4obgRz8XNg38QuSP83L1AXpUgfxPNcvnAGj"),gs=new Qt("FrspKwj8i3pNmKwXreTveC4fu7KL5ZbGeXdZBe2XViu1"),Jt={3:er,5:tr,6:rr},$t={3:Ce,5:nr,6:ir},ys=e=>[3,5,6].indexOf(e)!==-1,bs=e=>{var s;let{version:t,rewardInfos:r,rewardTokenAccountsPublicKeys:n}=e,i=`rewardInfo:${JSON.stringify(r)}, rewardAccount:${JSON.stringify(n)}`,o={3:()=>{if(r.length!==1||n.length!==1)return`rewardInfos or rewardTokenAccounts lengths not equal 1: ${i}`},5:()=>{if(r.length!==n.length)return`rewardInfos and rewardTokenAccounts lengths not equal: ${i}`},6:()=>{if(!n.length||r.length!==n.length)return`no rewardTokenAccounts or rewardInfos and rewardTokenAccounts lengths not equal: ${i}`}};return(s=o[t])==null?void 0:s.call(o)},ke={"Standard SPL":0,"Option tokens":1},hs={[Yt.toString()]:3,[Zt.toString()]:5,[Xt.toString()]:6};var ct=K([V("instruction")]),lt=K([V("instruction")]),Qr=K([y("rewardState"),y("rewardOpenTime"),y("rewardEndTime"),y("rewardLastUpdateTime"),y("totalReward"),y("totalRewardEmissioned"),y("rewardClaimed"),y("rewardPerSecond"),ne("accRewardPerShare"),L("rewardVault"),L("rewardMint"),L("rewardSender"),y("rewardType"),M(y(),15,"padding")]),Jr=K([y("state"),y("nonce"),L("lpVault"),L("rewardVault"),L(),L(),y(),y(),y("totalReward"),ne("perShareReward"),y("lastSlot"),y("perSlotReward")]),$r=K([y("state"),y("nonce"),L("lpVault"),L("rewardVaultA"),y("totalRewardA"),ne("perShareRewardA"),y("perSlotRewardA"),V("option"),L("rewardVaultB"),me(7),y("totalRewardB"),ne("perShareRewardB"),y("perSlotRewardB"),y("lastSlot"),L()]),en=K([y(),y("state"),y("nonce"),y("validRewardTokenNum"),ne("rewardMultiplier"),y("rewardPeriodMax"),y("rewardPeriodMin"),y("rewardPeriodExtend"),L("lpMint"),L("lpVault"),M(Qr,5,"rewardInfos"),L("creator"),L(),M(y(),32,"padding")]),er=new Proxy(Jr,{get(e,t,r){return t==="decode"?(...n)=>{let i=e.decode(...n);return{...i,version:3,rewardInfos:[{rewardVault:i.rewardVault,totalReward:i.totalReward,perSlotReward:i.perSlotReward,perShareReward:i.perShareReward}]}}:Reflect.get(e,t,r)}}),tr=new Proxy($r,{get(e,t,r){return t==="decode"?(...n)=>{let i=e.decode(...n);return{...i,version:5,rewardInfos:[{rewardVault:i.rewardVaultA,totalReward:i.totalRewardA,perSlotReward:i.perSlotRewardA,perShareReward:i.perShareRewardA},{rewardVault:i.rewardVaultB,totalReward:i.totalRewardB,perSlotReward:i.perSlotRewardB,perShareReward:i.perShareRewardB}]}}:Reflect.get(e,t,r)}}),rr=new Proxy(en,{get(e,t,r){return t==="decode"?(...n)=>{let i=e.decode(...n);return{...i,version:6,rewardInfos:i.rewardInfos.map(o=>{var s;return{...o,rewardType:((s=Object.entries(ke).find(a=>String(a[1])===o.rewardType.toString()))!=null?s:["Standard SPL"])[0]}})}}:Reflect.get(e,t,r)}}),tn=K([y("isSet"),y("rewardPerSecond"),y("rewardOpenTime"),y("rewardEndTime"),y("rewardType")]),dt=K([V("instruction"),y("nonce"),M(tn,5,"rewardTimeInfo")]),ft=K([V("instruction"),y("rewardReopenTime"),y("rewardEndTime"),y("rewardPerSecond")]),pt=K([V("instruction"),y("isSet"),y("rewardPerSecond"),y("rewardOpenTime"),y("rewardEndTime"),y("rewardType")]),As=K([y("state"),L("id"),L("owner"),y("deposited"),M(y(),1,"rewardDebts")]),Ce=K([y("state"),L("id"),L("owner"),y("deposited"),M(ne(),1,"rewardDebts"),y(""),y("voteLockedBalance"),M(y(),15)]),Ls=K([y("state"),L("id"),L("owner"),y("deposited"),M(y(),2,"rewardDebts")]),nr=K([y("state"),L("id"),L("owner"),y("deposited"),M(ne(),2,"rewardDebts"),M(y(),17)]),ir=K([y(),y("state"),L("id"),L("owner"),y("deposited"),M(ne(),5,"rewardDebts"),M(y(),16)]),z=K([V("instruction"),y("amount")]),rn=K([L("mint"),L("grantAuthority"),y("baselineVoteWeightScaledFactor"),y("maxExtraLockupVoteWeightScaledFactor"),y("lockupSaturationSecs"),Ht("digitShift"),M(V(),7,"reserved1"),M(y(),7,"reserved2")]),or=K([me(8),L("governanceProgramId"),L("realm"),L("realmGoverningTokenMint"),L("realmAuthority"),M(V(),32,"reserved1"),M(rn,4,"votingMints"),Ue("timeOffset"),V("bump"),M(V(),7,"reserved2"),M(y(),11,"reserved3")]),nn=K([Ue("startTime"),Ue("endTime"),V("kind"),M(V(),15,"reserved")]),on=K([M(nn,1,"lockup"),y("amountDeposited_native"),y("amountInitiallyLockedNative"),Re("isUsed"),Re("allowClawback"),V("votingMintConfigIdx"),M(V(),29,"reserved")]),sr=K([me(8),L("voterAuthority"),L("registrar"),M(on,32,"deposits"),V("voterBump"),V("voterWweightRecordBump"),M(V(),94,"reserved")]);import Z from"bn.js";import{PublicKey as sn}from"@solana/web3.js";import{MINT_SIZE as Fs,TOKEN_PROGRAM_ID as _s,getTransferFeeConfig as Ms,unpackMint as vs}from"@solana/spl-token";var mt=W("Raydium_accountInfo_util");async function ar(e,t,r){let{batchRequest:n,commitment:i="confirmed",chunkCount:o=100}={batchRequest:!1,...r},s=gt(t,o),a=new Array(s.length).fill([]);if(n){let c=s.map(d=>{let f=e._buildArgs([d.map(m=>m.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:f}}),u=gt(c,10);a=(await(await Promise.all(u.map(async d=>await e._rpcBatchRequest(d)))).flat()).map(d=>(d.error&&mt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${d.error.message}`),d.result.value.map(f=>{if(f){let{data:m,executable:h,lamports:b,owner:T,rentEpoch:S}=f;return m.length!==2&&m[1]!=="base64"&&mt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(m[0],"base64"),executable:h,lamports:b,owner:new sn(T),rentEpoch:S}}return null})))}else try{a=await Promise.all(s.map(c=>e.getMultipleAccountsInfo(c,i)))}catch(c){c instanceof Error&&mt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function ur(e,t,r){let n=await ar(e,t.map(i=>i.pubkey),r);return t.map((i,o)=>({...i,accountInfo:n[o]}))}import ae from"bn.js";var Ae=9e15,fe=1e9,bt="0123456789abcdef",Ge="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",He="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ht={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ae,maxE:Ae,crypto:!1},fr,ie,x=!0,ze="[DecimalError] ",de=ze+"Invalid argument: ",pr=ze+"Precision limit exceeded",mr=ze+"crypto unavailable",gr="[object Decimal]",H=Math.floor,O=Math.pow,an=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,un=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,cn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,yr=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,ee=1e7,P=7,ln=9007199254740991,dn=Ge.length-1,wt=He.length-1,g={toStringTag:gr};g.absoluteValue=g.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),w(e)};g.ceil=function(){return w(new this.constructor(this),this.e+1,2)};g.clampedTo=g.clamp=function(e,t){var r,n=this,i=n.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(de+t);return r=n.cmp(e),r<0?e:n.cmp(t)>0?t:new i(n)};g.comparedTo=g.cmp=function(e){var t,r,n,i,o=this,s=o.d,a=(e=new o.constructor(e)).d,c=o.s,u=e.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(o.e!==e.e)return o.e>e.e^c<0?1:-1;for(n=s.length,i=a.length,t=0,r=n<i?n:i;t<r;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};g.cosine=g.cos=function(){var e,t,r=this,n=r.constructor;return r.d?r.d[0]?(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+P,n.rounding=1,r=fn(n,Tr(n,r)),n.precision=e,n.rounding=t,w(ie==2||ie==3?r.neg():r,e,t,!0)):new n(1):new n(NaN)};g.cubeRoot=g.cbrt=function(){var e,t,r,n,i,o,s,a,c,u,l=this,d=l.constructor;if(!l.isFinite()||l.isZero())return new d(l);for(x=!1,o=l.s*O(l.s*l,1/3),!o||Math.abs(o)==1/0?(r=q(l.d),e=l.e,(o=(e-r.length+1)%3)&&(r+=o==1||o==-2?"0":"00"),o=O(r,1/3),e=H((e+1)/3)-(e%3==(e<0?-1:2)),o==1/0?r="5e"+e:(r=o.toExponential(),r=r.slice(0,r.indexOf("e")+1)+e),n=new d(r),n.s=l.s):n=new d(o.toString()),s=(e=d.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=E(u.plus(l).times(a),u.plus(c),s+2,1),q(a.d).slice(0,s)===(r=q(n.d)).slice(0,s))if(r=r.slice(s-3,s+1),r=="9999"||!i&&r=="4999"){if(!i&&(w(a,e+1,0),a.times(a).times(a).eq(l))){n=a;break}s+=4,i=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(w(n,e+1,1),t=!n.times(n).times(n).eq(l));break}return x=!0,w(n,e,d.rounding,t)};g.decimalPlaces=g.dp=function(){var e,t=this.d,r=NaN;if(t){if(e=t.length-1,r=(e-H(this.e/P))*P,e=t[e],e)for(;e%10==0;e/=10)r--;r<0&&(r=0)}return r};g.dividedBy=g.div=function(e){return E(this,new this.constructor(e))};g.dividedToIntegerBy=g.divToInt=function(e){var t=this,r=t.constructor;return w(E(t,new r(e),0,1,1),r.precision,r.rounding)};g.equals=g.eq=function(e){return this.cmp(e)===0};g.floor=function(){return w(new this.constructor(this),this.e+1,3)};g.greaterThan=g.gt=function(e){return this.cmp(e)>0};g.greaterThanOrEqualTo=g.gte=function(e){var t=this.cmp(e);return t==1||t===0};g.hyperbolicCosine=g.cosh=function(){var e,t,r,n,i,o=this,s=o.constructor,a=new s(1);if(!o.isFinite())return new s(o.s?1/0:NaN);if(o.isZero())return a;r=s.precision,n=s.rounding,s.precision=r+Math.max(o.e,o.sd())+4,s.rounding=1,i=o.d.length,i<32?(e=Math.ceil(i/3),t=(1/Ze(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),o=Le(s,1,o.times(t),new s(1),!0);for(var c,u=e,l=new s(8);u--;)c=o.times(o),o=a.minus(c.times(l.minus(c.times(l))));return w(o,s.precision=r,s.rounding=n,!0)};g.hyperbolicSine=g.sinh=function(){var e,t,r,n,i=this,o=i.constructor;if(!i.isFinite()||i.isZero())return new o(i);if(t=o.precision,r=o.rounding,o.precision=t+Math.max(i.e,i.sd())+4,o.rounding=1,n=i.d.length,n<3)i=Le(o,2,i,i,!0);else{e=1.4*Math.sqrt(n),e=e>16?16:e|0,i=i.times(1/Ze(5,e)),i=Le(o,2,i,i,!0);for(var s,a=new o(5),c=new o(16),u=new o(20);e--;)s=i.times(i),i=i.times(a.plus(s.times(c.times(s).plus(u))))}return o.precision=t,o.rounding=r,w(i,t,r,!0)};g.hyperbolicTangent=g.tanh=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+7,n.rounding=1,E(r.sinh(),r.cosh(),n.precision=e,n.rounding=t)):new n(r.s)};g.inverseCosine=g.acos=function(){var e,t=this,r=t.constructor,n=t.abs().cmp(1),i=r.precision,o=r.rounding;return n!==-1?n===0?t.isNeg()?$(r,i,o):new r(0):new r(NaN):t.isZero()?$(r,i+4,o).times(.5):(r.precision=i+6,r.rounding=1,t=t.asin(),e=$(r,i+4,o).times(.5),r.precision=i,r.rounding=o,e.minus(t))};g.inverseHyperbolicCosine=g.acosh=function(){var e,t,r=this,n=r.constructor;return r.lte(1)?new n(r.eq(1)?0:NaN):r.isFinite()?(e=n.precision,t=n.rounding,n.precision=e+Math.max(Math.abs(r.e),r.sd())+4,n.rounding=1,x=!1,r=r.times(r).minus(1).sqrt().plus(r),x=!0,n.precision=e,n.rounding=t,r.ln()):new n(r)};g.inverseHyperbolicSine=g.asinh=function(){var e,t,r=this,n=r.constructor;return!r.isFinite()||r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+2*Math.max(Math.abs(r.e),r.sd())+6,n.rounding=1,x=!1,r=r.times(r).plus(1).sqrt().plus(r),x=!0,n.precision=e,n.rounding=t,r.ln())};g.inverseHyperbolicTangent=g.atanh=function(){var e,t,r,n,i=this,o=i.constructor;return i.isFinite()?i.e>=0?new o(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=o.precision,t=o.rounding,n=i.sd(),Math.max(n,e)<2*-i.e-1?w(new o(i),e,t,!0):(o.precision=r=n-i.e,i=E(i.plus(1),new o(1).minus(i),r+e,1),o.precision=e+4,o.rounding=1,i=i.ln(),o.precision=e,o.rounding=t,i.times(.5))):new o(NaN)};g.inverseSine=g.asin=function(){var e,t,r,n,i=this,o=i.constructor;return i.isZero()?new o(i):(t=i.abs().cmp(1),r=o.precision,n=o.rounding,t!==-1?t===0?(e=$(o,r+4,n).times(.5),e.s=i.s,e):new o(NaN):(o.precision=r+6,o.rounding=1,i=i.div(new o(1).minus(i.times(i)).sqrt().plus(1)).atan(),o.precision=r,o.rounding=n,i.times(2)))};g.inverseTangent=g.atan=function(){var e,t,r,n,i,o,s,a,c,u=this,l=u.constructor,d=l.precision,f=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&d+4<=wt)return s=$(l,d+4,f).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(d+4<=wt)return s=$(l,d+4,f).times(.5),s.s=u.s,s}for(l.precision=a=d+10,l.rounding=1,r=Math.min(28,a/P+2|0),e=r;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(x=!1,t=Math.ceil(a/P),n=1,c=u.times(u),s=new l(u),i=u;e!==-1;)if(i=i.times(c),o=s.minus(i.div(n+=2)),i=i.times(c),s=o.plus(i.div(n+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===o.d[e]&&e--;);return r&&(s=s.times(2<<r-1)),x=!0,w(s,l.precision=d,l.rounding=f,!0)};g.isFinite=function(){return!!this.d};g.isInteger=g.isInt=function(){return!!this.d&&H(this.e/P)>this.d.length-2};g.isNaN=function(){return!this.s};g.isNegative=g.isNeg=function(){return this.s<0};g.isPositive=g.isPos=function(){return this.s>0};g.isZero=function(){return!!this.d&&this.d[0]===0};g.lessThan=g.lt=function(e){return this.cmp(e)<0};g.lessThanOrEqualTo=g.lte=function(e){return this.cmp(e)<1};g.logarithm=g.log=function(e){var t,r,n,i,o,s,a,c,u=this,l=u.constructor,d=l.precision,f=l.rounding,m=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),r=e.d,e.s<0||!r||!r[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(r=u.d,u.s<0||!r||!r[0]||u.eq(1))return new l(r&&!r[0]?-1/0:u.s!=1?NaN:r?0:1/0);if(t)if(r.length>1)o=!0;else{for(i=r[0];i%10===0;)i/=10;o=i!==1}if(x=!1,a=d+m,s=le(u,a),n=t?je(l,a+10):le(e,a),c=E(s,n,a,1),Ke(c.d,i=d,f))do if(a+=10,s=le(u,a),n=t?je(l,a+10):le(e,a),c=E(s,n,a,1),!o){+q(c.d).slice(i+1,i+15)+1==1e14&&(c=w(c,d+1,0));break}while(Ke(c.d,i+=10,f));return x=!0,w(c,d,f)};g.minus=g.sub=function(e){var t,r,n,i,o,s,a,c,u,l,d,f,m=this,h=m.constructor;if(e=new h(e),!m.d||!e.d)return!m.s||!e.s?e=new h(NaN):m.d?e.s=-e.s:e=new h(e.d||m.s!==e.s?m:NaN),e;if(m.s!=e.s)return e.s=-e.s,m.plus(e);if(u=m.d,f=e.d,a=h.precision,c=h.rounding,!u[0]||!f[0]){if(f[0])e.s=-e.s;else if(u[0])e=new h(m);else return new h(c===3?-0:0);return x?w(e,a,c):e}if(r=H(e.e/P),l=H(m.e/P),u=u.slice(),o=l-r,o){for(d=o<0,d?(t=u,o=-o,s=f.length):(t=f,r=l,s=u.length),n=Math.max(Math.ceil(a/P),s)+2,o>n&&(o=n,t.length=1),t.reverse(),n=o;n--;)t.push(0);t.reverse()}else{for(n=u.length,s=f.length,d=n<s,d&&(s=n),n=0;n<s;n++)if(u[n]!=f[n]){d=u[n]<f[n];break}o=0}for(d&&(t=u,u=f,f=t,e.s=-e.s),s=u.length,n=f.length-s;n>0;--n)u[s++]=0;for(n=f.length;n>o;){if(u[--n]<f[n]){for(i=n;i&&u[--i]===0;)u[i]=ee-1;--u[i],u[n]+=ee}u[n]-=f[n]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--r;return u[0]?(e.d=u,e.e=Ye(u,r),x?w(e,a,c):e):new h(c===3?-0:0)};g.modulo=g.mod=function(e){var t,r=this,n=r.constructor;return e=new n(e),!r.d||!e.s||e.d&&!e.d[0]?new n(NaN):!e.d||r.d&&!r.d[0]?w(new n(r),n.precision,n.rounding):(x=!1,n.modulo==9?(t=E(r,e.abs(),0,3,1),t.s*=e.s):t=E(r,e,0,n.modulo,1),t=t.times(e),x=!0,r.minus(t))};g.naturalExponential=g.exp=function(){return Pt(this)};g.naturalLogarithm=g.ln=function(){return le(this)};g.negated=g.neg=function(){var e=new this.constructor(this);return e.s=-e.s,w(e)};g.plus=g.add=function(e){var t,r,n,i,o,s,a,c,u,l,d=this,f=d.constructor;if(e=new f(e),!d.d||!e.d)return!d.s||!e.s?e=new f(NaN):d.d||(e=new f(e.d||d.s===e.s?d:NaN)),e;if(d.s!=e.s)return e.s=-e.s,d.minus(e);if(u=d.d,l=e.d,a=f.precision,c=f.rounding,!u[0]||!l[0])return l[0]||(e=new f(d)),x?w(e,a,c):e;if(o=H(d.e/P),n=H(e.e/P),u=u.slice(),i=o-n,i){for(i<0?(r=u,i=-i,s=l.length):(r=l,n=o,s=u.length),o=Math.ceil(a/P),s=o>s?o+1:s+1,i>s&&(i=s,r.length=1),r.reverse();i--;)r.push(0);r.reverse()}for(s=u.length,i=l.length,s-i<0&&(i=s,r=l,l=u,u=r),t=0;i;)t=(u[--i]=u[i]+l[i]+t)/ee|0,u[i]%=ee;for(t&&(u.unshift(t),++n),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=Ye(u,n),x?w(e,a,c):e};g.precision=g.sd=function(e){var t,r=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(de+e);return r.d?(t=br(r.d),e&&r.e+1>t&&(t=r.e+1)):t=NaN,t};g.round=function(){var e=this,t=e.constructor;return w(new t(e),e.e+1,t.rounding)};g.sine=g.sin=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+P,n.rounding=1,r=mn(n,Tr(n,r)),n.precision=e,n.rounding=t,w(ie>2?r.neg():r,e,t,!0)):new n(NaN)};g.squareRoot=g.sqrt=function(){var e,t,r,n,i,o,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(x=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=q(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=H((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),n=new l(t)):n=new l(u.toString()),r=(c=l.precision)+3;;)if(o=n,n=o.plus(E(s,o,r+2,1)).times(.5),q(o.d).slice(0,r)===(t=q(n.d)).slice(0,r))if(t=t.slice(r-3,r+1),t=="9999"||!i&&t=="4999"){if(!i&&(w(o,c+1,0),o.times(o).eq(s))){n=o;break}r+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(w(n,c+1,1),e=!n.times(n).eq(s));break}return x=!0,w(n,c,l.rounding,e)};g.tangent=g.tan=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+10,n.rounding=1,r=r.sin(),r.s=1,r=E(r,new n(1).minus(r.times(r)).sqrt(),e+10,0),n.precision=e,n.rounding=t,w(ie==2||ie==4?r.neg():r,e,t,!0)):new n(NaN)};g.times=g.mul=function(e){var t,r,n,i,o,s,a,c,u,l=this,d=l.constructor,f=l.d,m=(e=new d(e)).d;if(e.s*=l.s,!f||!f[0]||!m||!m[0])return new d(!e.s||f&&!f[0]&&!m||m&&!m[0]&&!f?NaN:!f||!m?e.s/0:e.s*0);for(r=H(l.e/P)+H(e.e/P),c=f.length,u=m.length,c<u&&(o=f,f=m,m=o,s=c,c=u,u=s),o=[],s=c+u,n=s;n--;)o.push(0);for(n=u;--n>=0;){for(t=0,i=c+n;i>n;)a=o[i]+m[n]*f[i-n-1]+t,o[i--]=a%ee|0,t=a/ee|0;o[i]=(o[i]+t)%ee|0}for(;!o[--s];)o.pop();return t?++r:o.shift(),e.d=o,e.e=Ye(o,r),x?w(e,d.precision,d.rounding):e};g.toBinary=function(e,t){return xt(this,2,e,t)};g.toDecimalPlaces=g.toDP=function(e,t){var r=this,n=r.constructor;return r=new n(r),e===void 0?r:(Y(e,0,fe),t===void 0?t=n.rounding:Y(t,0,8),w(r,e+r.e+1,t))};g.toExponential=function(e,t){var r,n=this,i=n.constructor;return e===void 0?r=re(n,!0):(Y(e,0,fe),t===void 0?t=i.rounding:Y(t,0,8),n=w(new i(n),e+1,t),r=re(n,!0,e+1)),n.isNeg()&&!n.isZero()?"-"+r:r};g.toFixed=function(e,t){var r,n,i=this,o=i.constructor;return e===void 0?r=re(i):(Y(e,0,fe),t===void 0?t=o.rounding:Y(t,0,8),n=w(new o(i),e+i.e+1,t),r=re(n,!1,e+n.e+1)),i.isNeg()&&!i.isZero()?"-"+r:r};g.toFraction=function(e){var t,r,n,i,o,s,a,c,u,l,d,f,m=this,h=m.d,b=m.constructor;if(!h)return new b(m);if(u=r=new b(1),n=c=new b(0),t=new b(n),o=t.e=br(h)-m.e-1,s=o%P,t.d[0]=O(10,s<0?P+s:s),e==null)e=o>0?t:u;else{if(a=new b(e),!a.isInt()||a.lt(u))throw Error(de+a);e=a.gt(t)?o>0?t:u:a}for(x=!1,a=new b(q(h)),l=b.precision,b.precision=o=h.length*P*2;d=E(a,t,0,1,1),i=r.plus(d.times(n)),i.cmp(e)!=1;)r=n,n=i,i=u,u=c.plus(d.times(i)),c=i,i=t,t=a.minus(d.times(i)),a=i;return i=E(e.minus(r),n,0,1,1),c=c.plus(i.times(u)),r=r.plus(i.times(n)),c.s=u.s=m.s,f=E(u,n,o,1).minus(m).abs().cmp(E(c,r,o,1).minus(m).abs())<1?[u,n]:[c,r],b.precision=l,x=!0,f};g.toHexadecimal=g.toHex=function(e,t){return xt(this,16,e,t)};g.toNearest=function(e,t){var r=this,n=r.constructor;if(r=new n(r),e==null){if(!r.d)return r;e=new n(1),t=n.rounding}else{if(e=new n(e),t===void 0?t=n.rounding:Y(t,0,8),!r.d)return e.s?r:e;if(!e.d)return e.s&&(e.s=r.s),e}return e.d[0]?(x=!1,r=E(r,e,0,t,1).times(e),x=!0,w(r)):(e.s=r.s,r=e),r};g.toNumber=function(){return+this};g.toOctal=function(e,t){return xt(this,8,e,t)};g.toPower=g.pow=function(e){var t,r,n,i,o,s,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(O(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,o=c.rounding,e.eq(1))return w(a,n,o);if(t=H(e.e/P),t>=e.d.length-1&&(r=u<0?-u:u)<=ln)return i=hr(c,a,r,n),e.s<0?new c(1).div(i):w(i,n,o);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return r=O(+a,u),t=r==0||!isFinite(r)?H(u*(Math.log("0."+q(a.d))/Math.LN10+a.e+1)):new c(r+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(x=!1,c.rounding=a.s=1,r=Math.min(12,(t+"").length),i=Pt(e.times(le(a,n+r)),n),i.d&&(i=w(i,n+5,1),Ke(i.d,n,o)&&(t=n+10,i=w(Pt(e.times(le(a,t+r)),t),t+5,1),+q(i.d).slice(n+1,n+15)+1==1e14&&(i=w(i,n+1,0)))),i.s=s,x=!0,c.rounding=o,w(i,n,o))};g.toPrecision=function(e,t){var r,n=this,i=n.constructor;return e===void 0?r=re(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(Y(e,1,fe),t===void 0?t=i.rounding:Y(t,0,8),n=w(new i(n),e,t),r=re(n,e<=n.e||n.e<=i.toExpNeg,e)),n.isNeg()&&!n.isZero()?"-"+r:r};g.toSignificantDigits=g.toSD=function(e,t){var r=this,n=r.constructor;return e===void 0?(e=n.precision,t=n.rounding):(Y(e,1,fe),t===void 0?t=n.rounding:Y(t,0,8)),w(new n(r),e,t)};g.toString=function(){var e=this,t=e.constructor,r=re(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+r:r};g.truncated=g.trunc=function(){return w(new this.constructor(this),this.e+1,1)};g.valueOf=g.toJSON=function(){var e=this,t=e.constructor,r=re(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+r:r};function q(e){var t,r,n,i=e.length-1,o="",s=e[0];if(i>0){for(o+=s,t=1;t<i;t++)n=e[t]+"",r=P-n.length,r&&(o+=ce(r)),o+=n;s=e[t],n=s+"",r=P-n.length,r&&(o+=ce(r))}else if(s===0)return"0";for(;s%10===0;)s/=10;return o+s}function Y(e,t,r){if(e!==~~e||e<t||e>r)throw Error(de+e)}function Ke(e,t,r,n){var i,o,s,a;for(o=e[0];o>=10;o/=10)--t;return--t<0?(t+=P,i=0):(i=Math.ceil((t+1)/P),t%=P),o=O(10,P-t),a=e[i]%o|0,n==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=r<4&&a==99999||r>3&&a==49999||a==5e4||a==0):s=(r<4&&a+1==o||r>3&&a+1==o/2)&&(e[i+1]/o/100|0)==O(10,t-2)-1||(a==o/2||a==0)&&(e[i+1]/o/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(n||r<4)&&a==9999||!n&&r>3&&a==4999):s=((n||r<4)&&a+1==o||!n&&r>3&&a+1==o/2)&&(e[i+1]/o/1e3|0)==O(10,t-3)-1,s}function qe(e,t,r){for(var n,i=[0],o,s=0,a=e.length;s<a;){for(o=i.length;o--;)i[o]*=t;for(i[0]+=bt.indexOf(e.charAt(s++)),n=0;n<i.length;n++)i[n]>r-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/r|0,i[n]%=r)}return i.reverse()}function fn(e,t){var r,n,i;if(t.isZero())return t;n=t.d.length,n<32?(r=Math.ceil(n/3),i=(1/Ze(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),e.precision+=r,t=Le(e,1,t.times(i),new e(1));for(var o=r;o--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=r,t}var E=function(){function e(n,i,o){var s,a=0,c=n.length;for(n=n.slice();c--;)s=n[c]*i+a,n[c]=s%o|0,a=s/o|0;return a&&n.unshift(a),n}function t(n,i,o,s){var a,c;if(o!=s)c=o>s?1:-1;else for(a=c=0;a<o;a++)if(n[a]!=i[a]){c=n[a]>i[a]?1:-1;break}return c}function r(n,i,o,s){for(var a=0;o--;)n[o]-=a,a=n[o]<i[o]?1:0,n[o]=a*s+n[o]-i[o];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,o,s,a,c){var u,l,d,f,m,h,b,T,S,F,R,D,ue,j,pe,Be,we,Pe,X,Te,We=n.constructor,it=n.s==i.s?1:-1,G=n.d,_=i.d;if(!G||!G[0]||!_||!_[0])return new We(!n.s||!i.s||(G?_&&G[0]==_[0]:!_)?NaN:G&&G[0]==0||!_?it*0:it/0);for(c?(m=1,l=n.e-i.e):(c=ee,m=P,l=H(n.e/m)-H(i.e/m)),X=_.length,we=G.length,S=new We(it),F=S.d=[],d=0;_[d]==(G[d]||0);d++);if(_[d]>(G[d]||0)&&l--,o==null?(j=o=We.precision,s=We.rounding):a?j=o+(n.e-i.e)+1:j=o,j<0)F.push(1),h=!0;else{if(j=j/m+2|0,d=0,X==1){for(f=0,_=_[0],j++;(d<we||f)&&j--;d++)pe=f*c+(G[d]||0),F[d]=pe/_|0,f=pe%_|0;h=f||d<we}else{for(f=c/(_[0]+1)|0,f>1&&(_=e(_,f,c),G=e(G,f,c),X=_.length,we=G.length),Be=X,R=G.slice(0,X),D=R.length;D<X;)R[D++]=0;Te=_.slice(),Te.unshift(0),Pe=_[0],_[1]>=c/2&&++Pe;do f=0,u=t(_,R,X,D),u<0?(ue=R[0],X!=D&&(ue=ue*c+(R[1]||0)),f=ue/Pe|0,f>1?(f>=c&&(f=c-1),b=e(_,f,c),T=b.length,D=R.length,u=t(b,R,T,D),u==1&&(f--,r(b,X<T?Te:_,T,c))):(f==0&&(u=f=1),b=_.slice()),T=b.length,T<D&&b.unshift(0),r(R,b,D,c),u==-1&&(D=R.length,u=t(_,R,X,D),u<1&&(f++,r(R,X<D?Te:_,D,c))),D=R.length):u===0&&(f++,R=[0]),F[d++]=f,u&&R[0]?R[D++]=G[Be]||0:(R=[G[Be]],D=1);while((Be++<we||R[0]!==void 0)&&j--);h=R[0]!==void 0}F[0]||F.shift()}if(m==1)S.e=l,fr=h;else{for(d=1,f=F[0];f>=10;f/=10)d++;S.e=d+l*m-1,w(S,a?o+S.e+1:o,s,h)}return S}}();function w(e,t,r,n){var i,o,s,a,c,u,l,d,f,m=e.constructor;e:if(t!=null){if(d=e.d,!d)return e;for(i=1,a=d[0];a>=10;a/=10)i++;if(o=t-i,o<0)o+=P,s=t,l=d[f=0],c=l/O(10,i-s-1)%10|0;else if(f=Math.ceil((o+1)/P),a=d.length,f>=a)if(n){for(;a++<=f;)d.push(0);l=c=0,i=1,o%=P,s=o-P+1}else break e;else{for(l=a=d[f],i=1;a>=10;a/=10)i++;o%=P,s=o-P+i,c=s<0?0:l/O(10,i-s-1)%10|0}if(n=n||t<0||d[f+1]!==void 0||(s<0?l:l%O(10,i-s-1)),u=r<4?(c||n)&&(r==0||r==(e.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(o>0?s>0?l/O(10,i-s):0:d[f-1])%10&1||r==(e.s<0?8:7)),t<1||!d[0])return d.length=0,u?(t-=e.e+1,d[0]=O(10,(P-t%P)%P),e.e=-t||0):d[0]=e.e=0,e;if(o==0?(d.length=f,a=1,f--):(d.length=f+1,a=O(10,P-o),d[f]=s>0?(l/O(10,i-s)%O(10,s)|0)*a:0),u)for(;;)if(f==0){for(o=1,s=d[0];s>=10;s/=10)o++;for(s=d[0]+=a,a=1;s>=10;s/=10)a++;o!=a&&(e.e++,d[0]==ee&&(d[0]=1));break}else{if(d[f]+=a,d[f]!=ee)break;d[f--]=0,a=1}for(o=d.length;d[--o]===0;)d.pop()}return x&&(e.e>m.maxE?(e.d=null,e.e=NaN):e.e<m.minE&&(e.e=0,e.d=[0])),e}function re(e,t,r){if(!e.isFinite())return Pr(e);var n,i=e.e,o=q(e.d),s=o.length;return t?(r&&(n=r-s)>0?o=o.charAt(0)+"."+o.slice(1)+ce(n):s>1&&(o=o.charAt(0)+"."+o.slice(1)),o=o+(e.e<0?"e":"e+")+e.e):i<0?(o="0."+ce(-i-1)+o,r&&(n=r-s)>0&&(o+=ce(n))):i>=s?(o+=ce(i+1-s),r&&(n=r-i-1)>0&&(o=o+"."+ce(n))):((n=i+1)<s&&(o=o.slice(0,n)+"."+o.slice(n)),r&&(n=r-s)>0&&(i+1===s&&(o+="."),o+=ce(n))),o}function Ye(e,t){var r=e[0];for(t*=P;r>=10;r/=10)t++;return t}function je(e,t,r){if(t>dn)throw x=!0,r&&(e.precision=r),Error(pr);return w(new e(Ge),t,1,!0)}function $(e,t,r){if(t>wt)throw Error(pr);return w(new e(He),t,r,!0)}function br(e){var t=e.length-1,r=t*P+1;if(t=e[t],t){for(;t%10==0;t/=10)r--;for(t=e[0];t>=10;t/=10)r++}return r}function ce(e){for(var t="";e--;)t+="0";return t}function hr(e,t,r,n){var i,o=new e(1),s=Math.ceil(n/P+4);for(x=!1;;){if(r%2&&(o=o.times(t),lr(o.d,s)&&(i=!0)),r=H(r/2),r===0){r=o.d.length-1,i&&o.d[r]===0&&++o.d[r];break}t=t.times(t),lr(t.d,s)}return x=!0,o}function cr(e){return e.d[e.d.length-1]&1}function wr(e,t,r){for(var n,i=new e(t[0]),o=0;++o<t.length;)if(n=new e(t[o]),n.s)i[r](n)&&(i=n);else{i=n;break}return i}function Pt(e,t){var r,n,i,o,s,a,c,u=0,l=0,d=0,f=e.constructor,m=f.rounding,h=f.precision;if(!e.d||!e.d[0]||e.e>17)return new f(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=h):c=t,a=new f(.03125);e.e>-2;)e=e.times(a),d+=5;for(n=Math.log(O(2,d))/Math.LN10*2+5|0,c+=n,r=o=s=new f(1),f.precision=c;;){if(o=w(o.times(e),c,1),r=r.times(++l),a=s.plus(E(o,r,c,1)),q(a.d).slice(0,c)===q(s.d).slice(0,c)){for(i=d;i--;)s=w(s.times(s),c,1);if(t==null)if(u<3&&Ke(s.d,c-n,m,u))f.precision=c+=10,r=o=a=new f(1),l=0,u++;else return w(s,f.precision=h,m,x=!0);else return f.precision=h,s}s=a}}function le(e,t){var r,n,i,o,s,a,c,u,l,d,f,m=1,h=10,b=e,T=b.d,S=b.constructor,F=S.rounding,R=S.precision;if(b.s<0||!T||!T[0]||!b.e&&T[0]==1&&T.length==1)return new S(T&&!T[0]?-1/0:b.s!=1?NaN:T?0:b);if(t==null?(x=!1,l=R):l=t,S.precision=l+=h,r=q(T),n=r.charAt(0),Math.abs(o=b.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)b=b.times(e),r=q(b.d),n=r.charAt(0),m++;o=b.e,n>1?(b=new S("0."+r),o++):b=new S(n+"."+r.slice(1))}else return u=je(S,l+2,R).times(o+""),b=le(new S(n+"."+r.slice(1)),l-h).plus(u),S.precision=R,t==null?w(b,R,F,x=!0):b;for(d=b,c=s=b=E(b.minus(1),b.plus(1),l,1),f=w(b.times(b),l,1),i=3;;){if(s=w(s.times(f),l,1),u=c.plus(E(s,new S(i),l,1)),q(u.d).slice(0,l)===q(c.d).slice(0,l))if(c=c.times(2),o!==0&&(c=c.plus(je(S,l+2,R).times(o+""))),c=E(c,new S(m),l,1),t==null)if(Ke(c.d,l-h,F,a))S.precision=l+=h,u=s=b=E(d.minus(1),d.plus(1),l,1),f=w(b.times(b),l,1),i=a=1;else return w(c,S.precision=R,F,x=!0);else return S.precision=R,c;c=u,i+=2}}function Pr(e){return String(e.s*e.s/0)}function Tt(e,t){var r,n,i;for((r=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(r<0&&(r=n),r+=+t.slice(n+1),t=t.substring(0,n)):r<0&&(r=t.length),n=0;t.charCodeAt(n)===48;n++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(n,i),t){if(i-=n,e.e=r=r-n-1,e.d=[],n=(r+1)%P,r<0&&(n+=P),n<i){for(n&&e.d.push(+t.slice(0,n)),i-=P;n<i;)e.d.push(+t.slice(n,n+=P));t=t.slice(n),n=P-t.length}else n-=i;for(;n--;)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 pn(e,t){var r,n,i,o,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),yr.test(t))return Tt(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(un.test(t))r=16,t=t.toLowerCase();else if(an.test(t))r=2;else if(cn.test(t))r=8;else throw Error(de+t);for(o=t.search(/p/i),o>0?(c=+t.slice(o+1),t=t.substring(2,o)):t=t.slice(2),o=t.indexOf("."),s=o>=0,n=e.constructor,s&&(t=t.replace(".",""),a=t.length,o=a-o,i=hr(n,new n(r),o,o*2)),u=qe(t,r,ee),l=u.length-1,o=l;u[o]===0;--o)u.pop();return o<0?new n(e.s*0):(e.e=Ye(u,l),e.d=u,x=!1,s&&(e=E(e,i,a*4)),c&&(e=e.times(Math.abs(c)<54?O(2,c):Xe.pow(2,c))),x=!0,e)}function mn(e,t){var r,n=t.d.length;if(n<3)return t.isZero()?t:Le(e,2,t,t);r=1.4*Math.sqrt(n),r=r>16?16:r|0,t=t.times(1/Ze(5,r)),t=Le(e,2,t,t);for(var i,o=new e(5),s=new e(16),a=new e(20);r--;)i=t.times(t),t=t.times(o.plus(i.times(s.times(i).minus(a))));return t}function Le(e,t,r,n,i){var o,s,a,c,u=1,l=e.precision,d=Math.ceil(l/P);for(x=!1,c=r.times(r),a=new e(n);;){if(s=E(a.times(c),new e(t++*t++),l,1),a=i?n.plus(s):n.minus(s),n=E(s.times(c),new e(t++*t++),l,1),s=a.plus(n),s.d[d]!==void 0){for(o=d;s.d[o]===a.d[o]&&o--;);if(o==-1)break}o=a,a=n,n=s,s=o,u++}return x=!0,s.d.length=d+1,s}function Ze(e,t){for(var r=e;--t;)r*=e;return r}function Tr(e,t){var r,n=t.s<0,i=$(e,e.precision,1),o=i.times(.5);if(t=t.abs(),t.lte(o))return ie=n?4:1,t;if(r=t.divToInt(i),r.isZero())ie=n?3:2;else{if(t=t.minus(r.times(i)),t.lte(o))return ie=cr(r)?n?2:3:n?4:1,t;ie=cr(r)?n?1:4:n?3:2}return t.minus(i).abs()}function xt(e,t,r,n){var i,o,s,a,c,u,l,d,f,m=e.constructor,h=r!==void 0;if(h?(Y(r,1,fe),n===void 0?n=m.rounding:Y(n,0,8)):(r=m.precision,n=m.rounding),!e.isFinite())l=Pr(e);else{for(l=re(e),s=l.indexOf("."),h?(i=2,t==16?r=r*4-3:t==8&&(r=r*3-2)):i=t,s>=0&&(l=l.replace(".",""),f=new m(1),f.e=l.length-s,f.d=qe(re(f),10,i),f.e=f.d.length),d=qe(l,10,i),o=c=d.length;d[--c]==0;)d.pop();if(!d[0])l=h?"0p+0":"0";else{if(s<0?o--:(e=new m(e),e.d=d,e.e=o,e=E(e,f,r,n,0,i),d=e.d,o=e.e,u=fr),s=d[r],a=i/2,u=u||d[r+1]!==void 0,u=n<4?(s!==void 0||u)&&(n===0||n===(e.s<0?3:2)):s>a||s===a&&(n===4||u||n===6&&d[r-1]&1||n===(e.s<0?8:7)),d.length=r,u)for(;++d[--r]>i-1;)d[r]=0,r||(++o,d.unshift(1));for(c=d.length;!d[c-1];--c);for(s=0,l="";s<c;s++)l+=bt.charAt(d[s]);if(h){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(d=qe(l,i,t),c=d.length;!d[c-1];--c);for(s=1,l="1.";s<c;s++)l+=bt.charAt(d[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(o<0?"p":"p+")+o}else if(o<0){for(;++o;)l="0"+l;l="0."+l}else if(++o>c)for(o-=c;o--;)l+="0";else o<c&&(l=l.slice(0,o)+"."+l.slice(o))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function lr(e,t){if(e.length>t)return e.length=t,!0}function gn(e){return new this(e).abs()}function yn(e){return new this(e).acos()}function bn(e){return new this(e).acosh()}function hn(e,t){return new this(e).plus(t)}function wn(e){return new this(e).asin()}function Pn(e){return new this(e).asinh()}function Tn(e){return new this(e).atan()}function xn(e){return new this(e).atanh()}function Sn(e,t){e=new this(e),t=new this(t);var r,n=this.precision,i=this.rounding,o=n+4;return!e.s||!t.s?r=new this(NaN):!e.d&&!t.d?(r=$(this,o,1).times(t.s>0?.25:.75),r.s=e.s):!t.d||e.isZero()?(r=t.s<0?$(this,n,i):new this(0),r.s=e.s):!e.d||t.isZero()?(r=$(this,o,1).times(.5),r.s=e.s):t.s<0?(this.precision=o,this.rounding=1,r=this.atan(E(e,t,o,1)),t=$(this,o,1),this.precision=n,this.rounding=i,r=e.s<0?r.minus(t):r.plus(t)):r=this.atan(E(e,t,o,1)),r}function kn(e){return new this(e).cbrt()}function An(e){return w(e=new this(e),e.e+1,2)}function Ln(e,t,r){return new this(e).clamp(t,r)}function In(e){if(!e||typeof e!="object")throw Error(ze+"Object expected");var t,r,n,i=e.defaults===!0,o=["precision",1,fe,"rounding",0,8,"toExpNeg",-Ae,0,"toExpPos",0,Ae,"maxE",0,Ae,"minE",-Ae,0,"modulo",0,9];for(t=0;t<o.length;t+=3)if(r=o[t],i&&(this[r]=ht[r]),(n=e[r])!==void 0)if(H(n)===n&&n>=o[t+1]&&n<=o[t+2])this[r]=n;else throw Error(de+r+": "+n);if(r="crypto",i&&(this[r]=ht[r]),(n=e[r])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(mr);else this[r]=!1;else throw Error(de+r+": "+n);return this}function Bn(e){return new this(e).cos()}function Rn(e){return new this(e).cosh()}function xr(e){var t,r,n;function i(o){var s,a,c,u=this;if(!(u instanceof i))return new i(o);if(u.constructor=i,dr(o)){u.s=o.s,x?!o.d||o.e>i.maxE?(u.e=NaN,u.d=null):o.e<i.minE?(u.e=0,u.d=[0]):(u.e=o.e,u.d=o.d.slice()):(u.e=o.e,u.d=o.d?o.d.slice():o.d);return}if(c=typeof o,c==="number"){if(o===0){u.s=1/o<0?-1:1,u.e=0,u.d=[0];return}if(o<0?(o=-o,u.s=-1):u.s=1,o===~~o&&o<1e7){for(s=0,a=o;a>=10;a/=10)s++;x?s>i.maxE?(u.e=NaN,u.d=null):s<i.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[o]):(u.e=s,u.d=[o]);return}else if(o*0!==0){o||(u.s=NaN),u.e=NaN,u.d=null;return}return Tt(u,o.toString())}else if(c!=="string")throw Error(de+o);return(a=o.charCodeAt(0))===45?(o=o.slice(1),u.s=-1):(a===43&&(o=o.slice(1)),u.s=1),yr.test(o)?Tt(u,o):pn(u,o)}if(i.prototype=g,i.ROUND_UP=0,i.ROUND_DOWN=1,i.ROUND_CEIL=2,i.ROUND_FLOOR=3,i.ROUND_HALF_UP=4,i.ROUND_HALF_DOWN=5,i.ROUND_HALF_EVEN=6,i.ROUND_HALF_CEIL=7,i.ROUND_HALF_FLOOR=8,i.EUCLID=9,i.config=i.set=In,i.clone=xr,i.isDecimal=dr,i.abs=gn,i.acos=yn,i.acosh=bn,i.add=hn,i.asin=wn,i.asinh=Pn,i.atan=Tn,i.atanh=xn,i.atan2=Sn,i.cbrt=kn,i.ceil=An,i.clamp=Ln,i.cos=Bn,i.cosh=Rn,i.div=Cn,i.exp=Kn,i.floor=Nn,i.hypot=Vn,i.ln=En,i.log=Fn,i.log10=Mn,i.log2=_n,i.max=vn,i.min=Dn,i.mod=Wn,i.mul=On,i.pow=Un,i.random=qn,i.round=Gn,i.sign=Hn,i.sin=jn,i.sinh=zn,i.sqrt=Yn,i.sub=Zn,i.sum=Xn,i.tan=Qn,i.tanh=Jn,i.trunc=$n,e===void 0&&(e={}),e&&e.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<n.length;)e.hasOwnProperty(r=n[t++])||(e[r]=this[r]);return i.config(e),i}function Cn(e,t){return new this(e).div(t)}function Kn(e){return new this(e).exp()}function Nn(e){return w(e=new this(e),e.e+1,3)}function Vn(){var e,t,r=new this(0);for(x=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)r.d&&(r=r.plus(t.times(t)));else{if(t.s)return x=!0,new this(1/0);r=t}return x=!0,r.sqrt()}function dr(e){return e instanceof Xe||e&&e.toStringTag===gr||!1}function En(e){return new this(e).ln()}function Fn(e,t){return new this(e).log(t)}function _n(e){return new this(e).log(2)}function Mn(e){return new this(e).log(10)}function vn(){return wr(this,arguments,"lt")}function Dn(){return wr(this,arguments,"gt")}function Wn(e,t){return new this(e).mod(t)}function On(e,t){return new this(e).mul(t)}function Un(e,t){return new this(e).pow(t)}function qn(e){var t,r,n,i,o=0,s=new this(1),a=[];if(e===void 0?e=this.precision:Y(e,1,fe),n=Math.ceil(e/P),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));o<n;)i=t[o],i>=429e7?t[o]=crypto.getRandomValues(new Uint32Array(1))[0]:a[o++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(n*=4);o<n;)i=t[o]+(t[o+1]<<8)+(t[o+2]<<16)+((t[o+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,o):(a.push(i%1e7),o+=4);o=n/4}else throw Error(mr);else for(;o<n;)a[o++]=Math.random()*1e7|0;for(n=a[--o],e%=P,n&&e&&(i=O(10,P-e),a[o]=(n/i|0)*i);a[o]===0;o--)a.pop();if(o<0)r=0,a=[0];else{for(r=-1;a[0]===0;r-=P)a.shift();for(n=1,i=a[0];i>=10;i/=10)n++;n<P&&(r-=P-n)}return s.e=r,s.d=a,s}function Gn(e){return w(e=new this(e),e.e+1,this.rounding)}function Hn(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function jn(e){return new this(e).sin()}function zn(e){return new this(e).sinh()}function Yn(e){return new this(e).sqrt()}function Zn(e,t){return new this(e).sub(t)}function Xn(){var e=0,t=arguments,r=new this(t[e]);for(x=!1;r.s&&++e<t.length;)r=r.plus(t[e]);return x=!0,w(r,this.precision,this.rounding)}function Qn(e){return new this(e).tan()}function Jn(e){return new this(e).tanh()}function $n(e){return w(e=new this(e),e.e+1,1)}g[Symbol.for("nodejs.util.inspect.custom")]=g.toString;g[Symbol.toStringTag]="Decimal";var Xe=g.constructor=xr(ht);Ge=new Xe(Ge);He=new Xe(He);import ai from"big.js";import $e from"bn.js";import ei from"toformat";var ti=ei,Ne=ti;import Je from"big.js";import ni from"bn.js";import ii from"decimal.js-light";import Ve from"bn.js";var Sr=9007199254740991;function C(e){let t=W("Raydium_parseBigNumberish");if(e instanceof Ve)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new Ve(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=Sr||e<=-Sr)&&t.logWithError(`BigNumberish number overflow: ${e}`),new Ve(String(e))):typeof e=="bigint"?new Ve(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new Ve(0))}var Qe=W("module/fraction"),St=Ne(Je),Ee=Ne(ii),oi={[0]:Ee.ROUND_DOWN,[1]:Ee.ROUND_HALF_UP,[2]:Ee.ROUND_UP},si={[0]:Je.roundDown,[1]:Je.roundHalfUp,[2]:Je.roundUp},N=class{constructor(t,r=new ni(1)){this.numerator=C(t),this.denominator=C(r)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new N(this.denominator,this.numerator)}add(t){let r=t instanceof N?t:new N(C(t));return this.denominator.eq(r.denominator)?new N(this.numerator.add(r.numerator),this.denominator):new N(this.numerator.mul(r.denominator).add(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}sub(t){let r=t instanceof N?t:new N(C(t));return this.denominator.eq(r.denominator)?new N(this.numerator.sub(r.numerator),this.denominator):new N(this.numerator.mul(r.denominator).sub(r.numerator.mul(this.denominator)),this.denominator.mul(r.denominator))}mul(t){let r=t instanceof N?t:new N(C(t));return new N(this.numerator.mul(r.numerator),this.denominator.mul(r.denominator))}div(t){let r=t instanceof N?t:new N(C(t));return new N(this.numerator.mul(r.denominator),this.denominator.mul(r.numerator))}toSignificant(t,r={groupSeparator:""},n=1){Number.isInteger(t)||Qe.logWithError(`${t} is not an integer.`),t<=0&&Qe.logWithError(`${t} is not positive.`),Ee.set({precision:t+1,rounding:oi[n]});let i=new Ee(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return i.toFormat(i.decimalPlaces(),r)}toFixed(t,r={groupSeparator:""},n=1){return Number.isInteger(t)||Qe.logWithError(`${t} is not an integer.`),t<0&&Qe.logWithError(`${t} is negative.`),St.DP=t,St.RM=si[n]||1,new St(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,r)}isZero(){return this.numerator.isZero()}};var ui=W("Raydium_amount"),kr=Ne(ai);function ci(e,t){let r="0",n="0";if(e.includes(".")){let i=e.split(".");i.length===2?([r,n]=i,n=n.padEnd(t,"0")):ui.logWithError(`invalid number string, num: ${e}`)}else r=e;return[r,n.slice(0,t)||n]}var oe=class extends N{constructor(r,n,i=!0,o){let s=new $e(0),a=kt.pow(new $e(r.decimals));if(i)s=C(n);else{let c=new $e(0),u=new $e(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,d]=ci(n.toString(),r.decimals);c=C(l),u=C(d)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=W(o||"TokenAmount"),this.token=r}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(r){return this.token.equals(r.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(r.raw)}lt(r){return this.token.equals(r.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(r.raw)}add(r){return this.token.equals(r.token)||this.logger.logWithError("add token not equals"),new oe(this.token,this.raw.add(r.raw))}subtract(r){return this.token.equals(r.token)||this.logger.logWithError("sub token not equals"),new oe(this.token,this.raw.sub(r.raw))}toSignificant(r=this.token.decimals,n,i=0){return super.toSignificant(r,n,i)}toFixed(r=this.token.decimals,n,i=0){return r>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(r,n,i)}toExact(r={groupSeparator:""}){return kr.DP=this.token.decimals,new kr(this.numerator.toString()).div(this.denominator.toString()).toFormat(r)}};import{PublicKey as li}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Ar}from"@solana/spl-token";var Lr={chainId:101,address:li.default.toBase58(),programId:Ar.toBase58(),decimals:9,symbol:"SOL",name:"solana",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}},ge={chainId:101,address:"So11111111111111111111111111111111111111112",programId:Ar.toBase58(),decimals:9,symbol:"WSOL",name:"Wrapped SOL",logoURI:"https://img.raydium.io/icon/So11111111111111111111111111111111111111112.png",tags:[],priority:2,type:"raydium",extensions:{coingeckoId:"solana"}};import{PublicKey as Bt}from"@solana/web3.js";import{PublicKey as v,SystemProgram as Ir,SYSVAR_RENT_PUBKEY as di}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as fi}from"@solana/spl-token";function p({pubkey:e,isSigner:t=!1,isWritable:r=!0}){return{pubkey:e,isWritable:r,isSigner:t}}var At=[p({pubkey:fi,isWritable:!1}),p({pubkey:Ir.programId,isWritable:!1}),p({pubkey:di,isWritable:!1})];function Br({publicKey:e,transformSol:t}){let r=Lt(e.toString());if(r instanceof v)return t&&r.equals(ye)?yt:r;if(t&&r.toString()===ye.toBase58())return yt;if(typeof r=="string"){if(r===v.default.toBase58())return v.default;try{return new v(r)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Lt(e){try{return new v(e)}catch{return e}}var ha=new v("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),wa=new v("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),It=new v("SysvarRent111111111111111111111111111111111"),Pa=new v("SysvarC1ock11111111111111111111111111111111"),Ta=new v("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),et=new v("Sysvar1nstructions1111111111111111111111111"),xa=Ir.programId,Sa=new v("2cpMA1jNS4obgRz8XNg38QuSP83L1AXpUgfxPNcvnAGj"),ka=new v("Ea5SjE2Y6yvCeW5dYTn7PYMuW5ikXkvbGdcmSnXeaLjS"),Aa=new v("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"),La=new v("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),Ia=new v("Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"),Ba=new v("mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So"),Ra=new v("7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj"),Ca=new v("USDH1SM1ojwWUga67PGrgFWUHibbjqMvuMaDkRJTgkX"),Ka=new v("NRVwhjBQiUPYtfDT5zRBVJajzFQHaBUNtC7SNVvqRFa"),Na=new v("ANAxByE6G2WjFp7A4NqtWYXb3mgruyzZYg3spfxe6Lbo"),Va=new v("7vfCXTUXx5WJV5JADk17DUJ4ksgau7utNKj4b963voxs"),yt=new v("So11111111111111111111111111111111111111112"),ye=v.default;var Rt=class{constructor({mint:t,decimals:r,symbol:n,name:i,skipMint:o=!1,isToken2022:s=!1}){if(t===ye.toBase58()||t instanceof Bt&&ye.equals(t)){this.decimals=ge.decimals,this.symbol=ge.symbol,this.name=ge.name,this.mint=new Bt(ge.address),this.isToken2022=!1;return}this.decimals=r,thi