UNPKG

@cobaltx/sdk-v2

Version:

An SDK for building applications on top of CobaltX.

1 lines 412 kB
import fu from"axios";import{MINT_SIZE as ml,TOKEN_PROGRAM_ID as dl,getTransferFeeConfig as pl,unpackMint as fl}from"@solana/spl-token";import{PublicKey as Sa}from"@solana/web3.js";import{get as Cr,set as Ia}from"lodash";var ll=(i=>(i[i.Error=0]="Error",i[i.Warning=1]="Warning",i[i.Info=2]="Info",i[i.Debug=3]="Debug",i))(ll||{}),Lr=class{constructor(e){this.logLevel=e.logLevel!==void 0?e.logLevel:0,this.name=e.name}set level(e){this.logLevel=e}get time(){return Date.now().toString()}get moduleName(){return this.name}isLogLevel(e){return e<=this.logLevel}error(...e){return this.isLogLevel(0)?(console.error(this.time,this.name,"sdk logger error",...e),this):this}logWithError(...e){let t=e.map(n=>typeof n=="object"?JSON.stringify(n):n).join(", ");throw new Error(t)}warning(...e){return this.isLogLevel(1)?(console.warn(this.time,this.name,"sdk logger warning",...e),this):this}info(...e){return this.isLogLevel(2)?(console.info(this.time,this.name,"sdk logger info",...e),this):this}debug(...e){return this.isLogLevel(3)?(console.debug(this.time,this.name,"sdk logger debug",...e),this):this}},Or={},Ba={};function ce(o){let e=Cr(Or,o);if(!e){let t=Cr(Ba,o);e=new Lr({name:o,logLevel:t}),Ia(Or,o,e)}return e}function $f(o,e){Ia(Ba,o,e);let t=Cr(Or,o);t&&(t.level=e)}var Rr=ce("CobaltX_accountInfo_util");async function Mt(o,e,t){let{batchRequest:n,commitment:i="confirmed",chunkCount:r=100}={batchRequest:!1,...t},s=Nr(e,r),a=new Array(s.length).fill([]);if(n){let c=s.map(d=>{let m=o._buildArgs([d.map(p=>p.toBase58())],i,"base64");return{methodName:"getMultipleAccounts",args:m}}),u=Nr(c,10);a=(await(await Promise.all(u.map(async d=>await o._rpcBatchRequest(d)))).flat()).map(d=>(d.error&&Rr.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${d.error.message}`),d.result.value.map(m=>{if(m){let{data:p,executable:b,lamports:f,owner:g,rentEpoch:y}=m;return p.length!==2&&p[1]!=="base64"&&Rr.logWithError("info must be base64 encoded, RPC_ERROR"),{data:Buffer.from(p[0],"base64"),executable:b,lamports:f,owner:new Sa(g),rentEpoch:y}}return null})))}else try{a=await Promise.all(s.map(c=>o.getMultipleAccountsInfo(c,i)))}catch(c){c instanceof Error&&Rr.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${c.message}`)}return a.flat()}async function Xe(o,e,t){let n=await Mt(o,e.map(i=>i.pubkey),t);return e.map((i,r)=>({...i,accountInfo:n[r]}))}var bl=(n=>(n[n.Uninitialized=0]="Uninitialized",n[n.Mint=1]="Mint",n[n.Account=2]="Account",n))(bl||{}),ab=1;async function Yn({connection:o,mints:e,network:t,config:n}){var s,a,c;if(e.length===0)return{};let i=await Xe(o,e.map(u=>({pubkey:st(u,t)})),n),r={};for(let u of i){if(!u.accountInfo||u.accountInfo.data.length<ml){console.log("invalid mint account",u.pubkey.toBase58());continue}let l=fl(u.pubkey,u.accountInfo,(s=u.accountInfo)==null?void 0:s.owner);r[u.pubkey.toString()]={...l,programId:((a=u.accountInfo)==null?void 0:a.owner)||dl,feeConfig:(c=pl(l))!=null?c:void 0}}return r[Sa.default.toBase58()]=r[$(t).WSOLMint.toBase58()],r}import Ue from"bn.js";var jn=9e15,bn=1e9,Mr="0123456789abcdef",hi="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Ti="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",_r={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-jn,maxE:jn,crypto:!1},La,Zt,ie=!0,Bi="[DecimalError] ",fn=Bi+"Invalid argument: ",Oa=Bi+"Precision limit exceeded",Ra=Bi+"crypto unavailable",Na="[object Decimal]",at=Math.floor,Ye=Math.pow,yl=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,gl=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,wl=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,Ma=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,_t=1e7,te=7,Al=9007199254740991,kl=hi.length-1,Er=Ti.length-1,D={toStringTag:Na};D.absoluteValue=D.abs=function(){var o=new this.constructor(this);return o.s<0&&(o.s=1),Z(o)};D.ceil=function(){return Z(new this.constructor(this),this.e+1,2)};D.clampedTo=D.clamp=function(o,e){var t,n=this,i=n.constructor;if(o=new i(o),e=new i(e),!o.s||!e.s)return new i(NaN);if(o.gt(e))throw Error(fn+e);return t=n.cmp(o),t<0?o:n.cmp(e)>0?e:new i(n)};D.comparedTo=D.cmp=function(o){var e,t,n,i,r=this,s=r.d,a=(o=new r.constructor(o)).d,c=r.s,u=o.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(r.e!==o.e)return r.e>o.e^c<0?1:-1;for(n=s.length,i=a.length,e=0,t=n<i?n:i;e<t;++e)if(s[e]!==a[e])return s[e]>a[e]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};D.cosine=D.cos=function(){var o,e,t=this,n=t.constructor;return t.d?t.d[0]?(o=n.precision,e=n.rounding,n.precision=o+Math.max(t.e,t.sd())+te,n.rounding=1,t=Pl(n,Da(n,t)),n.precision=o,n.rounding=e,Z(Zt==2||Zt==3?t.neg():t,o,e,!0)):new n(1):new n(NaN)};D.cubeRoot=D.cbrt=function(){var o,e,t,n,i,r,s,a,c,u,l=this,d=l.constructor;if(!l.isFinite()||l.isZero())return new d(l);for(ie=!1,r=l.s*Ye(l.s*l,1/3),!r||Math.abs(r)==1/0?(t=nt(l.d),o=l.e,(r=(o-t.length+1)%3)&&(t+=r==1||r==-2?"0":"00"),r=Ye(t,1/3),o=at((o+1)/3)-(o%3==(o<0?-1:2)),r==1/0?t="5e"+o:(t=r.toExponential(),t=t.slice(0,t.indexOf("e")+1)+o),n=new d(t),n.s=l.s):n=new d(r.toString()),s=(o=d.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=he(u.plus(l).times(a),u.plus(c),s+2,1),nt(a.d).slice(0,s)===(t=nt(n.d)).slice(0,s))if(t=t.slice(s-3,s+1),t=="9999"||!i&&t=="4999"){if(!i&&(Z(a,o+1,0),a.times(a).times(a).eq(l))){n=a;break}s+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(Z(n,o+1,1),e=!n.times(n).times(n).eq(l));break}return ie=!0,Z(n,o,d.rounding,e)};D.decimalPlaces=D.dp=function(){var o,e=this.d,t=NaN;if(e){if(o=e.length-1,t=(o-at(this.e/te))*te,o=e[o],o)for(;o%10==0;o/=10)t--;t<0&&(t=0)}return t};D.dividedBy=D.div=function(o){return he(this,new this.constructor(o))};D.dividedToIntegerBy=D.divToInt=function(o){var e=this,t=e.constructor;return Z(he(e,new t(o),0,1,1),t.precision,t.rounding)};D.equals=D.eq=function(o){return this.cmp(o)===0};D.floor=function(){return Z(new this.constructor(this),this.e+1,3)};D.greaterThan=D.gt=function(o){return this.cmp(o)>0};D.greaterThanOrEqualTo=D.gte=function(o){var e=this.cmp(o);return e==1||e===0};D.hyperbolicCosine=D.cosh=function(){var o,e,t,n,i,r=this,s=r.constructor,a=new s(1);if(!r.isFinite())return new s(r.s?1/0:NaN);if(r.isZero())return a;t=s.precision,n=s.rounding,s.precision=t+Math.max(r.e,r.sd())+4,s.rounding=1,i=r.d.length,i<32?(o=Math.ceil(i/3),e=(1/xi(4,o)).toString()):(o=16,e="2.3283064365386962890625e-10"),r=Zn(s,1,r.times(e),new s(1),!0);for(var c,u=o,l=new s(8);u--;)c=r.times(r),r=a.minus(c.times(l.minus(c.times(l))));return Z(r,s.precision=t,s.rounding=n,!0)};D.hyperbolicSine=D.sinh=function(){var o,e,t,n,i=this,r=i.constructor;if(!i.isFinite()||i.isZero())return new r(i);if(e=r.precision,t=r.rounding,r.precision=e+Math.max(i.e,i.sd())+4,r.rounding=1,n=i.d.length,n<3)i=Zn(r,2,i,i,!0);else{o=1.4*Math.sqrt(n),o=o>16?16:o|0,i=i.times(1/xi(5,o)),i=Zn(r,2,i,i,!0);for(var s,a=new r(5),c=new r(16),u=new r(20);o--;)s=i.times(i),i=i.times(a.plus(s.times(c.times(s).plus(u))))}return r.precision=e,r.rounding=t,Z(i,e,t,!0)};D.hyperbolicTangent=D.tanh=function(){var o,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(o=n.precision,e=n.rounding,n.precision=o+7,n.rounding=1,he(t.sinh(),t.cosh(),n.precision=o,n.rounding=e)):new n(t.s)};D.inverseCosine=D.acos=function(){var o=this,e=o.constructor,t=o.abs().cmp(1),n=e.precision,i=e.rounding;return t!==-1?t===0?o.isNeg()?Gt(e,n,i):new e(0):new e(NaN):o.isZero()?Gt(e,n+4,i).times(.5):(e.precision=n+6,e.rounding=1,o=new e(1).minus(o).div(o.plus(1)).sqrt().atan(),e.precision=n,e.rounding=i,o.times(2))};D.inverseHyperbolicCosine=D.acosh=function(){var o,e,t=this,n=t.constructor;return t.lte(1)?new n(t.eq(1)?0:NaN):t.isFinite()?(o=n.precision,e=n.rounding,n.precision=o+Math.max(Math.abs(t.e),t.sd())+4,n.rounding=1,ie=!1,t=t.times(t).minus(1).sqrt().plus(t),ie=!0,n.precision=o,n.rounding=e,t.ln()):new n(t)};D.inverseHyperbolicSine=D.asinh=function(){var o,e,t=this,n=t.constructor;return!t.isFinite()||t.isZero()?new n(t):(o=n.precision,e=n.rounding,n.precision=o+2*Math.max(Math.abs(t.e),t.sd())+6,n.rounding=1,ie=!1,t=t.times(t).plus(1).sqrt().plus(t),ie=!0,n.precision=o,n.rounding=e,t.ln())};D.inverseHyperbolicTangent=D.atanh=function(){var o,e,t,n,i=this,r=i.constructor;return i.isFinite()?i.e>=0?new r(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(o=r.precision,e=r.rounding,n=i.sd(),Math.max(n,o)<2*-i.e-1?Z(new r(i),o,e,!0):(r.precision=t=n-i.e,i=he(i.plus(1),new r(1).minus(i),t+o,1),r.precision=o+4,r.rounding=1,i=i.ln(),r.precision=o,r.rounding=e,i.times(.5))):new r(NaN)};D.inverseSine=D.asin=function(){var o,e,t,n,i=this,r=i.constructor;return i.isZero()?new r(i):(e=i.abs().cmp(1),t=r.precision,n=r.rounding,e!==-1?e===0?(o=Gt(r,t+4,n).times(.5),o.s=i.s,o):new r(NaN):(r.precision=t+6,r.rounding=1,i=i.div(new r(1).minus(i.times(i)).sqrt().plus(1)).atan(),r.precision=t,r.rounding=n,i.times(2)))};D.inverseTangent=D.atan=function(){var o,e,t,n,i,r,s,a,c,u=this,l=u.constructor,d=l.precision,m=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&d+4<=Er)return s=Gt(l,d+4,m).times(.25),s.s=u.s,s}else{if(!u.s)return new l(NaN);if(d+4<=Er)return s=Gt(l,d+4,m).times(.5),s.s=u.s,s}for(l.precision=a=d+10,l.rounding=1,t=Math.min(28,a/te+2|0),o=t;o;--o)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(ie=!1,e=Math.ceil(a/te),n=1,c=u.times(u),s=new l(u),i=u;o!==-1;)if(i=i.times(c),r=s.minus(i.div(n+=2)),i=i.times(c),s=r.plus(i.div(n+=2)),s.d[e]!==void 0)for(o=e;s.d[o]===r.d[o]&&o--;);return t&&(s=s.times(2<<t-1)),ie=!0,Z(s,l.precision=d,l.rounding=m,!0)};D.isFinite=function(){return!!this.d};D.isInteger=D.isInt=function(){return!!this.d&&at(this.e/te)>this.d.length-2};D.isNaN=function(){return!this.s};D.isNegative=D.isNeg=function(){return this.s<0};D.isPositive=D.isPos=function(){return this.s>0};D.isZero=function(){return!!this.d&&this.d[0]===0};D.lessThan=D.lt=function(o){return this.cmp(o)<0};D.lessThanOrEqualTo=D.lte=function(o){return this.cmp(o)<1};D.logarithm=D.log=function(o){var e,t,n,i,r,s,a,c,u=this,l=u.constructor,d=l.precision,m=l.rounding,p=5;if(o==null)o=new l(10),e=!0;else{if(o=new l(o),t=o.d,o.s<0||!t||!t[0]||o.eq(1))return new l(NaN);e=o.eq(10)}if(t=u.d,u.s<0||!t||!t[0]||u.eq(1))return new l(t&&!t[0]?-1/0:u.s!=1?NaN:t?0:1/0);if(e)if(t.length>1)r=!0;else{for(i=t[0];i%10===0;)i/=10;r=i!==1}if(ie=!1,a=d+p,s=pn(u,a),n=e?Ii(l,a+10):pn(o,a),c=he(s,n,a,1),yo(c.d,i=d,m))do if(a+=10,s=pn(u,a),n=e?Ii(l,a+10):pn(o,a),c=he(s,n,a,1),!r){+nt(c.d).slice(i+1,i+15)+1==1e14&&(c=Z(c,d+1,0));break}while(yo(c.d,i+=10,m));return ie=!0,Z(c,d,m)};D.minus=D.sub=function(o){var e,t,n,i,r,s,a,c,u,l,d,m,p=this,b=p.constructor;if(o=new b(o),!p.d||!o.d)return!p.s||!o.s?o=new b(NaN):p.d?o.s=-o.s:o=new b(o.d||p.s!==o.s?p:NaN),o;if(p.s!=o.s)return o.s=-o.s,p.plus(o);if(u=p.d,m=o.d,a=b.precision,c=b.rounding,!u[0]||!m[0]){if(m[0])o.s=-o.s;else if(u[0])o=new b(p);else return new b(c===3?-0:0);return ie?Z(o,a,c):o}if(t=at(o.e/te),l=at(p.e/te),u=u.slice(),r=l-t,r){for(d=r<0,d?(e=u,r=-r,s=m.length):(e=m,t=l,s=u.length),n=Math.max(Math.ceil(a/te),s)+2,r>n&&(r=n,e.length=1),e.reverse(),n=r;n--;)e.push(0);e.reverse()}else{for(n=u.length,s=m.length,d=n<s,d&&(s=n),n=0;n<s;n++)if(u[n]!=m[n]){d=u[n]<m[n];break}r=0}for(d&&(e=u,u=m,m=e,o.s=-o.s),s=u.length,n=m.length-s;n>0;--n)u[s++]=0;for(n=m.length;n>r;){if(u[--n]<m[n]){for(i=n;i&&u[--i]===0;)u[i]=_t-1;--u[i],u[n]+=_t}u[n]-=m[n]}for(;u[--s]===0;)u.pop();for(;u[0]===0;u.shift())--t;return u[0]?(o.d=u,o.e=Si(u,t),ie?Z(o,a,c):o):new b(c===3?-0:0)};D.modulo=D.mod=function(o){var e,t=this,n=t.constructor;return o=new n(o),!t.d||!o.s||o.d&&!o.d[0]?new n(NaN):!o.d||t.d&&!t.d[0]?Z(new n(t),n.precision,n.rounding):(ie=!1,n.modulo==9?(e=he(t,o.abs(),0,3,1),e.s*=o.s):e=he(t,o,0,n.modulo,1),e=e.times(o),ie=!0,t.minus(e))};D.naturalExponential=D.exp=function(){return vr(this)};D.naturalLogarithm=D.ln=function(){return pn(this)};D.negated=D.neg=function(){var o=new this.constructor(this);return o.s=-o.s,Z(o)};D.plus=D.add=function(o){var e,t,n,i,r,s,a,c,u,l,d=this,m=d.constructor;if(o=new m(o),!d.d||!o.d)return!d.s||!o.s?o=new m(NaN):d.d||(o=new m(o.d||d.s===o.s?d:NaN)),o;if(d.s!=o.s)return o.s=-o.s,d.minus(o);if(u=d.d,l=o.d,a=m.precision,c=m.rounding,!u[0]||!l[0])return l[0]||(o=new m(d)),ie?Z(o,a,c):o;if(r=at(d.e/te),n=at(o.e/te),u=u.slice(),i=r-n,i){for(i<0?(t=u,i=-i,s=l.length):(t=l,n=r,s=u.length),r=Math.ceil(a/te),s=r>s?r+1:s+1,i>s&&(i=s,t.length=1),t.reverse();i--;)t.push(0);t.reverse()}for(s=u.length,i=l.length,s-i<0&&(i=s,t=l,l=u,u=t),e=0;i;)e=(u[--i]=u[i]+l[i]+e)/_t|0,u[i]%=_t;for(e&&(u.unshift(e),++n),s=u.length;u[--s]==0;)u.pop();return o.d=u,o.e=Si(u,n),ie?Z(o,a,c):o};D.precision=D.sd=function(o){var e,t=this;if(o!==void 0&&o!==!!o&&o!==1&&o!==0)throw Error(fn+o);return t.d?(e=_a(t.d),o&&t.e+1>e&&(e=t.e+1)):e=NaN,e};D.round=function(){var o=this,e=o.constructor;return Z(new e(o),o.e+1,e.rounding)};D.sine=D.sin=function(){var o,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(o=n.precision,e=n.rounding,n.precision=o+Math.max(t.e,t.sd())+te,n.rounding=1,t=Tl(n,Da(n,t)),n.precision=o,n.rounding=e,Z(Zt>2?t.neg():t,o,e,!0)):new n(NaN)};D.squareRoot=D.sqrt=function(){var o,e,t,n,i,r,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(ie=!1,u=Math.sqrt(+s),u==0||u==1/0?(e=nt(a),(e.length+c)%2==0&&(e+="0"),u=Math.sqrt(e),c=at((c+1)/2)-(c<0||c%2),u==1/0?e="5e"+c:(e=u.toExponential(),e=e.slice(0,e.indexOf("e")+1)+c),n=new l(e)):n=new l(u.toString()),t=(c=l.precision)+3;;)if(r=n,n=r.plus(he(s,r,t+2,1)).times(.5),nt(r.d).slice(0,t)===(e=nt(n.d)).slice(0,t))if(e=e.slice(t-3,t+1),e=="9999"||!i&&e=="4999"){if(!i&&(Z(r,c+1,0),r.times(r).eq(s))){n=r;break}t+=4,i=1}else{(!+e||!+e.slice(1)&&e.charAt(0)=="5")&&(Z(n,c+1,1),o=!n.times(n).eq(s));break}return ie=!0,Z(n,c,l.rounding,o)};D.tangent=D.tan=function(){var o,e,t=this,n=t.constructor;return t.isFinite()?t.isZero()?new n(t):(o=n.precision,e=n.rounding,n.precision=o+10,n.rounding=1,t=t.sin(),t.s=1,t=he(t,new n(1).minus(t.times(t)).sqrt(),o+10,0),n.precision=o,n.rounding=e,Z(Zt==2||Zt==4?t.neg():t,o,e,!0)):new n(NaN)};D.times=D.mul=function(o){var e,t,n,i,r,s,a,c,u,l=this,d=l.constructor,m=l.d,p=(o=new d(o)).d;if(o.s*=l.s,!m||!m[0]||!p||!p[0])return new d(!o.s||m&&!m[0]&&!p||p&&!p[0]&&!m?NaN:!m||!p?o.s/0:o.s*0);for(t=at(l.e/te)+at(o.e/te),c=m.length,u=p.length,c<u&&(r=m,m=p,p=r,s=c,c=u,u=s),r=[],s=c+u,n=s;n--;)r.push(0);for(n=u;--n>=0;){for(e=0,i=c+n;i>n;)a=r[i]+p[n]*m[i-n-1]+e,r[i--]=a%_t|0,e=a/_t|0;r[i]=(r[i]+e)%_t|0}for(;!r[--s];)r.pop();return e?++t:r.shift(),o.d=r,o.e=Si(r,t),ie?Z(o,d.precision,d.rounding):o};D.toBinary=function(o,e){return Vr(this,2,o,e)};D.toDecimalPlaces=D.toDP=function(o,e){var t=this,n=t.constructor;return t=new n(t),o===void 0?t:(gt(o,0,bn),e===void 0?e=n.rounding:gt(e,0,8),Z(t,o+t.e+1,e))};D.toExponential=function(o,e){var t,n=this,i=n.constructor;return o===void 0?t=Xt(n,!0):(gt(o,0,bn),e===void 0?e=i.rounding:gt(e,0,8),n=Z(new i(n),o+1,e),t=Xt(n,!0,o+1)),n.isNeg()&&!n.isZero()?"-"+t:t};D.toFixed=function(o,e){var t,n,i=this,r=i.constructor;return o===void 0?t=Xt(i):(gt(o,0,bn),e===void 0?e=r.rounding:gt(e,0,8),n=Z(new r(i),o+i.e+1,e),t=Xt(n,!1,o+n.e+1)),i.isNeg()&&!i.isZero()?"-"+t:t};D.toFraction=function(o){var e,t,n,i,r,s,a,c,u,l,d,m,p=this,b=p.d,f=p.constructor;if(!b)return new f(p);if(u=t=new f(1),n=c=new f(0),e=new f(n),r=e.e=_a(b)-p.e-1,s=r%te,e.d[0]=Ye(10,s<0?te+s:s),o==null)o=r>0?e:u;else{if(a=new f(o),!a.isInt()||a.lt(u))throw Error(fn+a);o=a.gt(e)?r>0?e:u:a}for(ie=!1,a=new f(nt(b)),l=f.precision,f.precision=r=b.length*te*2;d=he(a,e,0,1,1),i=t.plus(d.times(n)),i.cmp(o)!=1;)t=n,n=i,i=u,u=c.plus(d.times(i)),c=i,i=e,e=a.minus(d.times(i)),a=i;return i=he(o.minus(t),n,0,1,1),c=c.plus(i.times(u)),t=t.plus(i.times(n)),c.s=u.s=p.s,m=he(u,n,r,1).minus(p).abs().cmp(he(c,t,r,1).minus(p).abs())<1?[u,n]:[c,t],f.precision=l,ie=!0,m};D.toHexadecimal=D.toHex=function(o,e){return Vr(this,16,o,e)};D.toNearest=function(o,e){var t=this,n=t.constructor;if(t=new n(t),o==null){if(!t.d)return t;o=new n(1),e=n.rounding}else{if(o=new n(o),e===void 0?e=n.rounding:gt(e,0,8),!t.d)return o.s?t:o;if(!o.d)return o.s&&(o.s=t.s),o}return o.d[0]?(ie=!1,t=he(t,o,0,e,1).times(o),ie=!0,Z(t)):(o.s=t.s,t=o),t};D.toNumber=function(){return+this};D.toOctal=function(o,e){return Vr(this,8,o,e)};D.toPower=D.pow=function(o){var e,t,n,i,r,s,a=this,c=a.constructor,u=+(o=new c(o));if(!a.d||!o.d||!a.d[0]||!o.d[0])return new c(Ye(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,r=c.rounding,o.eq(1))return Z(a,n,r);if(e=at(o.e/te),e>=o.d.length-1&&(t=u<0?-u:u)<=Al)return i=Ea(c,a,t,n),o.s<0?new c(1).div(i):Z(i,n,r);if(s=a.s,s<0){if(e<o.d.length-1)return new c(NaN);if((o.d[e]&1)==0&&(s=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=s,a}return t=Ye(+a,u),e=t==0||!isFinite(t)?at(u*(Math.log("0."+nt(a.d))/Math.LN10+a.e+1)):new c(t+"").e,e>c.maxE+1||e<c.minE-1?new c(e>0?s/0:0):(ie=!1,c.rounding=a.s=1,t=Math.min(12,(e+"").length),i=vr(o.times(pn(a,n+t)),n),i.d&&(i=Z(i,n+5,1),yo(i.d,n,r)&&(e=n+10,i=Z(vr(o.times(pn(a,e+t)),e),e+5,1),+nt(i.d).slice(n+1,n+15)+1==1e14&&(i=Z(i,n+1,0)))),i.s=s,ie=!0,c.rounding=r,Z(i,n,r))};D.toPrecision=function(o,e){var t,n=this,i=n.constructor;return o===void 0?t=Xt(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(gt(o,1,bn),e===void 0?e=i.rounding:gt(e,0,8),n=Z(new i(n),o,e),t=Xt(n,o<=n.e||n.e<=i.toExpNeg,o)),n.isNeg()&&!n.isZero()?"-"+t:t};D.toSignificantDigits=D.toSD=function(o,e){var t=this,n=t.constructor;return o===void 0?(o=n.precision,e=n.rounding):(gt(o,1,bn),e===void 0?e=n.rounding:gt(e,0,8)),Z(new n(t),o,e)};D.toString=function(){var o=this,e=o.constructor,t=Xt(o,o.e<=e.toExpNeg||o.e>=e.toExpPos);return o.isNeg()&&!o.isZero()?"-"+t:t};D.truncated=D.trunc=function(){return Z(new this.constructor(this),this.e+1,1)};D.valueOf=D.toJSON=function(){var o=this,e=o.constructor,t=Xt(o,o.e<=e.toExpNeg||o.e>=e.toExpPos);return o.isNeg()?"-"+t:t};function nt(o){var e,t,n,i=o.length-1,r="",s=o[0];if(i>0){for(r+=s,e=1;e<i;e++)n=o[e]+"",t=te-n.length,t&&(r+=dn(t)),r+=n;s=o[e],n=s+"",t=te-n.length,t&&(r+=dn(t))}else if(s===0)return"0";for(;s%10===0;)s/=10;return r+s}function gt(o,e,t){if(o!==~~o||o<e||o>t)throw Error(fn+o)}function yo(o,e,t,n){var i,r,s,a;for(r=o[0];r>=10;r/=10)--e;return--e<0?(e+=te,i=0):(i=Math.ceil((e+1)/te),e%=te),r=Ye(10,te-e),a=o[i]%r|0,n==null?e<3?(e==0?a=a/100|0:e==1&&(a=a/10|0),s=t<4&&a==99999||t>3&&a==49999||a==5e4||a==0):s=(t<4&&a+1==r||t>3&&a+1==r/2)&&(o[i+1]/r/100|0)==Ye(10,e-2)-1||(a==r/2||a==0)&&(o[i+1]/r/100|0)==0:e<4?(e==0?a=a/1e3|0:e==1?a=a/100|0:e==2&&(a=a/10|0),s=(n||t<4)&&a==9999||!n&&t>3&&a==4999):s=((n||t<4)&&a+1==r||!n&&t>3&&a+1==r/2)&&(o[i+1]/r/1e3|0)==Ye(10,e-3)-1,s}function ki(o,e,t){for(var n,i=[0],r,s=0,a=o.length;s<a;){for(r=i.length;r--;)i[r]*=e;for(i[0]+=Mr.indexOf(o.charAt(s++)),n=0;n<i.length;n++)i[n]>t-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/t|0,i[n]%=t)}return i.reverse()}function Pl(o,e){var t,n,i;if(e.isZero())return e;n=e.d.length,n<32?(t=Math.ceil(n/3),i=(1/xi(4,t)).toString()):(t=16,i="2.3283064365386962890625e-10"),o.precision+=t,e=Zn(o,1,e.times(i),new o(1));for(var r=t;r--;){var s=e.times(e);e=s.times(s).minus(s).times(8).plus(1)}return o.precision-=t,e}var he=function(){function o(n,i,r){var s,a=0,c=n.length;for(n=n.slice();c--;)s=n[c]*i+a,n[c]=s%r|0,a=s/r|0;return a&&n.unshift(a),n}function e(n,i,r,s){var a,c;if(r!=s)c=r>s?1:-1;else for(a=c=0;a<r;a++)if(n[a]!=i[a]){c=n[a]>i[a]?1:-1;break}return c}function t(n,i,r,s){for(var a=0;r--;)n[r]-=a,a=n[r]<i[r]?1:0,n[r]=a*s+n[r]-i[r];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,r,s,a,c){var u,l,d,m,p,b,f,g,y,A,k,h,I,T,S,B,C,x,K,M,R=n.constructor,V=n.s==i.s?1:-1,U=n.d,W=i.d;if(!U||!U[0]||!W||!W[0])return new R(!n.s||!i.s||(U?W&&U[0]==W[0]:!W)?NaN:U&&U[0]==0||!W?V*0:V/0);for(c?(p=1,l=n.e-i.e):(c=_t,p=te,l=at(n.e/p)-at(i.e/p)),K=W.length,C=U.length,y=new R(V),A=y.d=[],d=0;W[d]==(U[d]||0);d++);if(W[d]>(U[d]||0)&&l--,r==null?(T=r=R.precision,s=R.rounding):a?T=r+(n.e-i.e)+1:T=r,T<0)A.push(1),b=!0;else{if(T=T/p+2|0,d=0,K==1){for(m=0,W=W[0],T++;(d<C||m)&&T--;d++)S=m*c+(U[d]||0),A[d]=S/W|0,m=S%W|0;b=m||d<C}else{for(m=c/(W[0]+1)|0,m>1&&(W=o(W,m,c),U=o(U,m,c),K=W.length,C=U.length),B=K,k=U.slice(0,K),h=k.length;h<K;)k[h++]=0;M=W.slice(),M.unshift(0),x=W[0],W[1]>=c/2&&++x;do m=0,u=e(W,k,K,h),u<0?(I=k[0],K!=h&&(I=I*c+(k[1]||0)),m=I/x|0,m>1?(m>=c&&(m=c-1),f=o(W,m,c),g=f.length,h=k.length,u=e(f,k,g,h),u==1&&(m--,t(f,K<g?M:W,g,c))):(m==0&&(u=m=1),f=W.slice()),g=f.length,g<h&&f.unshift(0),t(k,f,h,c),u==-1&&(h=k.length,u=e(W,k,K,h),u<1&&(m++,t(k,K<h?M:W,h,c))),h=k.length):u===0&&(m++,k=[0]),A[d++]=m,u&&k[0]?k[h++]=U[B]||0:(k=[U[B]],h=1);while((B++<C||k[0]!==void 0)&&T--);b=k[0]!==void 0}A[0]||A.shift()}if(p==1)y.e=l,La=b;else{for(d=1,m=A[0];m>=10;m/=10)d++;y.e=d+l*p-1,Z(y,a?r+y.e+1:r,s,b)}return y}}();function Z(o,e,t,n){var i,r,s,a,c,u,l,d,m,p=o.constructor;e:if(e!=null){if(d=o.d,!d)return o;for(i=1,a=d[0];a>=10;a/=10)i++;if(r=e-i,r<0)r+=te,s=e,l=d[m=0],c=l/Ye(10,i-s-1)%10|0;else if(m=Math.ceil((r+1)/te),a=d.length,m>=a)if(n){for(;a++<=m;)d.push(0);l=c=0,i=1,r%=te,s=r-te+1}else break e;else{for(l=a=d[m],i=1;a>=10;a/=10)i++;r%=te,s=r-te+i,c=s<0?0:l/Ye(10,i-s-1)%10|0}if(n=n||e<0||d[m+1]!==void 0||(s<0?l:l%Ye(10,i-s-1)),u=t<4?(c||n)&&(t==0||t==(o.s<0?3:2)):c>5||c==5&&(t==4||n||t==6&&(r>0?s>0?l/Ye(10,i-s):0:d[m-1])%10&1||t==(o.s<0?8:7)),e<1||!d[0])return d.length=0,u?(e-=o.e+1,d[0]=Ye(10,(te-e%te)%te),o.e=-e||0):d[0]=o.e=0,o;if(r==0?(d.length=m,a=1,m--):(d.length=m+1,a=Ye(10,te-r),d[m]=s>0?(l/Ye(10,i-s)%Ye(10,s)|0)*a:0),u)for(;;)if(m==0){for(r=1,s=d[0];s>=10;s/=10)r++;for(s=d[0]+=a,a=1;s>=10;s/=10)a++;r!=a&&(o.e++,d[0]==_t&&(d[0]=1));break}else{if(d[m]+=a,d[m]!=_t)break;d[m--]=0,a=1}for(r=d.length;d[--r]===0;)d.pop()}return ie&&(o.e>p.maxE?(o.d=null,o.e=NaN):o.e<p.minE&&(o.e=0,o.d=[0])),o}function Xt(o,e,t){if(!o.isFinite())return Va(o);var n,i=o.e,r=nt(o.d),s=r.length;return e?(t&&(n=t-s)>0?r=r.charAt(0)+"."+r.slice(1)+dn(n):s>1&&(r=r.charAt(0)+"."+r.slice(1)),r=r+(o.e<0?"e":"e+")+o.e):i<0?(r="0."+dn(-i-1)+r,t&&(n=t-s)>0&&(r+=dn(n))):i>=s?(r+=dn(i+1-s),t&&(n=t-i-1)>0&&(r=r+"."+dn(n))):((n=i+1)<s&&(r=r.slice(0,n)+"."+r.slice(n)),t&&(n=t-s)>0&&(i+1===s&&(r+="."),r+=dn(n))),r}function Si(o,e){var t=o[0];for(e*=te;t>=10;t/=10)e++;return e}function Ii(o,e,t){if(e>kl)throw ie=!0,t&&(o.precision=t),Error(Oa);return Z(new o(hi),e,1,!0)}function Gt(o,e,t){if(e>Er)throw Error(Oa);return Z(new o(Ti),e,t,!0)}function _a(o){var e=o.length-1,t=e*te+1;if(e=o[e],e){for(;e%10==0;e/=10)t--;for(e=o[0];e>=10;e/=10)t++}return t}function dn(o){for(var e="";o--;)e+="0";return e}function Ea(o,e,t,n){var i,r=new o(1),s=Math.ceil(n/te+4);for(ie=!1;;){if(t%2&&(r=r.times(e),Ka(r.d,s)&&(i=!0)),t=at(t/2),t===0){t=r.d.length-1,i&&r.d[t]===0&&++r.d[t];break}e=e.times(e),Ka(e.d,s)}return ie=!0,r}function xa(o){return o.d[o.d.length-1]&1}function va(o,e,t){for(var n,i,r=new o(e[0]),s=0;++s<e.length;){if(i=new o(e[s]),!i.s){r=i;break}n=r.cmp(i),(n===t||n===0&&r.s===t)&&(r=i)}return r}function vr(o,e){var t,n,i,r,s,a,c,u=0,l=0,d=0,m=o.constructor,p=m.rounding,b=m.precision;if(!o.d||!o.d[0]||o.e>17)return new m(o.d?o.d[0]?o.s<0?0:1/0:1:o.s?o.s<0?0:o:0/0);for(e==null?(ie=!1,c=b):c=e,a=new m(.03125);o.e>-2;)o=o.times(a),d+=5;for(n=Math.log(Ye(2,d))/Math.LN10*2+5|0,c+=n,t=r=s=new m(1),m.precision=c;;){if(r=Z(r.times(o),c,1),t=t.times(++l),a=s.plus(he(r,t,c,1)),nt(a.d).slice(0,c)===nt(s.d).slice(0,c)){for(i=d;i--;)s=Z(s.times(s),c,1);if(e==null)if(u<3&&yo(s.d,c-n,p,u))m.precision=c+=10,t=r=a=new m(1),l=0,u++;else return Z(s,m.precision=b,p,ie=!0);else return m.precision=b,s}s=a}}function pn(o,e){var t,n,i,r,s,a,c,u,l,d,m,p=1,b=10,f=o,g=f.d,y=f.constructor,A=y.rounding,k=y.precision;if(f.s<0||!g||!g[0]||!f.e&&g[0]==1&&g.length==1)return new y(g&&!g[0]?-1/0:f.s!=1?NaN:g?0:f);if(e==null?(ie=!1,l=k):l=e,y.precision=l+=b,t=nt(g),n=t.charAt(0),Math.abs(r=f.e)<15e14){for(;n<7&&n!=1||n==1&&t.charAt(1)>3;)f=f.times(o),t=nt(f.d),n=t.charAt(0),p++;r=f.e,n>1?(f=new y("0."+t),r++):f=new y(n+"."+t.slice(1))}else return u=Ii(y,l+2,k).times(r+""),f=pn(new y(n+"."+t.slice(1)),l-b).plus(u),y.precision=k,e==null?Z(f,k,A,ie=!0):f;for(d=f,c=s=f=he(f.minus(1),f.plus(1),l,1),m=Z(f.times(f),l,1),i=3;;){if(s=Z(s.times(m),l,1),u=c.plus(he(s,new y(i),l,1)),nt(u.d).slice(0,l)===nt(c.d).slice(0,l))if(c=c.times(2),r!==0&&(c=c.plus(Ii(y,l+2,k).times(r+""))),c=he(c,new y(p),l,1),e==null)if(yo(c.d,l-b,A,a))y.precision=l+=b,u=s=f=he(d.minus(1),d.plus(1),l,1),m=Z(f.times(f),l,1),i=a=1;else return Z(c,y.precision=k,A,ie=!0);else return y.precision=k,c;c=u,i+=2}}function Va(o){return String(o.s*o.s/0)}function Pi(o,e){var t,n,i;for((t=e.indexOf("."))>-1&&(e=e.replace(".","")),(n=e.search(/e/i))>0?(t<0&&(t=n),t+=+e.slice(n+1),e=e.substring(0,n)):t<0&&(t=e.length),n=0;e.charCodeAt(n)===48;n++);for(i=e.length;e.charCodeAt(i-1)===48;--i);if(e=e.slice(n,i),e){if(i-=n,o.e=t=t-n-1,o.d=[],n=(t+1)%te,t<0&&(n+=te),n<i){for(n&&o.d.push(+e.slice(0,n)),i-=te;n<i;)o.d.push(+e.slice(n,n+=te));e=e.slice(n),n=te-e.length}else n-=i;for(;n--;)e+="0";o.d.push(+e),ie&&(o.e>o.constructor.maxE?(o.d=null,o.e=NaN):o.e<o.constructor.minE&&(o.e=0,o.d=[0]))}else o.e=0,o.d=[0];return o}function hl(o,e){var t,n,i,r,s,a,c,u,l;if(e.indexOf("_")>-1){if(e=e.replace(/(\d)_(?=\d)/g,"$1"),Ma.test(e))return Pi(o,e)}else if(e==="Infinity"||e==="NaN")return+e||(o.s=NaN),o.e=NaN,o.d=null,o;if(gl.test(e))t=16,e=e.toLowerCase();else if(yl.test(e))t=2;else if(wl.test(e))t=8;else throw Error(fn+e);for(r=e.search(/p/i),r>0?(c=+e.slice(r+1),e=e.substring(2,r)):e=e.slice(2),r=e.indexOf("."),s=r>=0,n=o.constructor,s&&(e=e.replace(".",""),a=e.length,r=a-r,i=Ea(n,new n(t),r,r*2)),u=ki(e,t,_t),l=u.length-1,r=l;u[r]===0;--r)u.pop();return r<0?new n(o.s*0):(o.e=Si(u,l),o.d=u,ie=!1,s&&(o=he(o,i,a*4)),c&&(o=o.times(Math.abs(c)<54?Ye(2,c):go.pow(2,c))),ie=!0,o)}function Tl(o,e){var t,n=e.d.length;if(n<3)return e.isZero()?e:Zn(o,2,e,e);t=1.4*Math.sqrt(n),t=t>16?16:t|0,e=e.times(1/xi(5,t)),e=Zn(o,2,e,e);for(var i,r=new o(5),s=new o(16),a=new o(20);t--;)i=e.times(e),e=e.times(r.plus(i.times(s.times(i).minus(a))));return e}function Zn(o,e,t,n,i){var r,s,a,c,u=1,l=o.precision,d=Math.ceil(l/te);for(ie=!1,c=t.times(t),a=new o(n);;){if(s=he(a.times(c),new o(e++*e++),l,1),a=i?n.plus(s):n.minus(s),n=he(s.times(c),new o(e++*e++),l,1),s=a.plus(n),s.d[d]!==void 0){for(r=d;s.d[r]===a.d[r]&&r--;);if(r==-1)break}r=a,a=n,n=s,s=r,u++}return ie=!0,s.d.length=d+1,s}function xi(o,e){for(var t=o;--e;)t*=o;return t}function Da(o,e){var t,n=e.s<0,i=Gt(o,o.precision,1),r=i.times(.5);if(e=e.abs(),e.lte(r))return Zt=n?4:1,e;if(t=e.divToInt(i),t.isZero())Zt=n?3:2;else{if(e=e.minus(t.times(i)),e.lte(r))return Zt=xa(t)?n?2:3:n?4:1,e;Zt=xa(t)?n?1:4:n?3:2}return e.minus(i).abs()}function Vr(o,e,t,n){var i,r,s,a,c,u,l,d,m,p=o.constructor,b=t!==void 0;if(b?(gt(t,1,bn),n===void 0?n=p.rounding:gt(n,0,8)):(t=p.precision,n=p.rounding),!o.isFinite())l=Va(o);else{for(l=Xt(o),s=l.indexOf("."),b?(i=2,e==16?t=t*4-3:e==8&&(t=t*3-2)):i=e,s>=0&&(l=l.replace(".",""),m=new p(1),m.e=l.length-s,m.d=ki(Xt(m),10,i),m.e=m.d.length),d=ki(l,10,i),r=c=d.length;d[--c]==0;)d.pop();if(!d[0])l=b?"0p+0":"0";else{if(s<0?r--:(o=new p(o),o.d=d,o.e=r,o=he(o,m,t,n,0,i),d=o.d,r=o.e,u=La),s=d[t],a=i/2,u=u||d[t+1]!==void 0,u=n<4?(s!==void 0||u)&&(n===0||n===(o.s<0?3:2)):s>a||s===a&&(n===4||u||n===6&&d[t-1]&1||n===(o.s<0?8:7)),d.length=t,u)for(;++d[--t]>i-1;)d[t]=0,t||(++r,d.unshift(1));for(c=d.length;!d[c-1];--c);for(s=0,l="";s<c;s++)l+=Mr.charAt(d[s]);if(b){if(c>1)if(e==16||e==8){for(s=e==16?4:3,--c;c%s;c++)l+="0";for(d=ki(l,i,e),c=d.length;!d[c-1];--c);for(s=1,l="1.";s<c;s++)l+=Mr.charAt(d[s])}else l=l.charAt(0)+"."+l.slice(1);l=l+(r<0?"p":"p+")+r}else if(r<0){for(;++r;)l="0"+l;l="0."+l}else if(++r>c)for(r-=c;r--;)l+="0";else r<c&&(l=l.slice(0,r)+"."+l.slice(r))}l=(e==16?"0x":e==2?"0b":e==8?"0o":"")+l}return o.s<0?"-"+l:l}function Ka(o,e){if(o.length>e)return o.length=e,!0}function Il(o){return new this(o).abs()}function Bl(o){return new this(o).acos()}function Sl(o){return new this(o).acosh()}function xl(o,e){return new this(o).plus(e)}function Kl(o){return new this(o).asin()}function Cl(o){return new this(o).asinh()}function Ll(o){return new this(o).atan()}function Ol(o){return new this(o).atanh()}function Rl(o,e){o=new this(o),e=new this(e);var t,n=this.precision,i=this.rounding,r=n+4;return!o.s||!e.s?t=new this(NaN):!o.d&&!e.d?(t=Gt(this,r,1).times(e.s>0?.25:.75),t.s=o.s):!e.d||o.isZero()?(t=e.s<0?Gt(this,n,i):new this(0),t.s=o.s):!o.d||e.isZero()?(t=Gt(this,r,1).times(.5),t.s=o.s):e.s<0?(this.precision=r,this.rounding=1,t=this.atan(he(o,e,r,1)),e=Gt(this,r,1),this.precision=n,this.rounding=i,t=o.s<0?t.minus(e):t.plus(e)):t=this.atan(he(o,e,r,1)),t}function Nl(o){return new this(o).cbrt()}function Ml(o){return Z(o=new this(o),o.e+1,2)}function _l(o,e,t){return new this(o).clamp(e,t)}function El(o){if(!o||typeof o!="object")throw Error(Bi+"Object expected");var e,t,n,i=o.defaults===!0,r=["precision",1,bn,"rounding",0,8,"toExpNeg",-jn,0,"toExpPos",0,jn,"maxE",0,jn,"minE",-jn,0,"modulo",0,9];for(e=0;e<r.length;e+=3)if(t=r[e],i&&(this[t]=_r[t]),(n=o[t])!==void 0)if(at(n)===n&&n>=r[e+1]&&n<=r[e+2])this[t]=n;else throw Error(fn+t+": "+n);if(t="crypto",i&&(this[t]=_r[t]),(n=o[t])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[t]=!0;else throw Error(Ra);else this[t]=!1;else throw Error(fn+t+": "+n);return this}function vl(o){return new this(o).cos()}function Vl(o){return new this(o).cosh()}function Fa(o){var e,t,n;function i(r){var s,a,c,u=this;if(!(u instanceof i))return new i(r);if(u.constructor=i,Ca(r)){u.s=r.s,ie?!r.d||r.e>i.maxE?(u.e=NaN,u.d=null):r.e<i.minE?(u.e=0,u.d=[0]):(u.e=r.e,u.d=r.d.slice()):(u.e=r.e,u.d=r.d?r.d.slice():r.d);return}if(c=typeof r,c==="number"){if(r===0){u.s=1/r<0?-1:1,u.e=0,u.d=[0];return}if(r<0?(r=-r,u.s=-1):u.s=1,r===~~r&&r<1e7){for(s=0,a=r;a>=10;a/=10)s++;ie?s>i.maxE?(u.e=NaN,u.d=null):s<i.minE?(u.e=0,u.d=[0]):(u.e=s,u.d=[r]):(u.e=s,u.d=[r]);return}if(r*0!==0){r||(u.s=NaN),u.e=NaN,u.d=null;return}return Pi(u,r.toString())}if(c==="string")return(a=r.charCodeAt(0))===45?(r=r.slice(1),u.s=-1):(a===43&&(r=r.slice(1)),u.s=1),Ma.test(r)?Pi(u,r):hl(u,r);if(c==="bigint")return r<0?(r=-r,u.s=-1):u.s=1,Pi(u,r.toString());throw Error(fn+r)}if(i.prototype=D,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=El,i.clone=Fa,i.isDecimal=Ca,i.abs=Il,i.acos=Bl,i.acosh=Sl,i.add=xl,i.asin=Kl,i.asinh=Cl,i.atan=Ll,i.atanh=Ol,i.atan2=Rl,i.cbrt=Nl,i.ceil=Ml,i.clamp=_l,i.cos=vl,i.cosh=Vl,i.div=Dl,i.exp=Fl,i.floor=Wl,i.hypot=ql,i.ln=Ul,i.log=Gl,i.log10=Hl,i.log2=Xl,i.max=Ql,i.min=zl,i.mod=Yl,i.mul=jl,i.pow=Zl,i.random=$l,i.round=Jl,i.sign=em,i.sin=tm,i.sinh=nm,i.sqrt=om,i.sub=im,i.sum=rm,i.tan=sm,i.tanh=am,i.trunc=um,o===void 0&&(o={}),o&&o.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],e=0;e<n.length;)o.hasOwnProperty(t=n[e++])||(o[t]=this[t]);return i.config(o),i}function Dl(o,e){return new this(o).div(e)}function Fl(o){return new this(o).exp()}function Wl(o){return Z(o=new this(o),o.e+1,3)}function ql(){var o,e,t=new this(0);for(ie=!1,o=0;o<arguments.length;)if(e=new this(arguments[o++]),e.d)t.d&&(t=t.plus(e.times(e)));else{if(e.s)return ie=!0,new this(1/0);t=e}return ie=!0,t.sqrt()}function Ca(o){return o instanceof go||o&&o.toStringTag===Na||!1}function Ul(o){return new this(o).ln()}function Gl(o,e){return new this(o).log(e)}function Xl(o){return new this(o).log(2)}function Hl(o){return new this(o).log(10)}function Ql(){return va(this,arguments,-1)}function zl(){return va(this,arguments,1)}function Yl(o,e){return new this(o).mod(e)}function jl(o,e){return new this(o).mul(e)}function Zl(o,e){return new this(o).pow(e)}function $l(o){var e,t,n,i,r=0,s=new this(1),a=[];if(o===void 0?o=this.precision:gt(o,1,bn),n=Math.ceil(o/te),this.crypto)if(crypto.getRandomValues)for(e=crypto.getRandomValues(new Uint32Array(n));r<n;)i=e[r],i>=429e7?e[r]=crypto.getRandomValues(new Uint32Array(1))[0]:a[r++]=i%1e7;else if(crypto.randomBytes){for(e=crypto.randomBytes(n*=4);r<n;)i=e[r]+(e[r+1]<<8)+(e[r+2]<<16)+((e[r+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(e,r):(a.push(i%1e7),r+=4);r=n/4}else throw Error(Ra);else for(;r<n;)a[r++]=Math.random()*1e7|0;for(n=a[--r],o%=te,n&&o&&(i=Ye(10,te-o),a[r]=(n/i|0)*i);a[r]===0;r--)a.pop();if(r<0)t=0,a=[0];else{for(t=-1;a[0]===0;t-=te)a.shift();for(n=1,i=a[0];i>=10;i/=10)n++;n<te&&(t-=te-n)}return s.e=t,s.d=a,s}function Jl(o){return Z(o=new this(o),o.e+1,this.rounding)}function em(o){return o=new this(o),o.d?o.d[0]?o.s:0*o.s:o.s||NaN}function tm(o){return new this(o).sin()}function nm(o){return new this(o).sinh()}function om(o){return new this(o).sqrt()}function im(o,e){return new this(o).sub(e)}function rm(){var o=0,e=arguments,t=new this(e[o]);for(ie=!1;t.s&&++o<e.length;)t=t.plus(e[o]);return ie=!0,Z(t,this.precision,this.rounding)}function sm(o){return new this(o).tan()}function am(o){return new this(o).tanh()}function um(o){return Z(o=new this(o),o.e+1,1)}D[Symbol.for("nodejs.util.inspect.custom")]=D.toString;D[Symbol.toStringTag]="Decimal";var go=D.constructor=Fa(_r);hi=new go(hi);Ti=new go(Ti);var N=go;import bm from"big.js";import yn from"bn.js";import cm from"toformat";var lm=cm,wo=lm;import Ci from"big.js";import mm from"bn.js";import dm from"decimal.js-light";import Ao from"bn.js";var Dr=(n=>(n[n.ROUND_DOWN=0]="ROUND_DOWN",n[n.ROUND_HALF_UP=1]="ROUND_HALF_UP",n[n.ROUND_UP=2]="ROUND_UP",n))(Dr||{}),Wa=9007199254740991;function Y(o){let e=ce("CobaltX_parseBigNumberish");if(o instanceof Ao)return o;if(typeof o=="string"){if(o.match(/^-?[0-9]+$/))return new Ao(o);e.logWithError(`invalid BigNumberish string: ${o}`)}return typeof o=="number"?(o%1&&e.logWithError(`BigNumberish number underflow: ${o}`),(o>=Wa||o<=-Wa)&&e.logWithError(`BigNumberish number overflow: ${o}`),new Ao(String(o))):typeof o=="bigint"?new Ao(o.toString()):(e.error(`invalid BigNumberish value: ${o}`),new Ao(0))}var Ki=ce("module/fraction"),Fr=wo(Ci),ko=wo(dm),pm={[0]:ko.ROUND_DOWN,[1]:ko.ROUND_HALF_UP,[2]:ko.ROUND_UP},fm={[0]:Ci.roundDown,[1]:Ci.roundHalfUp,[2]:Ci.roundUp},re=class{constructor(e,t=new mm(1)){this.numerator=Y(e),this.denominator=Y(t)}get quotient(){return this.numerator.div(this.denominator)}invert(){return new re(this.denominator,this.numerator)}add(e){let t=e instanceof re?e:new re(Y(e));return this.denominator.eq(t.denominator)?new re(this.numerator.add(t.numerator),this.denominator):new re(this.numerator.mul(t.denominator).add(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}sub(e){let t=e instanceof re?e:new re(Y(e));return this.denominator.eq(t.denominator)?new re(this.numerator.sub(t.numerator),this.denominator):new re(this.numerator.mul(t.denominator).sub(t.numerator.mul(this.denominator)),this.denominator.mul(t.denominator))}mul(e){let t=e instanceof re?e:new re(Y(e));return new re(this.numerator.mul(t.numerator),this.denominator.mul(t.denominator))}div(e){let t=e instanceof re?e:new re(Y(e));return new re(this.numerator.mul(t.denominator),this.denominator.mul(t.numerator))}toSignificant(e,t={groupSeparator:""},n=1){Number.isInteger(e)||Ki.logWithError(`${e} is not an integer.`),e<=0&&Ki.logWithError(`${e} is not positive.`),ko.set({precision:e+1,rounding:pm[n]});let i=new ko(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return i.toFormat(i.decimalPlaces(),t)}toFixed(e,t={groupSeparator:""},n=1){return Number.isInteger(e)||Ki.logWithError(`${e} is not an integer.`),e<0&&Ki.logWithError(`${e} is negative.`),Fr.DP=e,Fr.RM=fm[n]||1,new Fr(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)}isZero(){return this.numerator.isZero()}};var ym=ce("CobaltX_amount"),Li=wo(bm);function qa(o,e){let t="0",n="0";if(o.includes(".")){let i=o.split(".");i.length===2?([t,n]=i,n=n.padEnd(e,"0")):ym.logWithError(`invalid number string, num: ${o}`)}else t=o;return[t,n.slice(0,e)||n]}var fe=class extends re{constructor(t,n,i=!0,r){let s=new yn(0),a=Cn.pow(new yn(t.decimals));if(i)s=Y(n);else{let c=new yn(0),u=new yn(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,d]=qa(n.toString(),t.decimals);c=Y(l),u=Y(d)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=ce(r||"TokenAmount"),this.token=t}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(t){return this.token.equals(t.token)||this.logger.logWithError("gt token not equals"),this.raw.gt(t.raw)}lt(t){return this.token.equals(t.token)||this.logger.logWithError("lt token not equals"),this.raw.lt(t.raw)}add(t){return this.token.equals(t.token)||this.logger.logWithError("add token not equals"),new fe(this.token,this.raw.add(t.raw))}subtract(t){return this.token.equals(t.token)||this.logger.logWithError("sub token not equals"),new fe(this.token,this.raw.sub(t.raw))}toSignificant(t=this.token.decimals,n,i=0){return super.toSignificant(t,n,i)}toFixed(t=this.token.decimals,n,i=0){return t>this.token.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(t,n,i)}toExact(t={groupSeparator:""}){return Li.DP=this.token.decimals,new Li(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)}},Kn=class extends re{constructor(t,n,i=!0,r){let s=new yn(0),a=Cn.pow(new yn(t.decimals));if(i)s=Y(n);else{let c=new yn(0),u=new yn(0);if(typeof n=="string"||typeof n=="number"||typeof n=="bigint"){let[l,d]=qa(n.toString(),t.decimals);c=Y(l),u=Y(d)}c=c.mul(a),s=c.add(u)}super(s,a);this.logger=ce(r||"TokenAmount"),this.currency=t}get raw(){return this.numerator}isZero(){return this.raw.isZero()}gt(t){return this.currency.equals(t.currency)||this.logger.logWithError("gt currency not equals"),this.raw.gt(t.raw)}lt(t){return this.currency.equals(t.currency)||this.logger.logWithError("lt currency not equals"),this.raw.lt(t.raw)}add(t){return this.currency.equals(t.currency)||this.logger.logWithError("add currency not equals"),new Kn(this.currency,this.raw.add(t.raw))}sub(t){return this.currency.equals(t.currency)||this.logger.logWithError("sub currency not equals"),new Kn(this.currency,this.raw.sub(t.raw))}toSignificant(t=this.currency.decimals,n,i=0){return super.toSignificant(t,n,i)}toFixed(t=this.currency.decimals,n,i=0){return t>this.currency.decimals&&this.logger.logWithError("decimals overflow"),super.toFixed(t,n,i)}toExact(t={groupSeparator:""}){return Li.DP=this.currency.decimals,new Li(this.numerator.toString()).div(this.denominator.toString()).toFormat(t)}};import{TOKEN_PROGRAM_ID as Ua}from"@solana/spl-token";import{PublicKey as wm}from"@solana/web3.js";import{PublicKey as $t}from"@solana/web3.js";var gm={["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:$t.default.toString(),OUTPUT_MINT_ADDRESS:"742wcXVzkhNuEePAot7L3GvPseh93pvYFPgyHLX8mUy9",POPULAR_TOKENS:{SOL:$t.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:$t.default.toBase58(),OUTPUT_MINT_ADDRESS:"ABoT7umUXnx8RtJTeRqKB6myebVjP2wdJGQuV23jVVH3",POPULAR_TOKENS:{SOL:$t.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:$t.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:$t.default.toString(),OUTPUT_MINT_ADDRESS:"63tPXWPnYeZ9hA3dJsAY5RcQ8YbwEz8uZ5nKu3uFD1aK",POPULAR_TOKENS:{SOL:$t.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:$t.default.toString(),OUTPUT_MINT_ADDRESS:"BoYN2f2gLQS4jpvMSV9dAZwfzKJiKGk4NPck5BjXfujo",POPULAR_TOKENS:{SOL:$t.default.toString(),ETH:"FkvCG5DcuYCQ1BnPH4ZzTkCdk3VzutgyDAFBec4qAjhh",USDC:"BoYN2f2gLQS4jpvMSV9dAZwfzKJiKGk4NPck5BjXfujo",USDT:"J87bysZjwfS3n6KR21cwbdPZVJWNSFcXpWF5kiChAwQH"},WSOL_DECIMALS:9}},wt=o=>gm[o];function Ht(o){let e=wt(o);return{chainId:101,address:wm.default.toBase58(),programId:Ua.toBase58(),decimals:9,symbol:e.NATIVE_TOKEN_SYMBOL,name:e.FULL_TOKEN_NAME,logoURI:e.GITHUB_LOGO_URL,tags:[],priority:2,type:"cobaltx",extensions:{coingeckoId:"solana"}}}function Te(o){let e=wt(o);return{chainId:101,address:e.WSOL_MINT_ADDRESS,programId:Ua.toBase58(),decimals:9,symbol:e.WRAPPED_TOKEN_SYMBOL||"",name:e.FULL_TOKEN_NAME,logoURI:e.GITHUB_LOGO_URL,tags:[],priority:2,type:"cobaltx",extensions:{coingeckoId:"solana"}}}import{PublicKey as Xr}from"@solana/web3.js";import{TOKEN_PROGRAM_ID as Am}from"@solana/spl-token";import{PublicKey as Re,SystemProgram as Ga,SYSVAR_RENT_PUBKEY as km}from"@solana/web3.js";function w({pubkey:o,isSigner:e=!1,isWritable:t=!0}){return{pubkey:o,isWritable:t,isSigner:e}}var Wr=[w({pubkey:Am,isWritable:!1}),w({pubkey:Ga.programId,isWritable:!1}),w({pubkey:km,isWritable:!1})];function qr({publicKey:o,transformSol:e,network:t}){let n=Ur(o.toString());if(e&&t){let{WSOLMint:i}=$(t);if(n instanceof Re)return e&&n.equals($e)?i:n;if(e&&n.toString()===$e.toBase58())return i}else if(n instanceof Re)return n;if(typeof n=="string"){if(n===Re.default.toBase58())return Re.default;try{return new Re(n)}catch{throw new Error("invalid public key")}}throw new Error("invalid public key")}function Ur(o){try{return new Re(o)}catch{return o}}var Oi=new Re("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Qt=new Re("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"),Je=new Re("SysvarRent111111111111111111111111111111111"),Gr=new Re("SysvarC1ock11111111111111111111111111111111"),Jt=new Re("metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"),Ri=new Re("Sysvar1nstructions1111111111111111111111111"),Ni=Ga.programId,$e=Re.default;function $(o){let e=wt(o);return{USDCMint:new Re(e.USDC_MINT_ADDRESS),USDTMint:new Re(e.USDT_MINT_ADDRESS),WSOLMint:new Re(e.WSOL_MINT_ADDRESS),ETHMint:new Re(e.ETH_MINT_ADDRESS),BONK_Mint:e.BON