UNPKG

@cobaltx/sdk-v2

Version:

An SDK for building applications on top of CobaltX.

1 lines 65.3 kB
"use strict";var Nn=Object.create;var Ce=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var Bn=Object.getOwnPropertyNames;var Rn=Object.getPrototypeOf,kn=Object.prototype.hasOwnProperty;var In=(e,t)=>{for(var n in t)Ce(e,n,{get:t[n],enumerable:!0})},Tt=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Bn(t))!kn.call(e,o)&&o!==n&&Ce(e,o,{get:()=>t[o],enumerable:!(r=En(t,o))||r.enumerable});return e};var q=(e,t,n)=>(n=e!=null?Nn(Rn(e)):{},Tt(t||!e||!e.__esModule?Ce(n,"default",{value:e,enumerable:!0}):n,e)),Cn=e=>Tt(Ce({},"__esModule",{value:!0}),e);var fo={};In(fo,{calFarmRewardAmount:()=>ao,farmRewardInfoToConfig:()=>so,fetchMultipleFarmInfoAndUpdate:()=>uo,getAssociatedAuthority:()=>io,getAssociatedLedgerAccount:()=>xn,getAssociatedLedgerPoolAccount:()=>oo,getDepositEntryIndex:()=>lo,getFarmLedgerLayout:()=>An,getFarmStateLayout:()=>Ln,judgeFarmType:()=>co,updateFarmPoolInfo:()=>_n});module.exports=Cn(fo);var H=q(require("bn.js"));var De=require("@solana/spl-token"),St=require("@solana/web3.js");var Te=require("lodash");var et=class{constructor(t){this.logLevel=t.logLevel!==void 0?t.logLevel:0,this.name=t.name}set level(t){this.logLevel=t}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(t){return t<=this.logLevel}error(...t){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...t),this):this}logWithError(...t){let n=t.map(r=>typeof r=="object"?JSON.stringify(r):r).join(", ");throw new Error(n)}warning(...t){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...t),this):this}info(...t){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...t),this):this}debug(...t){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...t),this):this}},yt={},Dn={};function F(e){let t=(0,Te.get)(yt,e);if(!t){let n=(0,Te.get)(Dn,e);t=new et({name:e,logLevel:n}),(0,Te.set)(yt,e,t)}return t}var tt=F("CobaltX_accountInfo_util");async function Pt(e,t,n){let{batchRequest:r,commitment:o="confirmed",chunkCount:i=100}={batchRequest:!1,...n},s=nt(t,i),a=new Array(s.length).fill([]);if(r){let c=s.map(d=>{let f=e._buildArgs([d.map(p=>p.toBase58())],o,"base64");return{methodName:"getMultipleAccounts",args:f}}),u=nt(c,10);a=(await(await Promise.all(u.map(async d=>await e._rpcBatchRequest(d)))).flat()).map(d=>(d.error&&tt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${d.error.message}`),d.result.value.map(f=>{if(f){let{data:p,executable:S,lamports:T,owner:_,rentEpoch:A}=f;return p.length!==2&&p[1]!=="base64"&&tt.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:S,lamports:T,owner:new St.PublicKey(_),rentEpoch:A}}return null})))}else try{a=await Promise.all(s.map(c=>e.getMultipleAccountsInfo(c,o)))}catch(c){c instanceof Error&&tt.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function xt(e,t,n){let r=await Pt(e,t.map(o=>o.pubkey),n);return t.map((o,i)=>({...o,accountInfo:r[i]}))}var Q=q(require("bn.js"));var de=9e15,se=1e9,rt="0123456789abcdef",Ve="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",ve="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",ot={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-de,maxE:de,crypto:!1},Et,$,y=!0,Ke="[DecimalError] ",ie=Ke+"Invalid argument: ",Bt=Ke+"Precision limit exceeded",Rt=Ke+"crypto unavailable",kt="[object Decimal]",W=Math.floor,V=Math.pow,Mn=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,On=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,Vn=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,It=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,Y=1e7,b=7,vn=9007199254740991,Fn=Ve.length-1,it=ve.length-1,m={toStringTag:kt};m.absoluteValue=m.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),h(e)};m.ceil=function(){return h(new this.constructor(this),this.e+1,2)};m.clampedTo=m.clamp=function(e,t){var n,r=this,o=r.constructor;if(e=new o(e),t=new o(t),!e.s||!t.s)return new o(NaN);if(e.gt(t))throw Error(ie+t);return n=r.cmp(e),n<0?e:r.cmp(t)>0?t:new o(r)};m.comparedTo=m.cmp=function(e){var t,n,r,o,i=this,s=i.d,a=(e=new i.constructor(e)).d,c=i.s,u=e.s;if(!s||!a)return!c||!u?NaN:c!==u?c:s===a?0:!s^c<0?1:-1;if(!s[0]||!a[0])return s[0]?c:a[0]?-u:0;if(c!==u)return c;if(i.e!==e.e)return i.e>e.e^c<0?1:-1;for(r=s.length,o=a.length,t=0,n=r<o?r:o;t<n;++t)if(s[t]!==a[t])return s[t]>a[t]^c<0?1:-1;return r===o?0:r>o^c<0?1:-1};m.cosine=m.cos=function(){var e,t,n=this,r=n.constructor;return n.d?n.d[0]?(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+b,r.rounding=1,n=Kn(r,Vt(r,n)),r.precision=e,r.rounding=t,h($==2||$==3?n.neg():n,e,t,!0)):new r(1):new r(NaN)};m.cubeRoot=m.cbrt=function(){var e,t,n,r,o,i,s,a,c,u,l=this,d=l.constructor;if(!l.isFinite()||l.isZero())return new d(l);for(y=!1,i=l.s*V(l.s*l,1/3),!i||Math.abs(i)==1/0?(n=K(l.d),e=l.e,(i=(e-n.length+1)%3)&&(n+=i==1||i==-2?"0":"00"),i=V(n,1/3),e=W((e+1)/3)-(e%3==(e<0?-1:2)),i==1/0?n="5e"+e:(n=i.toExponential(),n=n.slice(0,n.indexOf("e")+1)+e),r=new d(n),r.s=l.s):r=new d(i.toString()),s=(e=d.precision)+3;;)if(a=r,c=a.times(a).times(a),u=c.plus(l),r=R(u.plus(l).times(a),u.plus(c),s+2,1),K(a.d).slice(0,s)===(n=K(r.d)).slice(0,s))if(n=n.slice(s-3,s+1),n=="9999"||!o&&n=="4999"){if(!o&&(h(a,e+1,0),a.times(a).times(a).eq(l))){r=a;break}s+=4,o=1}else{(!+n||!+n.slice(1)&&n.charAt(0)=="5")&&(h(r,e+1,1),t=!r.times(r).times(r).eq(l));break}return y=!0,h(r,e,d.rounding,t)};m.decimalPlaces=m.dp=function(){var e,t=this.d,n=NaN;if(t){if(e=t.length-1,n=(e-W(this.e/b))*b,e=t[e],e)for(;e%10==0;e/=10)n--;n<0&&(n=0)}return n};m.dividedBy=m.div=function(e){return R(this,new this.constructor(e))};m.dividedToIntegerBy=m.divToInt=function(e){var t=this,n=t.constructor;return h(R(t,new n(e),0,1,1),n.precision,n.rounding)};m.equals=m.eq=function(e){return this.cmp(e)===0};m.floor=function(){return h(new this.constructor(this),this.e+1,3)};m.greaterThan=m.gt=function(e){return this.cmp(e)>0};m.greaterThanOrEqualTo=m.gte=function(e){var t=this.cmp(e);return t==1||t===0};m.hyperbolicCosine=m.cosh=function(){var e,t,n,r,o,i=this,s=i.constructor,a=new s(1);if(!i.isFinite())return new s(i.s?1/0:NaN);if(i.isZero())return a;n=s.precision,r=s.rounding,s.precision=n+Math.max(i.e,i.sd())+4,s.rounding=1,o=i.d.length,o<32?(e=Math.ceil(o/3),t=(1/We(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),i=fe(s,1,i.times(t),new s(1),!0);for(var c,u=e,l=new s(8);u--;)c=i.times(i),i=a.minus(c.times(l.minus(c.times(l))));return h(i,s.precision=n,s.rounding=r,!0)};m.hyperbolicSine=m.sinh=function(){var e,t,n,r,o=this,i=o.constructor;if(!o.isFinite()||o.isZero())return new i(o);if(t=i.precision,n=i.rounding,i.precision=t+Math.max(o.e,o.sd())+4,i.rounding=1,r=o.d.length,r<3)o=fe(i,2,o,o,!0);else{e=1.4*Math.sqrt(r),e=e>16?16:e|0,o=o.times(1/We(5,e)),o=fe(i,2,o,o,!0);for(var s,a=new i(5),c=new i(16),u=new i(20);e--;)s=o.times(o),o=o.times(a.plus(s.times(c.times(s).plus(u))))}return i.precision=t,i.rounding=n,h(o,t,n,!0)};m.hyperbolicTangent=m.tanh=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+7,r.rounding=1,R(n.sinh(),n.cosh(),r.precision=e,r.rounding=t)):new r(n.s)};m.inverseCosine=m.acos=function(){var e=this,t=e.constructor,n=e.abs().cmp(1),r=t.precision,o=t.rounding;return n!==-1?n===0?e.isNeg()?z(t,r,o):new t(0):new t(NaN):e.isZero()?z(t,r+4,o).times(.5):(t.precision=r+6,t.rounding=1,e=new t(1).minus(e).div(e.plus(1)).sqrt().atan(),t.precision=r,t.rounding=o,e.times(2))};m.inverseHyperbolicCosine=m.acosh=function(){var e,t,n=this,r=n.constructor;return n.lte(1)?new r(n.eq(1)?0:NaN):n.isFinite()?(e=r.precision,t=r.rounding,r.precision=e+Math.max(Math.abs(n.e),n.sd())+4,r.rounding=1,y=!1,n=n.times(n).minus(1).sqrt().plus(n),y=!0,r.precision=e,r.rounding=t,n.ln()):new r(n)};m.inverseHyperbolicSine=m.asinh=function(){var e,t,n=this,r=n.constructor;return!n.isFinite()||n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+2*Math.max(Math.abs(n.e),n.sd())+6,r.rounding=1,y=!1,n=n.times(n).plus(1).sqrt().plus(n),y=!0,r.precision=e,r.rounding=t,n.ln())};m.inverseHyperbolicTangent=m.atanh=function(){var e,t,n,r,o=this,i=o.constructor;return o.isFinite()?o.e>=0?new i(o.abs().eq(1)?o.s/0:o.isZero()?o:NaN):(e=i.precision,t=i.rounding,r=o.sd(),Math.max(r,e)<2*-o.e-1?h(new i(o),e,t,!0):(i.precision=n=r-o.e,o=R(o.plus(1),new i(1).minus(o),n+e,1),i.precision=e+4,i.rounding=1,o=o.ln(),i.precision=e,i.rounding=t,o.times(.5))):new i(NaN)};m.inverseSine=m.asin=function(){var e,t,n,r,o=this,i=o.constructor;return o.isZero()?new i(o):(t=o.abs().cmp(1),n=i.precision,r=i.rounding,t!==-1?t===0?(e=z(i,n+4,r).times(.5),e.s=o.s,e):new i(NaN):(i.precision=n+6,i.rounding=1,o=o.div(new i(1).minus(o.times(o)).sqrt().plus(1)).atan(),i.precision=n,i.rounding=r,o.times(2)))};m.inverseTangent=m.atan=function(){var e,t,n,r,o,i,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<=it)return s=z(l,d+4,f).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(d+4<=it)return s=z(l,d+4,f).times(.5),s.s=u.s,s}for(l.precision=a=d+10,l.rounding=1,n=Math.min(28,a/b+2|0),e=n;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(y=!1,t=Math.ceil(a/b),r=1,c=u.times(u),s=new l(u),o=u;e!==-1;)if(o=o.times(c),i=s.minus(o.div(r+=2)),o=o.times(c),s=i.plus(o.div(r+=2)),s.d[t]!==void 0)for(e=t;s.d[e]===i.d[e]&&e--;);return n&&(s=s.times(2<<n-1)),y=!0,h(s,l.precision=d,l.rounding=f,!0)};m.isFinite=function(){return!!this.d};m.isInteger=m.isInt=function(){return!!this.d&&W(this.e/b)>this.d.length-2};m.isNaN=function(){return!this.s};m.isNegative=m.isNeg=function(){return this.s<0};m.isPositive=m.isPos=function(){return this.s>0};m.isZero=function(){return!!this.d&&this.d[0]===0};m.lessThan=m.lt=function(e){return this.cmp(e)<0};m.lessThanOrEqualTo=m.lte=function(e){return this.cmp(e)<1};m.logarithm=m.log=function(e){var t,n,r,o,i,s,a,c,u=this,l=u.constructor,d=l.precision,f=l.rounding,p=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),n=e.d,e.s<0||!n||!n[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(n=u.d,u.s<0||!n||!n[0]||u.eq(1))return new l(n&&!n[0]?-1/0:u.s!=1?NaN:n?0:1/0);if(t)if(n.length>1)i=!0;else{for(o=n[0];o%10===0;)o/=10;i=o!==1}if(y=!1,a=d+p,s=oe(u,a),r=t?Fe(l,a+10):oe(e,a),c=R(s,r,a,1),ye(c.d,o=d,f))do if(a+=10,s=oe(u,a),r=t?Fe(l,a+10):oe(e,a),c=R(s,r,a,1),!i){+K(c.d).slice(o+1,o+15)+1==1e14&&(c=h(c,d+1,0));break}while(ye(c.d,o+=10,f));return y=!0,h(c,d,f)};m.minus=m.sub=function(e){var t,n,r,o,i,s,a,c,u,l,d,f,p=this,S=p.constructor;if(e=new S(e),!p.d||!e.d)return!p.s||!e.s?e=new S(NaN):p.d?e.s=-e.s:e=new S(e.d||p.s!==e.s?p:NaN),e;if(p.s!=e.s)return e.s=-e.s,p.plus(e);if(u=p.d,f=e.d,a=S.precision,c=S.rounding,!u[0]||!f[0]){if(f[0])e.s=-e.s;else if(u[0])e=new S(p);else return new S(c===3?-0:0);return y?h(e,a,c):e}if(n=W(e.e/b),l=W(p.e/b),u=u.slice(),i=l-n,i){for(d=i<0,d?(t=u,i=-i,s=f.length):(t=f,n=l,s=u.length),r=Math.max(Math.ceil(a/b),s)+2,i>r&&(i=r,t.length=1),t.reverse(),r=i;r--;)t.push(0);t.reverse()}else{for(r=u.length,s=f.length,d=r<s,d&&(s=r),r=0;r<s;r++)if(u[r]!=f[r]){d=u[r]<f[r];break}i=0}for(d&&(t=u,u=f,f=t,e.s=-e.s),s=u.length,r=f.length-s;r>0;--r)u[s++]=0;for(r=f.length;r>i;){if(u[--r]<f[r]){for(o=r;o&&u[--o]===0;)u[o]=Y-1;--u[o],u[r]+=Y}u[r]-=f[r]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--n;return u[0]?(e.d=u,e.e=Ue(u,n),y?h(e,a,c):e):new S(c===3?-0:0)};m.modulo=m.mod=function(e){var t,n=this,r=n.constructor;return e=new r(e),!n.d||!e.s||e.d&&!e.d[0]?new r(NaN):!e.d||n.d&&!n.d[0]?h(new r(n),r.precision,r.rounding):(y=!1,r.modulo==9?(t=R(n,e.abs(),0,3,1),t.s*=e.s):t=R(n,e,0,r.modulo,1),t=t.times(e),y=!0,n.minus(t))};m.naturalExponential=m.exp=function(){return st(this)};m.naturalLogarithm=m.ln=function(){return oe(this)};m.negated=m.neg=function(){var e=new this.constructor(this);return e.s=-e.s,h(e)};m.plus=m.add=function(e){var t,n,r,o,i,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)),y?h(e,a,c):e;if(i=W(d.e/b),r=W(e.e/b),u=u.slice(),o=i-r,o){for(o<0?(n=u,o=-o,s=l.length):(n=l,r=i,s=u.length),i=Math.ceil(a/b),s=i>s?i+1:s+1,o>s&&(o=s,n.length=1),n.reverse();o--;)n.push(0);n.reverse()}for(s=u.length,o=l.length,s-o<0&&(o=s,n=l,l=u,u=n),t=0;o;)t=(u[--o]=u[o]+l[o]+t)/Y|0,u[o]%=Y;for(t&&(u.unshift(t),++r),s=u.length;u[--s]==0;)u.pop();return e.d=u,e.e=Ue(u,r),y?h(e,a,c):e};m.precision=m.sd=function(e){var t,n=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(ie+e);return n.d?(t=Ct(n.d),e&&n.e+1>t&&(t=n.e+1)):t=NaN,t};m.round=function(){var e=this,t=e.constructor;return h(new t(e),e.e+1,t.rounding)};m.sine=m.sin=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+Math.max(n.e,n.sd())+b,r.rounding=1,n=Wn(r,Vt(r,n)),r.precision=e,r.rounding=t,h($>2?n.neg():n,e,t,!0)):new r(NaN)};m.squareRoot=m.sqrt=function(){var e,t,n,r,o,i,s=this,a=s.d,c=s.e,u=s.s,l=s.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?s:1/0);for(y=!1,u=Math.sqrt(+s),u==0||u==1/0?(t=K(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=W((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),r=new l(t)):r=new l(u.toString()),n=(c=l.precision)+3;;)if(i=r,r=i.plus(R(s,i,n+2,1)).times(.5),K(i.d).slice(0,n)===(t=K(r.d)).slice(0,n))if(t=t.slice(n-3,n+1),t=="9999"||!o&&t=="4999"){if(!o&&(h(i,c+1,0),i.times(i).eq(s))){r=i;break}n+=4,o=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(h(r,c+1,1),e=!r.times(r).eq(s));break}return y=!0,h(r,c,l.rounding,e)};m.tangent=m.tan=function(){var e,t,n=this,r=n.constructor;return n.isFinite()?n.isZero()?new r(n):(e=r.precision,t=r.rounding,r.precision=e+10,r.rounding=1,n=n.sin(),n.s=1,n=R(n,new r(1).minus(n.times(n)).sqrt(),e+10,0),r.precision=e,r.rounding=t,h($==2||$==4?n.neg():n,e,t,!0)):new r(NaN)};m.times=m.mul=function(e){var t,n,r,o,i,s,a,c,u,l=this,d=l.constructor,f=l.d,p=(e=new d(e)).d;if(e.s*=l.s,!f||!f[0]||!p||!p[0])return new d(!e.s||f&&!f[0]&&!p||p&&!p[0]&&!f?NaN:!f||!p?e.s/0:e.s*0);for(n=W(l.e/b)+W(e.e/b),c=f.length,u=p.length,c<u&&(i=f,f=p,p=i,s=c,c=u,u=s),i=[],s=c+u,r=s;r--;)i.push(0);for(r=u;--r>=0;){for(t=0,o=c+r;o>r;)a=i[o]+p[r]*f[o-r-1]+t,i[o--]=a%Y|0,t=a/Y|0;i[o]=(i[o]+t)%Y|0}for(;!i[--s];)i.pop();return t?++n:i.shift(),e.d=i,e.e=Ue(i,n),y?h(e,d.precision,d.rounding):e};m.toBinary=function(e,t){return at(this,2,e,t)};m.toDecimalPlaces=m.toDP=function(e,t){var n=this,r=n.constructor;return n=new r(n),e===void 0?n:(G(e,0,se),t===void 0?t=r.rounding:G(t,0,8),h(n,e+n.e+1,t))};m.toExponential=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=X(r,!0):(G(e,0,se),t===void 0?t=o.rounding:G(t,0,8),r=h(new o(r),e+1,t),n=X(r,!0,e+1)),r.isNeg()&&!r.isZero()?"-"+n:n};m.toFixed=function(e,t){var n,r,o=this,i=o.constructor;return e===void 0?n=X(o):(G(e,0,se),t===void 0?t=i.rounding:G(t,0,8),r=h(new i(o),e+o.e+1,t),n=X(r,!1,e+r.e+1)),o.isNeg()&&!o.isZero()?"-"+n:n};m.toFraction=function(e){var t,n,r,o,i,s,a,c,u,l,d,f,p=this,S=p.d,T=p.constructor;if(!S)return new T(p);if(u=n=new T(1),r=c=new T(0),t=new T(r),i=t.e=Ct(S)-p.e-1,s=i%b,t.d[0]=V(10,s<0?b+s:s),e==null)e=i>0?t:u;else{if(a=new T(e),!a.isInt()||a.lt(u))throw Error(ie+a);e=a.gt(t)?i>0?t:u:a}for(y=!1,a=new T(K(S)),l=T.precision,T.precision=i=S.length*b*2;d=R(a,t,0,1,1),o=n.plus(d.times(r)),o.cmp(e)!=1;)n=r,r=o,o=u,u=c.plus(d.times(o)),c=o,o=t,t=a.minus(d.times(o)),a=o;return o=R(e.minus(n),r,0,1,1),c=c.plus(o.times(u)),n=n.plus(o.times(r)),c.s=u.s=p.s,f=R(u,r,i,1).minus(p).abs().cmp(R(c,n,i,1).minus(p).abs())<1?[u,r]:[c,n],T.precision=l,y=!0,f};m.toHexadecimal=m.toHex=function(e,t){return at(this,16,e,t)};m.toNearest=function(e,t){var n=this,r=n.constructor;if(n=new r(n),e==null){if(!n.d)return n;e=new r(1),t=r.rounding}else{if(e=new r(e),t===void 0?t=r.rounding:G(t,0,8),!n.d)return e.s?n:e;if(!e.d)return e.s&&(e.s=n.s),e}return e.d[0]?(y=!1,n=R(n,e,0,t,1).times(e),y=!0,h(n)):(e.s=n.s,n=e),n};m.toNumber=function(){return+this};m.toOctal=function(e,t){return at(this,8,e,t)};m.toPower=m.pow=function(e){var t,n,r,o,i,s,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(V(+a,u));if(a=new c(a),a.eq(1))return a;if(r=c.precision,i=c.rounding,e.eq(1))return h(a,r,i);if(t=W(e.e/b),t>=e.d.length-1&&(n=u<0?-u:u)<=vn)return o=Dt(c,a,n,r),e.s<0?new c(1).div(o):h(o,r,i);if(s=a.s,s<0){if(t<e.d.length-1)return new c(NaN);if((e.d[t]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return n=V(+a,u),t=n==0||!isFinite(n)?W(u*(Math.log("0."+K(a.d))/Math.LN10+a.e+1)):new c(n+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?s/0:0):(y=!1,c.rounding=a.s=1,n=Math.min(12,(t+"").length),o=st(e.times(oe(a,r+n)),r),o.d&&(o=h(o,r+5,1),ye(o.d,r,i)&&(t=r+10,o=h(st(e.times(oe(a,t+n)),t),t+5,1),+K(o.d).slice(r+1,r+15)+1==1e14&&(o=h(o,r+1,0)))),o.s=s,y=!0,c.rounding=i,h(o,r,i))};m.toPrecision=function(e,t){var n,r=this,o=r.constructor;return e===void 0?n=X(r,r.e<=o.toExpNeg||r.e>=o.toExpPos):(G(e,1,se),t===void 0?t=o.rounding:G(t,0,8),r=h(new o(r),e,t),n=X(r,e<=r.e||r.e<=o.toExpNeg,e)),r.isNeg()&&!r.isZero()?"-"+n:n};m.toSignificantDigits=m.toSD=function(e,t){var n=this,r=n.constructor;return e===void 0?(e=r.precision,t=r.rounding):(G(e,1,se),t===void 0?t=r.rounding:G(t,0,8)),h(new r(n),e,t)};m.toString=function(){var e=this,t=e.constructor,n=X(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+n:n};m.truncated=m.trunc=function(){return h(new this.constructor(this),this.e+1,1)};m.valueOf=m.toJSON=function(){var e=this,t=e.constructor,n=X(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+n:n};function K(e){var t,n,r,o=e.length-1,i="",s=e[0];if(o>0){for(i+=s,t=1;t<o;t++)r=e[t]+"",n=b-r.length,n&&(i+=re(n)),i+=r;s=e[t],r=s+"",n=b-r.length,n&&(i+=re(n))}else if(s===0)return"0";for(;s%10===0;)s/=10;return i+s}function G(e,t,n){if(e!==~~e||e<t||e>n)throw Error(ie+e)}function ye(e,t,n,r){var o,i,s,a;for(i=e[0];i>=10;i/=10)--t;return--t<0?(t+=b,o=0):(o=Math.ceil((t+1)/b),t%=b),i=V(10,b-t),a=e[o]%i|0,r==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),s=n<4&&a==99999||n>3&&a==49999||a==5e4||a==0):s=(n<4&&a+1==i||n>3&&a+1==i/2)&&(e[o+1]/i/100|0)==V(10,t-2)-1||(a==i/2||a==0)&&(e[o+1]/i/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),s=(r||n<4)&&a==9999||!r&&n>3&&a==4999):s=((r||n<4)&&a+1==i||!r&&n>3&&a+1==i/2)&&(e[o+1]/i/1e3|0)==V(10,t-3)-1,s}function Me(e,t,n){for(var r,o=[0],i,s=0,a=e.length;s<a;){for(i=o.length;i--;)o[i]*=t;for(o[0]+=rt.indexOf(e.charAt(s++)),r=0;r<o.length;r++)o[r]>n-1&&(o[r+1]===void 0&&(o[r+1]=0),o[r+1]+=o[r]/n|0,o[r]%=n)}return o.reverse()}function Kn(e,t){var n,r,o;if(t.isZero())return t;r=t.d.length,r<32?(n=Math.ceil(r/3),o=(1/We(4,n)).toString()):(n=16,o="2.3283064365386962890625e-10"),e.precision+=n,t=fe(e,1,t.times(o),new e(1));for(var i=n;i--;){var s=t.times(t);t=s.times(s).minus(s).times(8).plus(1)}return e.precision-=n,t}var R=function(){function e(r,o,i){var s,a=0,c=r.length;for(r=r.slice();c--;)s=r[c]*o+a,r[c]=s%i|0,a=s/i|0;return a&&r.unshift(a),r}function t(r,o,i,s){var a,c;if(i!=s)c=i>s?1:-1;else for(a=c=0;a<i;a++)if(r[a]!=o[a]){c=r[a]>o[a]?1:-1;break}return c}function n(r,o,i,s){for(var a=0;i--;)r[i]-=a,a=r[i]<o[i]?1:0,r[i]=a*s+r[i]-o[i];for(;!r[0]&&r.length>1;)r.shift()}return function(r,o,i,s,a,c){var u,l,d,f,p,S,T,_,A,O,E,v,Be,J,Qe,Re,be,Je,j,ke,Ie=r.constructor,$e=r.s==o.s?1:-1,U=r.d,k=o.d;if(!U||!U[0]||!k||!k[0])return new Ie(!r.s||!o.s||(U?k&&U[0]==k[0]:!k)?NaN:U&&U[0]==0||!k?$e*0:$e/0);for(c?(p=1,l=r.e-o.e):(c=Y,p=b,l=W(r.e/p)-W(o.e/p)),j=k.length,be=U.length,A=new Ie($e),O=A.d=[],d=0;k[d]==(U[d]||0);d++);if(k[d]>(U[d]||0)&&l--,i==null?(J=i=Ie.precision,s=Ie.rounding):a?J=i+(r.e-o.e)+1:J=i,J<0)O.push(1),S=!0;else{if(J=J/p+2|0,d=0,j==1){for(f=0,k=k[0],J++;(d<be||f)&&J--;d++)Qe=f*c+(U[d]||0),O[d]=Qe/k|0,f=Qe%k|0;S=f||d<be}else{for(f=c/(k[0]+1)|0,f>1&&(k=e(k,f,c),U=e(U,f,c),j=k.length,be=U.length),Re=j,E=U.slice(0,j),v=E.length;v<j;)E[v++]=0;ke=k.slice(),ke.unshift(0),Je=k[0],k[1]>=c/2&&++Je;do f=0,u=t(k,E,j,v),u<0?(Be=E[0],j!=v&&(Be=Be*c+(E[1]||0)),f=Be/Je|0,f>1?(f>=c&&(f=c-1),T=e(k,f,c),_=T.length,v=E.length,u=t(T,E,_,v),u==1&&(f--,n(T,j<_?ke:k,_,c))):(f==0&&(u=f=1),T=k.slice()),_=T.length,_<v&&T.unshift(0),n(E,T,v,c),u==-1&&(v=E.length,u=t(k,E,j,v),u<1&&(f++,n(E,j<v?ke:k,v,c))),v=E.length):u===0&&(f++,E=[0]),O[d++]=f,u&&E[0]?E[v++]=U[Re]||0:(E=[U[Re]],v=1);while((Re++<be||E[0]!==void 0)&&J--);S=E[0]!==void 0}O[0]||O.shift()}if(p==1)A.e=l,Et=S;else{for(d=1,f=O[0];f>=10;f/=10)d++;A.e=d+l*p-1,h(A,a?i+A.e+1:i,s,S)}return A}}();function h(e,t,n,r){var o,i,s,a,c,u,l,d,f,p=e.constructor;e:if(t!=null){if(d=e.d,!d)return e;for(o=1,a=d[0];a>=10;a/=10)o++;if(i=t-o,i<0)i+=b,s=t,l=d[f=0],c=l/V(10,o-s-1)%10|0;else if(f=Math.ceil((i+1)/b),a=d.length,f>=a)if(r){for(;a++<=f;)d.push(0);l=c=0,o=1,i%=b,s=i-b+1}else break e;else{for(l=a=d[f],o=1;a>=10;a/=10)o++;i%=b,s=i-b+o,c=s<0?0:l/V(10,o-s-1)%10|0}if(r=r||t<0||d[f+1]!==void 0||(s<0?l:l%V(10,o-s-1)),u=n<4?(c||r)&&(n==0||n==(e.s<0?3:2)):c>5||c==5&&(n==4||r||n==6&&(i>0?s>0?l/V(10,o-s):0:d[f-1])%10&1||n==(e.s<0?8:7)),t<1||!d[0])return d.length=0,u?(t-=e.e+1,d[0]=V(10,(b-t%b)%b),e.e=-t||0):d[0]=e.e=0,e;if(i==0?(d.length=f,a=1,f--):(d.length=f+1,a=V(10,b-i),d[f]=s>0?(l/V(10,o-s)%V(10,s)|0)*a:0),u)for(;;)if(f==0){for(i=1,s=d[0];s>=10;s/=10)i++;for(s=d[0]+=a,a=1;s>=10;s/=10)a++;i!=a&&(e.e++,d[0]==Y&&(d[0]=1));break}else{if(d[f]+=a,d[f]!=Y)break;d[f--]=0,a=1}for(i=d.length;d[--i]===0;)d.pop()}return y&&(e.e>p.maxE?(e.d=null,e.e=NaN):e.e<p.minE&&(e.e=0,e.d=[0])),e}function X(e,t,n){if(!e.isFinite())return Ot(e);var r,o=e.e,i=K(e.d),s=i.length;return t?(n&&(r=n-s)>0?i=i.charAt(0)+"."+i.slice(1)+re(r):s>1&&(i=i.charAt(0)+"."+i.slice(1)),i=i+(e.e<0?"e":"e+")+e.e):o<0?(i="0."+re(-o-1)+i,n&&(r=n-s)>0&&(i+=re(r))):o>=s?(i+=re(o+1-s),n&&(r=n-o-1)>0&&(i=i+"."+re(r))):((r=o+1)<s&&(i=i.slice(0,r)+"."+i.slice(r)),n&&(r=n-s)>0&&(o+1===s&&(i+="."),i+=re(r))),i}function Ue(e,t){var n=e[0];for(t*=b;n>=10;n/=10)t++;return t}function Fe(e,t,n){if(t>Fn)throw y=!0,n&&(e.precision=n),Error(Bt);return h(new e(Ve),t,1,!0)}function z(e,t,n){if(t>it)throw Error(Bt);return h(new e(ve),t,n,!0)}function Ct(e){var t=e.length-1,n=t*b+1;if(t=e[t],t){for(;t%10==0;t/=10)n--;for(t=e[0];t>=10;t/=10)n++}return n}function re(e){for(var t="";e--;)t+="0";return t}function Dt(e,t,n,r){var o,i=new e(1),s=Math.ceil(r/b+4);for(y=!1;;){if(n%2&&(i=i.times(t),_t(i.d,s)&&(o=!0)),n=W(n/2),n===0){n=i.d.length-1,o&&i.d[n]===0&&++i.d[n];break}t=t.times(t),_t(t.d,s)}return y=!0,i}function Lt(e){return e.d[e.d.length-1]&1}function Mt(e,t,n){for(var r,o,i=new e(t[0]),s=0;++s<t.length;){if(o=new e(t[s]),!o.s){i=o;break}r=i.cmp(o),(r===n||r===0&&i.s===n)&&(i=o)}return i}function st(e,t){var n,r,o,i,s,a,c,u=0,l=0,d=0,f=e.constructor,p=f.rounding,S=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?(y=!1,c=S):c=t,a=new f(.03125);e.e>-2;)e=e.times(a),d+=5;for(r=Math.log(V(2,d))/Math.LN10*2+5|0,c+=r,n=i=s=new f(1),f.precision=c;;){if(i=h(i.times(e),c,1),n=n.times(++l),a=s.plus(R(i,n,c,1)),K(a.d).slice(0,c)===K(s.d).slice(0,c)){for(o=d;o--;)s=h(s.times(s),c,1);if(t==null)if(u<3&&ye(s.d,c-r,p,u))f.precision=c+=10,n=i=a=new f(1),l=0,u++;else return h(s,f.precision=S,p,y=!0);else return f.precision=S,s}s=a}}function oe(e,t){var n,r,o,i,s,a,c,u,l,d,f,p=1,S=10,T=e,_=T.d,A=T.constructor,O=A.rounding,E=A.precision;if(T.s<0||!_||!_[0]||!T.e&&_[0]==1&&_.length==1)return new A(_&&!_[0]?-1/0:T.s!=1?NaN:_?0:T);if(t==null?(y=!1,l=E):l=t,A.precision=l+=S,n=K(_),r=n.charAt(0),Math.abs(i=T.e)<15e14){for(;r<7&&r!=1||r==1&&n.charAt(1)>3;)T=T.times(e),n=K(T.d),r=n.charAt(0),p++;i=T.e,r>1?(T=new A("0."+n),i++):T=new A(r+"."+n.slice(1))}else return u=Fe(A,l+2,E).times(i+""),T=oe(new A(r+"."+n.slice(1)),l-S).plus(u),A.precision=E,t==null?h(T,E,O,y=!0):T;for(d=T,c=s=T=R(T.minus(1),T.plus(1),l,1),f=h(T.times(T),l,1),o=3;;){if(s=h(s.times(f),l,1),u=c.plus(R(s,new A(o),l,1)),K(u.d).slice(0,l)===K(c.d).slice(0,l))if(c=c.times(2),i!==0&&(c=c.plus(Fe(A,l+2,E).times(i+""))),c=R(c,new A(p),l,1),t==null)if(ye(c.d,l-S,O,a))A.precision=l+=S,u=s=T=R(d.minus(1),d.plus(1),l,1),f=h(T.times(T),l,1),o=a=1;else return h(c,A.precision=E,O,y=!0);else return A.precision=E,c;c=u,o+=2}}function Ot(e){return String(e.s*e.s/0)}function Oe(e,t){var n,r,o;for((n=t.indexOf("."))>-1&&(t=t.replace(".","")),(r=t.search(/e/i))>0?(n<0&&(n=r),n+=+t.slice(r+1),t=t.substring(0,r)):n<0&&(n=t.length),r=0;t.charCodeAt(r)===48;r++);for(o=t.length;t.charCodeAt(o-1)===48;--o);if(t=t.slice(r,o),t){if(o-=r,e.e=n=n-r-1,e.d=[],r=(n+1)%b,n<0&&(r+=b),r<o){for(r&&e.d.push(+t.slice(0,r)),o-=b;r<o;)e.d.push(+t.slice(r,r+=b));t=t.slice(r),r=b-t.length}else r-=o;for(;r--;)t+="0";e.d.push(+t),y&&(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 Un(e,t){var n,r,o,i,s,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),It.test(t))return Oe(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(On.test(t))n=16,t=t.toLowerCase();else if(Mn.test(t))n=2;else if(Vn.test(t))n=8;else throw Error(ie+t);for(i=t.search(/p/i),i>0?(c=+t.slice(i+1),t=t.substring(2,i)):t=t.slice(2),i=t.indexOf("."),s=i>=0,r=e.constructor,s&&(t=t.replace(".",""),a=t.length,i=a-i,o=Dt(r,new r(n),i,i*2)),u=Me(t,n,Y),l=u.length-1,i=l;u[i]===0;--i)u.pop();return i<0?new r(e.s*0):(e.e=Ue(u,l),e.d=u,y=!1,s&&(e=R(e,o,a*4)),c&&(e=e.times(Math.abs(c)<54?V(2,c):He.pow(2,c))),y=!0,e)}function Wn(e,t){var n,r=t.d.length;if(r<3)return t.isZero()?t:fe(e,2,t,t);n=1.4*Math.sqrt(r),n=n>16?16:n|0,t=t.times(1/We(5,n)),t=fe(e,2,t,t);for(var o,i=new e(5),s=new e(16),a=new e(20);n--;)o=t.times(t),t=t.times(i.plus(o.times(s.times(o).minus(a))));return t}function fe(e,t,n,r,o){var i,s,a,c,u=1,l=e.precision,d=Math.ceil(l/b);for(y=!1,c=n.times(n),a=new e(r);;){if(s=R(a.times(c),new e(t++*t++),l,1),a=o?r.plus(s):r.minus(s),r=R(s.times(c),new e(t++*t++),l,1),s=a.plus(r),s.d[d]!==void 0){for(i=d;s.d[i]===a.d[i]&&i--;);if(i==-1)break}i=a,a=r,r=s,s=i,u++}return y=!0,s.d.length=d+1,s}function We(e,t){for(var n=e;--t;)n*=e;return n}function Vt(e,t){var n,r=t.s<0,o=z(e,e.precision,1),i=o.times(.5);if(t=t.abs(),t.lte(i))return $=r?4:1,t;if(n=t.divToInt(o),n.isZero())$=r?3:2;else{if(t=t.minus(n.times(o)),t.lte(i))return $=Lt(n)?r?2:3:r?4:1,t;$=Lt(n)?r?1:4:r?3:2}return t.minus(o).abs()}function at(e,t,n,r){var o,i,s,a,c,u,l,d,f,p=e.constructor,S=n!==void 0;if(S?(G(n,1,se),r===void 0?r=p.rounding:G(r,0,8)):(n=p.precision,r=p.rounding),!e.isFinite())l=Ot(e);else{for(l=X(e),s=l.indexOf("."),S?(o=2,t==16?n=n*4-3:t==8&&(n=n*3-2)):o=t,s>=0&&(l=l.replace(".",""),f=new p(1),f.e=l.length-s,f.d=Me(X(f),10,o),f.e=f.d.length),d=Me(l,10,o),i=c=d.length;d[--c]==0;)d.pop();if(!d[0])l=S?"0p+0":"0";else{if(s<0?i--:(e=new p(e),e.d=d,e.e=i,e=R(e,f,n,r,0,o),d=e.d,i=e.e,u=Et),s=d[n],a=o/2,u=u||d[n+1]!==void 0,u=r<4?(s!==void 0||u)&&(r===0||r===(e.s<0?3:2)):s>a||s===a&&(r===4||u||r===6&&d[n-1]&1||r===(e.s<0?8:7)),d.length=n,u)for(;++d[--n]>o-1;)d[n]=0,n||(++i,d.unshift(1));for(c=d.length;!d[c-1];--c);for(s=0,l="";s<c;s++)l+=rt.charAt(d[s]);if(S){if(c>1)if(t==16||t==8){for(s=t==16?4:3,--c;c%s;c++)l+="0";for(d=Me(l,o,t),c=d.length;!d[c-1];--c);for(s=1,l="1.";s<c;s++)l+=rt.charAt(d[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(i<0?"p":"p+")+i}else if(i<0){for(;++i;)l="0"+l;l="0."+l}else if(++i>c)for(i-=c;i--;)l+="0";else i<c&&(l=l.slice(0,i)+"."+l.slice(i))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function _t(e,t){if(e.length>t)return e.length=t,!0}function Hn(e){return new this(e).abs()}function qn(e){return new this(e).acos()}function Gn(e){return new this(e).acosh()}function jn(e,t){return new this(e).plus(t)}function Yn(e){return new this(e).asin()}function zn(e){return new this(e).asinh()}function Xn(e){return new this(e).atan()}function Zn(e){return new this(e).atanh()}function Qn(e,t){e=new this(e),t=new this(t);var n,r=this.precision,o=this.rounding,i=r+4;return!e.s||!t.s?n=new this(NaN):!e.d&&!t.d?(n=z(this,i,1).times(t.s>0?.25:.75),n.s=e.s):!t.d||e.isZero()?(n=t.s<0?z(this,r,o):new this(0),n.s=e.s):!e.d||t.isZero()?(n=z(this,i,1).times(.5),n.s=e.s):t.s<0?(this.precision=i,this.rounding=1,n=this.atan(R(e,t,i,1)),t=z(this,i,1),this.precision=r,this.rounding=o,n=e.s<0?n.minus(t):n.plus(t)):n=this.atan(R(e,t,i,1)),n}function Jn(e){return new this(e).cbrt()}function $n(e){return h(e=new this(e),e.e+1,2)}function er(e,t,n){return new this(e).clamp(t,n)}function tr(e){if(!e||typeof e!="object")throw Error(Ke+"Object expected");var t,n,r,o=e.defaults===!0,i=["precision",1,se,"rounding",0,8,"toExpNeg",-de,0,"toExpPos",0,de,"maxE",0,de,"minE",-de,0,"modulo",0,9];for(t=0;t<i.length;t+=3)if(n=i[t],o&&(this[n]=ot[n]),(r=e[n])!==void 0)if(W(r)===r&&r>=i[t+1]&&r<=i[t+2])this[n]=r;else throw Error(ie+n+": "+r);if(n="crypto",o&&(this[n]=ot[n]),(r=e[n])!==void 0)if(r===!0||r===!1||r===0||r===1)if(r)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[n]=!0;else throw Error(Rt);else this[n]=!1;else throw Error(ie+n+": "+r);return this}function nr(e){return new this(e).cos()}function rr(e){return new this(e).cosh()}function vt(e){var t,n,r;function o(i){var s,a,c,u=this;if(!(u instanceof o))return new o(i);if(u.constructor=o,Nt(i)){u.s=i.s,y?!i.d||i.e>o.maxE?(u.e=NaN,u.d=null):i.e<o.minE?(u.e=0,u.d=[0]):(u.e=i.e,u.d=i.d.slice()):(u.e=i.e,u.d=i.d?i.d.slice():i.d);return}if(c=typeof i,c==="number"){if(i===0){u.s=1/i<0?-1:1,u.e=0,u.d=[0];return}if(i<0?(i=-i,u.s=-1):u.s=1,i===~~i&&i<1e7){for(s=0,a=i;a>=10;a/=10)s++;y?s>o.maxE?(u.e=NaN,u.d=null):s<o.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[i]):(u.e=s,u.d=[i]);return}if(i*0!==0){i||(u.s=NaN),u.e=NaN,u.d=null;return}return Oe(u,i.toString())}if(c==="string")return(a=i.charCodeAt(0))===45?(i=i.slice(1),u.s=-1):(a===43&&(i=i.slice(1)),u.s=1),It.test(i)?Oe(u,i):Un(u,i);if(c==="bigint")return i<0?(i=-i,u.s=-1):u.s=1,Oe(u,i.toString());throw Error(ie+i)}if(o.prototype=m,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=tr,o.clone=vt,o.isDecimal=Nt,o.abs=Hn,o.acos=qn,o.acosh=Gn,o.add=jn,o.asin=Yn,o.asinh=zn,o.atan=Xn,o.atanh=Zn,o.atan2=Qn,o.cbrt=Jn,o.ceil=$n,o.clamp=er,o.cos=nr,o.cosh=rr,o.div=or,o.exp=ir,o.floor=sr,o.hypot=ar,o.ln=ur,o.log=cr,o.log10=dr,o.log2=lr,o.max=fr,o.min=mr,o.mod=pr,o.mul=gr,o.pow=hr,o.random=wr,o.round=br,o.sign=Tr,o.sin=yr,o.sinh=Sr,o.sqrt=Pr,o.sub=xr,o.sum=Ar,o.tan=Lr,o.tanh=_r,o.trunc=Nr,e===void 0&&(e={}),e&&e.defaults!==!0)for(r=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<r.length;)e.hasOwnProperty(n=r[t++])||(e[n]=this[n]);return o.config(e),o}function or(e,t){return new this(e).div(t)}function ir(e){return new this(e).exp()}function sr(e){return h(e=new this(e),e.e+1,3)}function ar(){var e,t,n=new this(0);for(y=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)n.d&&(n=n.plus(t.times(t)));else{if(t.s)return y=!0,new this(1/0);n=t}return y=!0,n.sqrt()}function Nt(e){return e instanceof He||e&&e.toStringTag===kt||!1}function ur(e){return new this(e).ln()}function cr(e,t){return new this(e).log(t)}function lr(e){return new this(e).log(2)}function dr(e){return new this(e).log(10)}function fr(){return Mt(this,arguments,-1)}function mr(){return Mt(this,arguments,1)}function pr(e,t){return new this(e).mod(t)}function gr(e,t){return new this(e).mul(t)}function hr(e,t){return new this(e).pow(t)}function wr(e){var t,n,r,o,i=0,s=new this(1),a=[];if(e===void 0?e=this.precision:G(e,1,se),r=Math.ceil(e/b),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(r));i<r;)o=t[i],o>=429e7?t[i]=crypto.getRandomValues(new Uint32Array(1))[0]:a[i++]=o%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(r*=4);i<r;)o=t[i]+(t[i+1]<<8)+(t[i+2]<<16)+((t[i+3]&127)<<24),o>=214e7?crypto.randomBytes(4).copy(t,i):(a.push(o%1e7),i+=4);i=r/4}else throw Error(Rt);else for(;i<r;)a[i++]=Math.random()*1e7|0;for(r=a[--i],e%=b,r&&e&&(o=V(10,b-e),a[i]=(r/o|0)*o);a[i]===0;i--)a.pop();if(i<0)n=0,a=[0];else{for(n=-1;a[0]===0;n-=b)a.shift();for(r=1,o=a[0];o>=10;o/=10)r++;r<b&&(n-=b-r)}return s.e=n,s.d=a,s}function br(e){return h(e=new this(e),e.e+1,this.rounding)}function Tr(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function yr(e){return new this(e).sin()}function Sr(e){return new this(e).sinh()}function Pr(e){return new this(e).sqrt()}function xr(e,t){return new this(e).sub(t)}function Ar(){var e=0,t=arguments,n=new this(t[e]);for(y=!1;n.s&&++e<t.length;)n=n.plus(t[e]);return y=!0,h(n,this.precision,this.rounding)}function Lr(e){return new this(e).tan()}function _r(e){return new this(e).tanh()}function Nr(e){return h(e=new this(e),e.e+1,1)}m[Symbol.for("nodejs.util.inspect.custom")]=m.toString;m[Symbol.toStringTag]="Decimal";var He=m.constructor=vt(ot);Ve=new He(Ve);ve=new He(ve);var qt=q(require("big.js")),Ae=q(require("bn.js"));var Ft=q(require("toformat")),Er=Ft.default,Se=Er;var Pe=q(require("big.js")),Ut=q(require("bn.js")),Wt=q(require("decimal.js-light"));var me=q(require("bn.js"));var Kt=9007199254740991;function D(e){let t=F("CobaltX_parseBigNumberish");if(e instanceof me.default)return e;if(typeof e=="string"){if(e.match(/^-?[0-9]+$/))return new me.default(e);t.logWithError(`invalid BigNumberish string: ${e}`)}return typeof e=="number"?(e%1&&t.logWithError(`BigNumberish number underflow: ${e}`),(e>=Kt||e<=-Kt)&&t.logWithError(`BigNumberish number overflow: ${e}`),new me.default(String(e))):typeof e=="bigint"?new me.default(e.toString()):(t.error(`invalid BigNumberish value: ${e}`),new me.default(0))}var qe=F("module/fraction"),ut=Se(Pe.default),xe=Se(Wt.default),Rr={[0]:xe.ROUND_DOWN,[1]:xe.ROUND_HALF_UP,[2]:xe.ROUND_UP},kr={[0]:Pe.default.roundDown,[1]:Pe.default.roundHalfUp,[2]:Pe.default.roundUp},N=class{constructor(t,n=new Ut.default(1)){this.numerator=D(t),this.denominator=D(n)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new N(this.denominator,this.numerator)}add(t){let n=t instanceof N?t:new N(D(t));return this.denominator.eq(n.denominator)?new N(this.numerator.add(n.numerator),this.denominator):new N(this.numerator.mul(n.denominator).add(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}sub(t){let n=t instanceof N?t:new N(D(t));return this.denominator.eq(n.denominator)?new N(this.numerator.sub(n.numerator),this.denominator):new N(this.numerator.mul(n.denominator).sub(n.numerator.mul(this.denominator)),this.denominator.mul(n.denominator))}mul(t){let n=t instanceof N?t:new N(D(t));return new N(this.numerator.mul(n.numerator),this.denominator.mul(n.denominator))}div(t){let n=t instanceof N?t:new N(D(t));return new N(this.numerator.mul(n.denominator),this.denominator.mul(n.numerator))}toSignificant(t,n={groupSeparator:""},r=1){Number.isInteger(t)||qe.logWithError(`${t} is not an integer.`),t<=0&&qe.logWithError(`${t} is not positive.`),xe.set({precision:t+1,rounding:Rr[r]});let o=new xe(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return o.toFormat(o.decimalPlaces(),n)}toFixed(t,n={groupSeparator:""},r=1){return Number.isInteger(t)||qe.logWithError(`${t} is not an integer.`),t<0&&qe.logWithError(`${t} is negative.`),ut.DP=t,ut.RM=kr[r]||1,new ut(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,n)}isZero(){return this.numerator.isZero()}};var Ir=F("CobaltX_amount"),Ht=Se(qt.default);function Cr(e,t){let n="0",r="0";if(e.includes(".")){let o=e.split(".");o.length===2?([n,r]=o,r=r.padEnd(t,"0")):Ir.logWithError(`invalid number string, num: ${e}`)}else n=e;return[n,r.slice(0,t)||r]}var ee=class extends N{constructor(n,r,o=!0,i){let s=new Ae.default(0),a=ct.pow(new Ae.default(n.decimals));if(o)s=D(r);else{let c=new Ae.default(0),u=new Ae.default(0);if(typeof r=="string"||typeof r=="number"||typeof r=="bigint"){let[l,d]=Cr(r.toString(),n.decimals);c=D(l),u=D(d)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=F(i||"TokenAmount"),this.token=n}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(n){return this.token.equals(n.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(n.raw)}lt(n){return this.token.equals(n.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(n.raw)}add(n){return this.token.equals(n.token)||this.logger.logWithError("add token not equals"),new ee(this.token,this.raw.add(n.raw))}subtract(n){return this.token.equals(n.token)||this.logger.logWithError("sub token not equals"),new ee(this.token,this.raw.sub(n.raw))}toSignificant(n=this.token.decimals,r,o=0){return super.toSignificant(n,r,o)}toFixed(n=this.token.decimals,r,o=0){return n>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(n,r,o)}toExact(n={groupSeparator:""}){return Ht.DP=this.token.decimals,new Ht(this.numerator.toString()).div(this.denominator.toString()).toFormat(n)}};var Gt=require("@solana/spl-token"),Mr=require("@solana/web3.js");var Z=require("@solana/web3.js");var Dr={["sooneth"]:{NATIVE_TOKEN_SYMBOL:"ETH",SWAP_HOST:"https://trade-api.cobaltx.io",BASE_HOST:"https://api.cobaltx.io",OWNER_BASE_HOST:"https://api.cobaltx.io",SERVICE_BASE_HOST:"https://api.cobaltx.io",MONITOR_BASE_HOST:"https://api.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/tokens/main/logo/So11111111111111111111111111111111111111112.png",LOOKUP_TABLE_CACHE:"6fa5xTGwoYJPMLMXaQ4tQFKMoYvXuvsJFLigMJ9a5QeB",CLMM_PROGRAMM_ID:"2TnjBuwqyBB9to5jURagDT7jLmBPefGRiKL2yh1zPZ4V",BONK_MINT_ADDRESS:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",SOL_MINT_ADDRESS:"ERFzpDteGNo8LTDKW1WwVGrkRMmA2y9WZHXNHxMA6BSV",USDC_MINT_ADDRESS:"ExYxyorY2x3h8gLcuypnHFQV3F36rmMkQVn7HHV8mUy9",USDT_MINT_ADDRESS:"742wcXVzkhNuEePAot7L3GvPseh93pvYFPgyHLX8mUy9",FULL_TOKEN_NAME:"Wrapped Ethereum",ETH_MINT_ADDRESS:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",WRAPPED_TOKEN_SYMBOL:"WETH",INPUT_MINT_ADDRESS:Z.PublicKey.default.toString(),OUTPUT_MINT_ADDRESS:"742wcXVzkhNuEePAot7L3GvPseh93pvYFPgyHLX8mUy9",POPULAR_TOKENS:{SOL:Z.PublicKey.default.toString(),ETH:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",USDC:"ExYxyorY2x3h8gLcuypnHFQV3F36rmMkQVn7HHV8KjtA",USDT:"742wcXVzkhNuEePAot7L3GvPseh93pvYFPgyHLX8mUy9"},WSOL_DECIMALS:9},["svmbnb"]:{NATIVE_TOKEN_SYMBOL:"BNB",SWAP_HOST:"https://trade-api.svmbnb.cobaltx.io",BASE_HOST:"https://api.svmbnb.cobaltx.io",OWNER_BASE_HOST:"https://api.svmbnb.cobaltx.io",SERVICE_BASE_HOST:"https://api.svmbnb.cobaltx.io",MONITOR_BASE_HOST:"https://api.svmbnb.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.svmbnb.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.svmbnb.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbnb-tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbnb-tokens/main/logo/So11111111111111111111111111111111111111112.svg",LOOKUP_TABLE_CACHE:"GSR5XQGWhpzV9TTduBJR6qPNjYsepMQSGkpaqfrbrW9w",CLMM_PROGRAMM_ID:"6f1b3xyVZbnWMHXBjgW1KPwxmPAgXcRdrvKNn4Nmf1Cn",ETH_MINT_ADDRESS:"H3xpFH1yN5E1zFdAoBrC9Y7m7RfJUeQNLvkHi8kNf9Qu",USDC_MINT_ADDRESS:"5odzAHDpDETYhupMkc6kjiYen3K2nrf8oPmvqmsoNW4L",USDT_MINT_ADDRESS:"s8cRDxnp3VxjB6khRnGDdxv6QbCUPyY9Vn1bgSQQsnG",SOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",FULL_TOKEN_NAME:"Wrapped BNB",WRAPPED_TOKEN_SYMBOL:"WBNB",INPUT_MINT_ADDRESS:Z.PublicKey.default.toBase58(),OUTPUT_MINT_ADDRESS:"ABoT7umUXnx8RtJTeRqKB6myebVjP2wdJGQuV23jVVH3",POPULAR_TOKENS:{SOL:Z.PublicKey.default.toString(),ETH:"H3xpFH1yN5E1zFdAoBrC9Y7m7RfJUeQNLvkHi8kNf9Qu",USDC:"5odzAHDpDETYhupMkc6kjiYen3K2nrf8oPmvqmsoNW4L",USDT:"s8cRDxnp3VxjB6khRnGDdxv6QbCUPyY9Vn1bgSQQsnG"},WSOL_DECIMALS:9},["svmbnb_testnet"]:{NATIVE_TOKEN_SYMBOL:"BNB",SWAP_HOST:"https://trade-api.svmbnb.cobaltx.io",BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",OWNER_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",SERVICE_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",MONITOR_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.testnet.svmbnb.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbnb-testnet-tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbnb-testnet-tokens/main/logo/So11111111111111111111111111111111111111112.svg",LOOKUP_TABLE_CACHE:"D79gSiTNV9pyLPJyscW5yZYwdPVDrtKsamL3ZfQi6JiM",CLMM_PROGRAMM_ID:"FgycD57kcCZsjpoTAi2u67GTPxm59bPEhycL2Lw1icm1",ETH_MINT_ADDRESS:"5aLr3sV4UNVcMB6CiA3PZTWbgVBRNyMdEp1s5LNfhR95",USDC_MINT_ADDRESS:"jrhUNRxEDpFmGV3sqaWyveS7bVtRQgtHsfBTCdjfMBw",USDT_MINT_ADDRESS:"Ex86C4gmdjvPRNrfyvsyejbjkP6RstNaBC5g3itZw2iv",FULL_TOKEN_NAME:"Wrapped BNB",WRAPPED_TOKEN_SYMBOL:"WBNB",INPUT_MINT_ADDRESS:"bnb",OUTPUT_MINT_ADDRESS:"jrhUNRxEDpFmGV3sqaWyveS7bVtRQgtHsfBTCdjfMBw",POPULAR_TOKENS:{SOL:Z.PublicKey.default.toString(),ETH:"5aLr3sV4UNVcMB6CiA3PZTWbgVBRNyMdEp1s5LNfhR95",USDC:"jrhUNRxEDpFmGV3sqaWyveS7bVtRQgtHsfBTCdjfMBw",USDT:"Ex86C4gmdjvPRNrfyvsyejbjkP6RstNaBC5g3itZw2iv"},WSOL_DECIMALS:9},["svmbase_testnet"]:{NATIVE_TOKEN_SYMBOL:"ETH",SWAP_HOST:"https://trade-api.testnet.svmbase.cobaltx.io",BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",OWNER_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",SERVICE_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",MONITOR_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.testnet.svmbase.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbase-testnet-tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/svmbase-testnet-tokens/main/logo/So11111111111111111111111111111111111111112.png",LOOKUP_TABLE_CACHE:"AyPMvNmUUY2jwZ75NxhkLYPraQGNk5DssVfP4TnMcPJF",CLMM_PROGRAMM_ID:"DnZnBqJKiGSYHUHYvkXAbQmkMbwrjfgo4orR7jWyMsik",ETH_MINT_ADDRESS:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",USDC_MINT_ADDRESS:"63tPXWPnYeZ9hA3dJsAY5RcQ8YbwEz8uZ5nKu3uFD1aK",USDT_MINT_ADDRESS:"4fyX7hSmPetQC2wRS3YVAhWeFzif7WStarKwTvCXrBtD",FULL_TOKEN_NAME:"Wrapped Ethereum",WRAPPED_TOKEN_SYMBOL:"WETH",INPUT_MINT_ADDRESS:Z.PublicKey.default.toString(),OUTPUT_MINT_ADDRESS:"63tPXWPnYeZ9hA3dJsAY5RcQ8YbwEz8uZ5nKu3uFD1aK",POPULAR_TOKENS:{SOL:Z.PublicKey.default.toString(),ETH:"So11111111111111111111111111111111111111112",USDC:"63tPXWPnYeZ9hA3dJsAY5RcQ8YbwEz8uZ5nKu3uFD1aK",USDT:"4fyX7hSmPetQC2wRS3YVAhWeFzif7WStarKwTvCXrBtD"},WSOL_DECIMALS:9},["soonbase_mainnet"]:{NATIVE_TOKEN_SYMBOL:"ETH",SWAP_HOST:"https://trade-api.soonbase.cobaltx.io",BASE_HOST:"https://api.soonbase.cobaltx.io",OWNER_BASE_HOST:"https://api.soonbase.cobaltx.io",SERVICE_BASE_HOST:"https://api.soonbase.cobaltx.io",MONITOR_BASE_HOST:"https://api.soonbase.cobaltx.io",SERVICE_1_BASE_HOST:"https://api.soonbase.cobaltx.io",ANALYTICS_BASE_HOST:"https://api.soonbase.cobaltx.io",GITHUB_TOKEN_LIST_URL:"https://raw.githubusercontent.com/cobaltx-io/soonbase-tokens/main/tokens.json",WSOL_MINT_ADDRESS:"So11111111111111111111111111111111111111112",GITHUB_LOGO_URL:"https://raw.githubusercontent.com/cobaltx-io/soonbase-tokens/main/logo/So11111111111111111111111111111111111111112.png",LOOKUP_TABLE_CACHE:"FGRusuLycV6nhSPQc9VX55YjT6DCzJFc59mvTTarSTjK",CLMM_PROGRAMM_ID:"6f1b3xyVZbnWMHXBjgW1KPwxmPAgXcRdrvKNn4Nmf1Cn",ETH_MINT_ADDRESS:"71kRXzJMvSeArtXYNEWa8KAjpRJosdMQ7Dpgy5Jt5zfd",USDC_MINT_ADDRESS:"BoYN2f2gLQS4jpvMSV9dAZwfzKJiKGk4NPck5BjXfujo",USDT_MINT_ADDRESS:"J87bysZjwfS3n6KR21cwbdPZVJWNSFcXpWF5kiChAwQH",FULL_TOKEN_NAME:"Wrapped Ethereum",WRAPPED_TOKEN_SYMBOL:"WETH",INPUT_MINT_ADDRESS:Z.PublicKey.default.toString(),OUTPUT_MINT_ADDRESS:"BoYN2f2gLQS4jpvMSV9dAZwfzKJiKGk4NPck5BjXfujo",POPULAR_TOKENS:{SOL:Z.PublicKey.default.toString(),ETH:"FkvCG5DcuYCQ1BnPH4ZzTkCdk3VzutgyDAFBec4qAjhh",USDC:"BoYN2f2gLQS4jpvMSV9dAZwfzKJiKGk4NPck5BjXfujo",USDT:"J87bysZjwfS3n6KR21cwbdPZVJWNSFcXpWF5kiChAwQH"},WSOL_DECIMALS:9}},pe=e=>Dr[e];function ue(e){let t=pe(e);return{chainId:101,address:t.WSOL_MINT_ADDRESS,programId:Gt.TOKEN_PROGRAM_ID.toBase58(),decimals:9,symbol:t.WRAPPED_TOKEN_SYMBOL||"",name:t.FULL_TOKEN_NAME,logoURI:t.GITHUB_LOGO_URL,tags:[],priority:2,type:"cobaltx",extensions:{coingeckoId:"solana"}}}var Ge=require("@solana/web3.js");var jt=require("@solana/spl-token"),B=require("@solana/web3.js");function lt({pubkey:e,isSigner:t=!1,isWritable:n=!0}){return{pubkey:e,isWritable:n,isSigner:t}}var jo=[lt({pubkey:jt.TOKEN_PROGRAM_ID,isWritable:!1}),lt({pubkey:B.SystemProgram.programId,isWritable:!1}),lt({pubkey:B.SYSVAR_RENT_PUBKEY,isWritable:!1})];function Yt({publicKey:e,transformSol:t,network:n}){let r=dt(e.toString());if(t&&n){let{WSOLMint:o}=At(n);if(r instanceof B.PublicKey)return t&&r.equals(Le)?o:r;if(t&&r.toString()===Le.toBase58())return o}else if(r instanceof B.PublicKey)return r;if(typeof r=="string"){if(r===B.PublicKey.default.toBase58())return B.PublicKey.default;try{return new B.PublicKey(r)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function dt(e){try{return new B.PublicKey(e)}catch{return e}}var Yo=new B.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),zo=new B.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Xo=new B.PublicKey("SysvarRent111111111111111111111111111111111"),Zo=new B.PublicKey("SysvarC1ock11111111111111111111111111111111"),Qo=new B.PublicKey("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Jo=new B.PublicKey("Sysvar1nstructions1111111111111111111111111"),$o=B.SystemProgram.programId,Le=B.PublicKey.default;function At(e){let t=pe(e);return{USDCMint:new B.PublicKey(t.USDC_MINT_ADDRESS),USDTMint:new B.PublicKey(t.USDT_MINT_ADDRESS),WSOLMint:new B.PublicKey(t.WSOL_MINT_ADDRESS),ETHMint:new B.PublicKey(t.ETH_MINT_ADDRESS),BONK_Mint:t.BONK_MINT_ADDRESS?new B.PublicKey(t.BONK_MINT_ADDRESS):B.PublicKey.default,SOL_Mint:t.SOL_MINT_ADDRESS?new B.PublicKey(t.SOL_MINT_ADDRESS):B.PublicKey.default,INPUT_MINT:new B.PublicKey(t.INPUT_MINT_ADDRESS),OUTPUT_MINT:new B.PublicKey(t.OUTPUT_MINT_ADDRESS)}}var ae=class{constructor({mint:t,decimals:n,symbol:r,name:o,skipMint:i=!1,isToken2022:s=!1,network:a}){if(t===Le.toBase58()||t instanceof Ge.PublicKey&&Le.equals(t)&&a){this.decimals=ue(a).decimals,this.symbol=ue(a).symbol,this.name=ue(a).name,this.mint=new Ge.PublicKey(ue(a).address),this.isToken2022=!1;return}this.decimals=n,this.symbol=r||t.toString().substring(0,6),this.name=o||t.toString().substring(0,6),this.mint=i?Ge.PublicKey.default:Yt({publicKey:t}),this.isToken2022=s}static getWSol(t){return new ae({...ue(t),mint:ue(t).address})}equals(t){return this===t?!0:this.mint.equals(t.mint)}};var Xt=q(require("bn.js"));var zt=new N(new Xt.default(100)),ge=class extends N{toSignificant(t=5,n,r){return this.mul(zt).toSignificant(t,n,r)}toFixed(t=2,n,r){return this.mul(zt).toFixed(t,n,r)}};var Or=F("CobaltX_price"),te=class extends N{constructor(n){let{baseToken:r,quoteToken:o,numerator:i,denominator:s}=n;super(i,s);this.baseToken=r,this.quoteToken=o,this.scalar=new N(ft(r.decimals),ft(o.decimals))}get raw(){return new N(this.numerator,this.denominator)}get adjusted(){return super.mul(this.scalar)}invert(){return new te({baseToken:this.quoteToken,quoteToken:this.baseToken,denominator:this.numera