@cetusprotocol/terminal 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,7 +35,7 @@ React keys must be passed directly to JSX without using spread:
35
35
  `)}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...r){const n=new this(t);return r.forEach(i=>n.set(i)),n}static accessor(t){const n=(this[Wm]=this[Wm]={accessors:{}}).accessors,i=this.prototype;function s(o){const a=Ea(o);n[a]||(uk(i,o),n[a]=!0)}return fe.isArray(t)?t.forEach(s):s(t),this}}wl.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);fe.reduceDescriptors(wl.prototype,({value:e},t)=>{let r=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(n){this[r]=n}}});fe.freezeMethods(wl);var On=wl;function Nf(e,t){const r=this||Yp,n=t||r,i=On.from(n.headers);let s=n.data;return fe.forEach(e,function(a){s=a.call(r,s,i.normalize(),t?t.status:void 0)}),i.normalize(),s}function e4(e){return!!(e&&e.__CANCEL__)}function Zo(e,t,r){pt.call(this,e??"canceled",pt.ERR_CANCELED,t,r),this.name="CanceledError"}fe.inherits(Zo,pt,{__CANCEL__:!0});function t4(e,t,r){const n=r.config.validateStatus;!r.status||!n||n(r.status)?e(r):t(new pt("Request failed with status code "+r.status,[pt.ERR_BAD_REQUEST,pt.ERR_BAD_RESPONSE][Math.floor(r.status/100)-4],r.config,r.request,r))}function lk(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function fk(e,t){e=e||10;const r=new Array(e),n=new Array(e);let i=0,s=0,o;return t=t!==void 0?t:1e3,function(c){const u=Date.now(),l=n[s];o||(o=u),r[i]=c,n[i]=u;let f=s,h=0;for(;f!==i;)h+=r[f++],f=f%e;if(i=(i+1)%e,i===s&&(s=(s+1)%e),u-o<t)return;const y=l&&u-l;return y?Math.round(h*1e3/y):void 0}}function dk(e,t){let r=0,n=1e3/t,i,s;const o=(u,l=Date.now())=>{r=l,i=null,s&&(clearTimeout(s),s=null),e.apply(null,u)};return[(...u)=>{const l=Date.now(),f=l-r;f>=n?o(u,l):(i=u,s||(s=setTimeout(()=>{s=null,o(i)},n-f)))},()=>i&&o(i)]}const Ru=(e,t,r=3)=>{let n=0;const i=fk(50,250);return dk(s=>{const o=s.loaded,a=s.lengthComputable?s.total:void 0,c=o-n,u=i(c),l=o<=a;n=o;const f={loaded:o,total:a,progress:a?o/a:void 0,bytes:c,rate:u||void 0,estimated:u&&a&&l?(a-o)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},r)},Gm=(e,t)=>{const r=e!=null;return[n=>t[0]({lengthComputable:r,total:e,loaded:n}),t[1]]},Hm=e=>(...t)=>fe.asap(()=>e(...t));var hk=Mr.hasStandardBrowserEnv?((e,t)=>r=>(r=new URL(r,Mr.origin),e.protocol===r.protocol&&e.host===r.host&&(t||e.port===r.port)))(new URL(Mr.origin),Mr.navigator&&/(msie|trident)/i.test(Mr.navigator.userAgent)):()=>!0,pk=Mr.hasStandardBrowserEnv?{write(e,t,r,n,i,s){const o=[e+"="+encodeURIComponent(t)];fe.isNumber(r)&&o.push("expires="+new Date(r).toGMTString()),fe.isString(n)&&o.push("path="+n),fe.isString(i)&&o.push("domain="+i),s===!0&&o.push("secure"),document.cookie=o.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function mk(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function gk(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function r4(e,t){return e&&!mk(t)?gk(e,t):t}const Km=e=>e instanceof On?{...e}:e;function Ks(e,t){t=t||{};const r={};function n(u,l,f,h){return fe.isPlainObject(u)&&fe.isPlainObject(l)?fe.merge.call({caseless:h},u,l):fe.isPlainObject(l)?fe.merge({},l):fe.isArray(l)?l.slice():l}function i(u,l,f,h){if(fe.isUndefined(l)){if(!fe.isUndefined(u))return n(void 0,u,f,h)}else return n(u,l,f,h)}function s(u,l){if(!fe.isUndefined(l))return n(void 0,l)}function o(u,l){if(fe.isUndefined(l)){if(!fe.isUndefined(u))return n(void 0,u)}else return n(void 0,l)}function a(u,l,f){if(f in t)return n(u,l);if(f in e)return n(void 0,u)}const c={url:s,method:s,data:s,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:a,headers:(u,l,f)=>i(Km(u),Km(l),f,!0)};return fe.forEach(Object.keys(Object.assign({},e,t)),function(l){const f=c[l]||i,h=f(e[l],t[l],l);fe.isUndefined(h)&&f!==a||(r[l]=h)}),r}var n4=e=>{const t=Ks({},e);let{data:r,withXSRFToken:n,xsrfHeaderName:i,xsrfCookieName:s,headers:o,auth:a}=t;t.headers=o=On.from(o),t.url=Yx(r4(t.baseURL,t.url),e.params,e.paramsSerializer),a&&o.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):"")));let c;if(fe.isFormData(r)){if(Mr.hasStandardBrowserEnv||Mr.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if((c=o.getContentType())!==!1){const[u,...l]=c?c.split(";").map(f=>f.trim()).filter(Boolean):[];o.setContentType([u||"multipart/form-data",...l].join("; "))}}if(Mr.hasStandardBrowserEnv&&(n&&fe.isFunction(n)&&(n=n(t)),n||n!==!1&&hk(t.url))){const u=i&&s&&pk.read(s);u&&o.set(i,u)}return t};const vk=typeof XMLHttpRequest<"u";var yk=vk&&function(e){return new Promise(function(r,n){const i=n4(e);let s=i.data;const o=On.from(i.headers).normalize();let{responseType:a,onUploadProgress:c,onDownloadProgress:u}=i,l,f,h,y,b;function w(){y&&y(),b&&b(),i.cancelToken&&i.cancelToken.unsubscribe(l),i.signal&&i.signal.removeEventListener("abort",l)}let T=new XMLHttpRequest;T.open(i.method.toUpperCase(),i.url,!0),T.timeout=i.timeout;function P(){if(!T)return;const N=On.from("getAllResponseHeaders"in T&&T.getAllResponseHeaders()),L={data:!a||a==="text"||a==="json"?T.responseText:T.response,status:T.status,statusText:T.statusText,headers:N,config:e,request:T};t4(function(q){r(q),w()},function(q){n(q),w()},L),T=null}"onloadend"in T?T.onloadend=P:T.onreadystatechange=function(){!T||T.readyState!==4||T.status===0&&!(T.responseURL&&T.responseURL.indexOf("file:")===0)||setTimeout(P)},T.onabort=function(){T&&(n(new pt("Request aborted",pt.ECONNABORTED,e,T)),T=null)},T.onerror=function(){n(new pt("Network Error",pt.ERR_NETWORK,e,T)),T=null},T.ontimeout=function(){let F=i.timeout?"timeout of "+i.timeout+"ms exceeded":"timeout exceeded";const L=i.transitional||Zx;i.timeoutErrorMessage&&(F=i.timeoutErrorMessage),n(new pt(F,L.clarifyTimeoutError?pt.ETIMEDOUT:pt.ECONNABORTED,e,T)),T=null},s===void 0&&o.setContentType(null),"setRequestHeader"in T&&fe.forEach(o.toJSON(),function(F,L){T.setRequestHeader(L,F)}),fe.isUndefined(i.withCredentials)||(T.withCredentials=!!i.withCredentials),a&&a!=="json"&&(T.responseType=i.responseType),u&&([h,b]=Ru(u,!0),T.addEventListener("progress",h)),c&&T.upload&&([f,y]=Ru(c),T.upload.addEventListener("progress",f),T.upload.addEventListener("loadend",y)),(i.cancelToken||i.signal)&&(l=N=>{T&&(n(!N||N.type?new Zo(null,e,T):N),T.abort(),T=null)},i.cancelToken&&i.cancelToken.subscribe(l),i.signal&&(i.signal.aborted?l():i.signal.addEventListener("abort",l)));const k=lk(i.url);if(k&&Mr.protocols.indexOf(k)===-1){n(new pt("Unsupported protocol "+k+":",pt.ERR_BAD_REQUEST,e));return}T.send(s||null)})};const bk=(e,t)=>{const{length:r}=e=e?e.filter(Boolean):[];if(t||r){let n=new AbortController,i;const s=function(u){if(!i){i=!0,a();const l=u instanceof Error?u:this.reason;n.abort(l instanceof pt?l:new Zo(l instanceof Error?l.message:l))}};let o=t&&setTimeout(()=>{o=null,s(new pt(`timeout ${t} of ms exceeded`,pt.ETIMEDOUT))},t);const a=()=>{e&&(o&&clearTimeout(o),o=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:c}=n;return c.unsubscribe=()=>fe.asap(a),c}};var wk=bk;const _k=function*(e,t){let r=e.byteLength;if(!t||r<t){yield e;return}let n=0,i;for(;n<r;)i=n+t,yield e.slice(n,i),n=i},xk=async function*(e,t){for await(const r of Sk(e))yield*_k(r,t)},Sk=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:r,value:n}=await t.read();if(r)break;yield n}}finally{await t.cancel()}},Xm=(e,t,r,n)=>{const i=xk(e,t);let s=0,o,a=c=>{o||(o=!0,n&&n(c))};return new ReadableStream({async pull(c){try{const{done:u,value:l}=await i.next();if(u){a(),c.close();return}let f=l.byteLength;if(r){let h=s+=f;r(h)}c.enqueue(new Uint8Array(l))}catch(u){throw a(u),u}},cancel(c){return a(c),i.return()}},{highWaterMark:2})},_l=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",i4=_l&&typeof ReadableStream=="function",Ek=_l&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),s4=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Ck=i4&&s4(()=>{let e=!1;const t=new Request(Mr.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),Jm=64*1024,Kd=i4&&s4(()=>fe.isReadableStream(new Response("").body)),Nu={stream:Kd&&(e=>e.body)};_l&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!Nu[t]&&(Nu[t]=fe.isFunction(e[t])?r=>r[t]():(r,n)=>{throw new pt(`Response type '${t}' is not supported`,pt.ERR_NOT_SUPPORT,n)})})})(new Response);const Mk=async e=>{if(e==null)return 0;if(fe.isBlob(e))return e.size;if(fe.isSpecCompliantForm(e))return(await new Request(Mr.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(fe.isArrayBufferView(e)||fe.isArrayBuffer(e))return e.byteLength;if(fe.isURLSearchParams(e)&&(e=e+""),fe.isString(e))return(await Ek(e)).byteLength},Ak=async(e,t)=>{const r=fe.toFiniteNumber(e.getContentLength());return r??Mk(t)};var Tk=_l&&(async e=>{let{url:t,method:r,data:n,signal:i,cancelToken:s,timeout:o,onDownloadProgress:a,onUploadProgress:c,responseType:u,headers:l,withCredentials:f="same-origin",fetchOptions:h}=n4(e);u=u?(u+"").toLowerCase():"text";let y=wk([i,s&&s.toAbortSignal()],o),b;const w=y&&y.unsubscribe&&(()=>{y.unsubscribe()});let T;try{if(c&&Ck&&r!=="get"&&r!=="head"&&(T=await Ak(l,n))!==0){let L=new Request(t,{method:"POST",body:n,duplex:"half"}),G;if(fe.isFormData(n)&&(G=L.headers.get("content-type"))&&l.setContentType(G),L.body){const[q,X]=Gm(T,Ru(Hm(c)));n=Xm(L.body,Jm,q,X)}}fe.isString(f)||(f=f?"include":"omit");const P="credentials"in Request.prototype;b=new Request(t,{...h,signal:y,method:r.toUpperCase(),headers:l.normalize().toJSON(),body:n,duplex:"half",credentials:P?f:void 0});let k=await fetch(b);const N=Kd&&(u==="stream"||u==="response");if(Kd&&(a||N&&w)){const L={};["status","statusText","headers"].forEach(ne=>{L[ne]=k[ne]});const G=fe.toFiniteNumber(k.headers.get("content-length")),[q,X]=a&&Gm(G,Ru(Hm(a),!0))||[];k=new Response(Xm(k.body,Jm,q,()=>{X&&X(),w&&w()}),L)}u=u||"text";let F=await Nu[fe.findKey(Nu,u)||"text"](k,e);return!N&&w&&w(),await new Promise((L,G)=>{t4(L,G,{data:F,headers:On.from(k.headers),status:k.status,statusText:k.statusText,config:e,request:b})})}catch(P){throw w&&w(),P&&P.name==="TypeError"&&/fetch/i.test(P.message)?Object.assign(new pt("Network Error",pt.ERR_NETWORK,e,b),{cause:P.cause||P}):pt.from(P,P&&P.code,e,b)}});const Xd={http:Uj,xhr:yk,fetch:Tk};fe.forEach(Xd,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Ym=e=>`- ${e}`,Ok=e=>fe.isFunction(e)||e===null||e===!1;var o4={getAdapter:e=>{e=fe.isArray(e)?e:[e];const{length:t}=e;let r,n;const i={};for(let s=0;s<t;s++){r=e[s];let o;if(n=r,!Ok(r)&&(n=Xd[(o=String(r)).toLowerCase()],n===void 0))throw new pt(`Unknown adapter '${o}'`);if(n)break;i[o||"#"+s]=n}if(!n){const s=Object.entries(i).map(([a,c])=>`adapter ${a} `+(c===!1?"is not supported by the environment":"is not available in the build"));let o=t?s.length>1?`since :
36
36
  `+s.map(Ym).join(`
37
37
  `):" "+Ym(s[0]):"as no adapter specified";throw new pt("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return n},adapters:Xd};function Df(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Zo(null,e)}function Zm(e){return Df(e),e.headers=On.from(e.headers),e.data=Nf.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),o4.getAdapter(e.adapter||Yp.adapter)(e).then(function(n){return Df(e),n.data=Nf.call(e,e.transformResponse,n),n.headers=On.from(n.headers),n},function(n){return e4(n)||(Df(e),n&&n.response&&(n.response.data=Nf.call(e,e.transformResponse,n.response),n.response.headers=On.from(n.response.headers))),Promise.reject(n)})}const a4="1.7.9",xl={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{xl[e]=function(n){return typeof n===e||"a"+(t<1?"n ":" ")+e}});const Qm={};xl.transitional=function(t,r,n){function i(s,o){return"[Axios v"+a4+"] Transitional option '"+s+"'"+o+(n?". "+n:"")}return(s,o,a)=>{if(t===!1)throw new pt(i(o," has been removed"+(r?" in "+r:"")),pt.ERR_DEPRECATED);return r&&!Qm[o]&&(Qm[o]=!0,console.warn(i(o," has been deprecated since v"+r+" and will be removed in the near future"))),t?t(s,o,a):!0}};xl.spelling=function(t){return(r,n)=>(console.warn(`${n} is likely a misspelling of ${t}`),!0)};function Ik(e,t,r){if(typeof e!="object")throw new pt("options must be an object",pt.ERR_BAD_OPTION_VALUE);const n=Object.keys(e);let i=n.length;for(;i-- >0;){const s=n[i],o=t[s];if(o){const a=e[s],c=a===void 0||o(a,s,e);if(c!==!0)throw new pt("option "+s+" must be "+c,pt.ERR_BAD_OPTION_VALUE);continue}if(r!==!0)throw new pt("Unknown option "+s,pt.ERR_BAD_OPTION)}}var cu={assertOptions:Ik,validators:xl};const zn=cu.validators;class Du{constructor(t){this.defaults=t,this.interceptors={request:new qm,response:new qm}}async request(t,r){try{return await this._request(t,r)}catch(n){if(n instanceof Error){let i={};Error.captureStackTrace?Error.captureStackTrace(i):i=new Error;const s=i.stack?i.stack.replace(/^.+\n/,""):"";try{n.stack?s&&!String(n.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(n.stack+=`
38
- `+s):n.stack=s}catch{}}throw n}}_request(t,r){typeof t=="string"?(r=r||{},r.url=t):r=t||{},r=Ks(this.defaults,r);const{transitional:n,paramsSerializer:i,headers:s}=r;n!==void 0&&cu.assertOptions(n,{silentJSONParsing:zn.transitional(zn.boolean),forcedJSONParsing:zn.transitional(zn.boolean),clarifyTimeoutError:zn.transitional(zn.boolean)},!1),i!=null&&(fe.isFunction(i)?r.paramsSerializer={serialize:i}:cu.assertOptions(i,{encode:zn.function,serialize:zn.function},!0)),cu.assertOptions(r,{baseUrl:zn.spelling("baseURL"),withXsrfToken:zn.spelling("withXSRFToken")},!0),r.method=(r.method||this.defaults.method||"get").toLowerCase();let o=s&&fe.merge(s.common,s[r.method]);s&&fe.forEach(["delete","get","head","post","put","patch","common"],b=>{delete s[b]}),r.headers=On.concat(o,s);const a=[];let c=!0;this.interceptors.request.forEach(function(w){typeof w.runWhen=="function"&&w.runWhen(r)===!1||(c=c&&w.synchronous,a.unshift(w.fulfilled,w.rejected))});const u=[];this.interceptors.response.forEach(function(w){u.push(w.fulfilled,w.rejected)});let l,f=0,h;if(!c){const b=[Zm.bind(this),void 0];for(b.unshift.apply(b,a),b.push.apply(b,u),h=b.length,l=Promise.resolve(r);f<h;)l=l.then(b[f++],b[f++]);return l}h=a.length;let y=r;for(f=0;f<h;){const b=a[f++],w=a[f++];try{y=b(y)}catch(T){w.call(this,T);break}}try{l=Zm.call(this,y)}catch(b){return Promise.reject(b)}for(f=0,h=u.length;f<h;)l=l.then(u[f++],u[f++]);return l}getUri(t){t=Ks(this.defaults,t);const r=r4(t.baseURL,t.url);return Yx(r,t.params,t.paramsSerializer)}}fe.forEach(["delete","get","head","options"],function(t){Du.prototype[t]=function(r,n){return this.request(Ks(n||{},{method:t,url:r,data:(n||{}).data}))}});fe.forEach(["post","put","patch"],function(t){function r(n){return function(s,o,a){return this.request(Ks(a||{},{method:t,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Du.prototype[t]=r(),Du.prototype[t+"Form"]=r(!0)});var uu=Du;class Zp{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let r;this.promise=new Promise(function(s){r=s});const n=this;this.promise.then(i=>{if(!n._listeners)return;let s=n._listeners.length;for(;s-- >0;)n._listeners[s](i);n._listeners=null}),this.promise.then=i=>{let s;const o=new Promise(a=>{n.subscribe(a),s=a}).then(i);return o.cancel=function(){n.unsubscribe(s)},o},t(function(s,o,a){n.reason||(n.reason=new Zo(s,o,a),r(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const r=this._listeners.indexOf(t);r!==-1&&this._listeners.splice(r,1)}toAbortSignal(){const t=new AbortController,r=n=>{t.abort(n)};return this.subscribe(r),t.signal.unsubscribe=()=>this.unsubscribe(r),t.signal}static source(){let t;return{token:new Zp(function(i){t=i}),cancel:t}}}var Pk=Zp;function jk(e){return function(r){return e.apply(null,r)}}function kk(e){return fe.isObject(e)&&e.isAxiosError===!0}const Jd={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Jd).forEach(([e,t])=>{Jd[t]=e});var Rk=Jd;function c4(e){const t=new uu(e),r=Lx(uu.prototype.request,t);return fe.extend(r,uu.prototype,t,{allOwnKeys:!0}),fe.extend(r,t,null,{allOwnKeys:!0}),r.create=function(i){return c4(Ks(e,i))},r}const ur=c4(Yp);ur.Axios=uu;ur.CanceledError=Zo;ur.CancelToken=Pk;ur.isCancel=e4;ur.VERSION=a4;ur.toFormData=bl;ur.AxiosError=pt;ur.Cancel=ur.CanceledError;ur.all=function(t){return Promise.all(t)};ur.spread=jk;ur.isAxiosError=kk;ur.mergeConfig=Ks;ur.AxiosHeaders=On;ur.formToJSON=e=>Qx(fe.isHTMLForm(e)?new FormData(e):e);ur.getAdapter=o4.getAdapter;ur.HttpStatusCode=Rk;ur.default=ur;var u4=ur,Qp={exports:{}},Zr={},l4={exports:{}};(function(e){function t(r){return r&&r.__esModule?r:{default:r}}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports})(l4);var Nk=l4.exports,$f={exports:{}},Bf={exports:{}},eg;function Sl(){return eg||(eg=1,function(e){function t(r){"@babel/helpers - typeof";return e.exports=t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(Bf)),Bf.exports}var tg;function Dk(){return tg||(tg=1,function(e){var t=Sl().default;function r(){e.exports=r=function(){return i},e.exports.__esModule=!0,e.exports.default=e.exports;var n,i={},s=Object.prototype,o=s.hasOwnProperty,a=Object.defineProperty||function(E,O,C){E[O]=C.value},c=typeof Symbol=="function"?Symbol:{},u=c.iterator||"@@iterator",l=c.asyncIterator||"@@asyncIterator",f=c.toStringTag||"@@toStringTag";function h(E,O,C){return Object.defineProperty(E,O,{value:C,enumerable:!0,configurable:!0,writable:!0}),E[O]}try{h({},"")}catch{h=function(C,g,v){return C[g]=v}}function y(E,O,C,g){var v=O&&O.prototype instanceof F?O:F,j=Object.create(v.prototype),ee=new x(g||[]);return a(j,"_invoke",{value:D(E,C,ee)}),j}function b(E,O,C){try{return{type:"normal",arg:E.call(O,C)}}catch(g){return{type:"throw",arg:g}}}i.wrap=y;var w="suspendedStart",T="suspendedYield",P="executing",k="completed",N={};function F(){}function L(){}function G(){}var q={};h(q,u,function(){return this});var X=Object.getPrototypeOf,ne=X&&X(X(M([])));ne&&ne!==s&&o.call(ne,u)&&(q=ne);var ae=G.prototype=F.prototype=Object.create(q);function ce(E){["next","throw","return"].forEach(function(O){h(E,O,function(C){return this._invoke(O,C)})})}function V(E,O){function C(v,j,ee,ie){var de=b(E[v],E,j);if(de.type!=="throw"){var ye=de.arg,Ee=ye.value;return Ee&&t(Ee)=="object"&&o.call(Ee,"__await")?O.resolve(Ee.__await).then(function(Se){C("next",Se,ee,ie)},function(Se){C("throw",Se,ee,ie)}):O.resolve(Ee).then(function(Se){ye.value=Se,ee(ye)},function(Se){return C("throw",Se,ee,ie)})}ie(de.arg)}var g;a(this,"_invoke",{value:function(j,ee){function ie(){return new O(function(de,ye){C(j,ee,de,ye)})}return g=g?g.then(ie,ie):ie()}})}function D(E,O,C){var g=w;return function(v,j){if(g===P)throw Error("Generator is already running");if(g===k){if(v==="throw")throw j;return{value:n,done:!0}}for(C.method=v,C.arg=j;;){var ee=C.delegate;if(ee){var ie=p(ee,C);if(ie){if(ie===N)continue;return ie}}if(C.method==="next")C.sent=C._sent=C.arg;else if(C.method==="throw"){if(g===w)throw g=k,C.arg;C.dispatchException(C.arg)}else C.method==="return"&&C.abrupt("return",C.arg);g=P;var de=b(E,O,C);if(de.type==="normal"){if(g=C.done?k:T,de.arg===N)continue;return{value:de.arg,done:C.done}}de.type==="throw"&&(g=k,C.method="throw",C.arg=de.arg)}}}function p(E,O){var C=O.method,g=E.iterator[C];if(g===n)return O.delegate=null,C==="throw"&&E.iterator.return&&(O.method="return",O.arg=n,p(E,O),O.method==="throw")||C!=="return"&&(O.method="throw",O.arg=new TypeError("The iterator does not provide a '"+C+"' method")),N;var v=b(g,E.iterator,O.arg);if(v.type==="throw")return O.method="throw",O.arg=v.arg,O.delegate=null,N;var j=v.arg;return j?j.done?(O[E.resultName]=j.value,O.next=E.nextLoc,O.method!=="return"&&(O.method="next",O.arg=n),O.delegate=null,N):j:(O.method="throw",O.arg=new TypeError("iterator result is not an object"),O.delegate=null,N)}function d(E){var O={tryLoc:E[0]};1 in E&&(O.catchLoc=E[1]),2 in E&&(O.finallyLoc=E[2],O.afterLoc=E[3]),this.tryEntries.push(O)}function m(E){var O=E.completion||{};O.type="normal",delete O.arg,E.completion=O}function x(E){this.tryEntries=[{tryLoc:"root"}],E.forEach(d,this),this.reset(!0)}function M(E){if(E||E===""){var O=E[u];if(O)return O.call(E);if(typeof E.next=="function")return E;if(!isNaN(E.length)){var C=-1,g=function v(){for(;++C<E.length;)if(o.call(E,C))return v.value=E[C],v.done=!1,v;return v.value=n,v.done=!0,v};return g.next=g}}throw new TypeError(t(E)+" is not iterable")}return L.prototype=G,a(ae,"constructor",{value:G,configurable:!0}),a(G,"constructor",{value:L,configurable:!0}),L.displayName=h(G,f,"GeneratorFunction"),i.isGeneratorFunction=function(E){var O=typeof E=="function"&&E.constructor;return!!O&&(O===L||(O.displayName||O.name)==="GeneratorFunction")},i.mark=function(E){return Object.setPrototypeOf?Object.setPrototypeOf(E,G):(E.__proto__=G,h(E,f,"GeneratorFunction")),E.prototype=Object.create(ae),E},i.awrap=function(E){return{__await:E}},ce(V.prototype),h(V.prototype,l,function(){return this}),i.AsyncIterator=V,i.async=function(E,O,C,g,v){v===void 0&&(v=Promise);var j=new V(y(E,O,C,g),v);return i.isGeneratorFunction(O)?j:j.next().then(function(ee){return ee.done?ee.value:j.next()})},ce(ae),h(ae,f,"Generator"),h(ae,u,function(){return this}),h(ae,"toString",function(){return"[object Generator]"}),i.keys=function(E){var O=Object(E),C=[];for(var g in O)C.push(g);return C.reverse(),function v(){for(;C.length;){var j=C.pop();if(j in O)return v.value=j,v.done=!1,v}return v.done=!0,v}},i.values=M,x.prototype={constructor:x,reset:function(O){if(this.prev=0,this.next=0,this.sent=this._sent=n,this.done=!1,this.delegate=null,this.method="next",this.arg=n,this.tryEntries.forEach(m),!O)for(var C in this)C.charAt(0)==="t"&&o.call(this,C)&&!isNaN(+C.slice(1))&&(this[C]=n)},stop:function(){this.done=!0;var O=this.tryEntries[0].completion;if(O.type==="throw")throw O.arg;return this.rval},dispatchException:function(O){if(this.done)throw O;var C=this;function g(ye,Ee){return ee.type="throw",ee.arg=O,C.next=ye,Ee&&(C.method="next",C.arg=n),!!Ee}for(var v=this.tryEntries.length-1;v>=0;--v){var j=this.tryEntries[v],ee=j.completion;if(j.tryLoc==="root")return g("end");if(j.tryLoc<=this.prev){var ie=o.call(j,"catchLoc"),de=o.call(j,"finallyLoc");if(ie&&de){if(this.prev<j.catchLoc)return g(j.catchLoc,!0);if(this.prev<j.finallyLoc)return g(j.finallyLoc)}else if(ie){if(this.prev<j.catchLoc)return g(j.catchLoc,!0)}else{if(!de)throw Error("try statement without catch or finally");if(this.prev<j.finallyLoc)return g(j.finallyLoc)}}}},abrupt:function(O,C){for(var g=this.tryEntries.length-1;g>=0;--g){var v=this.tryEntries[g];if(v.tryLoc<=this.prev&&o.call(v,"finallyLoc")&&this.prev<v.finallyLoc){var j=v;break}}j&&(O==="break"||O==="continue")&&j.tryLoc<=C&&C<=j.finallyLoc&&(j=null);var ee=j?j.completion:{};return ee.type=O,ee.arg=C,j?(this.method="next",this.next=j.finallyLoc,N):this.complete(ee)},complete:function(O,C){if(O.type==="throw")throw O.arg;return O.type==="break"||O.type==="continue"?this.next=O.arg:O.type==="return"?(this.rval=this.arg=O.arg,this.method="return",this.next="end"):O.type==="normal"&&C&&(this.next=C),N},finish:function(O){for(var C=this.tryEntries.length-1;C>=0;--C){var g=this.tryEntries[C];if(g.finallyLoc===O)return this.complete(g.completion,g.afterLoc),m(g),N}},catch:function(O){for(var C=this.tryEntries.length-1;C>=0;--C){var g=this.tryEntries[C];if(g.tryLoc===O){var v=g.completion;if(v.type==="throw"){var j=v.arg;m(g)}return j}}throw Error("illegal catch attempt")},delegateYield:function(O,C,g){return this.delegate={iterator:M(O),resultName:C,nextLoc:g},this.method==="next"&&(this.arg=n),N}},i}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}($f)),$f.exports}var Lf,rg;function $k(){if(rg)return Lf;rg=1;var e=Dk()();Lf=e;try{regeneratorRuntime=e}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}return Lf}var Ff={exports:{}},ng;function Bk(){return ng||(ng=1,function(e){function t(n,i,s,o,a,c,u){try{var l=n[c](u),f=l.value}catch(h){return void s(h)}l.done?i(f):Promise.resolve(f).then(o,a)}function r(n){return function(){var i=this,s=arguments;return new Promise(function(o,a){var c=n.apply(i,s);function u(f){t(c,o,a,u,l,"next",f)}function l(f){t(c,o,a,u,l,"throw",f)}u(void 0)})}}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(Ff)),Ff.exports}var Uf={exports:{}},zf={exports:{}},Vf={exports:{}},ig;function Lk(){return ig||(ig=1,function(e){var t=Sl().default;function r(n,i){if(t(n)!="object"||!n)return n;var s=n[Symbol.toPrimitive];if(s!==void 0){var o=s.call(n,i||"default");if(t(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(i==="string"?String:Number)(n)}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(Vf)),Vf.exports}var sg;function Fk(){return sg||(sg=1,function(e){var t=Sl().default,r=Lk();function n(i){var s=r(i,"string");return t(s)=="symbol"?s:s+""}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}(zf)),zf.exports}var og;function Uk(){return og||(og=1,function(e){var t=Fk();function r(n,i,s){return(i=t(i))in n?Object.defineProperty(n,i,{value:s,enumerable:!0,configurable:!0,writable:!0}):n[i]=s,n}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(Uf)),Uf.exports}var qf,ag;function zk(){if(ag)return qf;ag=1;const e=new Set(["ENOTFOUND","ENETUNREACH","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_CRL","UNABLE_TO_DECRYPT_CERT_SIGNATURE","UNABLE_TO_DECRYPT_CRL_SIGNATURE","UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY","CERT_SIGNATURE_FAILURE","CRL_SIGNATURE_FAILURE","CERT_NOT_YET_VALID","CERT_HAS_EXPIRED","CRL_NOT_YET_VALID","CRL_HAS_EXPIRED","ERROR_IN_CERT_NOT_BEFORE_FIELD","ERROR_IN_CERT_NOT_AFTER_FIELD","ERROR_IN_CRL_LAST_UPDATE_FIELD","ERROR_IN_CRL_NEXT_UPDATE_FIELD","OUT_OF_MEM","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","CERT_CHAIN_TOO_LONG","CERT_REVOKED","INVALID_CA","PATH_LENGTH_EXCEEDED","INVALID_PURPOSE","CERT_UNTRUSTED","CERT_REJECTED","HOSTNAME_MISMATCH"]);return qf=t=>!e.has(t&&t.code),qf}var xc=Nk;Object.defineProperty(Zr,"__esModule",{value:!0});Zr.isNetworkError=t0;Zr.isRetryableError=El;Zr.isSafeRequestError=h4;Zr.isIdempotentRequestError=r0;Zr.isNetworkOrIdempotentRequestError=n0;Zr.exponentialDelay=p4;Zr.default=Qs;Zr.DEFAULT_OPTIONS=Zr.namespace=void 0;var $u=xc($k()),Vk=xc(Sl()),f4=xc(Bk()),qk=xc(Uk()),Wk=xc(zk());function cg(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function Wf(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?cg(Object(r),!0).forEach(function(n){(0,qk.default)(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):cg(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}var e0="axios-retry";Zr.namespace=e0;function t0(e){var t=["ERR_CANCELED","ECONNABORTED"];return!e.response&&!!e.code&&!t.includes(e.code)&&(0,Wk.default)(e)}var d4=["get","head","options"],Gk=d4.concat(["put","delete"]);function El(e){return e.code!=="ECONNABORTED"&&(!e.response||e.response.status>=500&&e.response.status<=599)}function h4(e){return e.config?El(e)&&d4.indexOf(e.config.method)!==-1:!1}function r0(e){return e.config?El(e)&&Gk.indexOf(e.config.method)!==-1:!1}function n0(e){return t0(e)||r0(e)}function Hk(){return 0}function p4(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:100,r=Math.pow(2,e)*t,n=r*.2*Math.random();return r+n}var m4={retries:3,retryCondition:n0,retryDelay:Hk,shouldResetTimeout:!1,onRetry:function(){}};Zr.DEFAULT_OPTIONS=m4;function Kk(e,t){return Wf(Wf(Wf({},m4),t),e[e0])}function ug(e,t){var r=Kk(e,t);return r.retryCount=r.retryCount||0,e[e0]=r,r}function Xk(e,t){e.defaults.agent===t.agent&&delete t.agent,e.defaults.httpAgent===t.httpAgent&&delete t.httpAgent,e.defaults.httpsAgent===t.httpsAgent&&delete t.httpsAgent}function Jk(e,t){return Yd.apply(this,arguments)}function Yd(){return Yd=(0,f4.default)($u.default.mark(function e(t,r){var n,i,s,o;return $u.default.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(n=t.retries,i=t.retryCondition,s=t.retryCount<n&&i(r),(0,Vk.default)(s)!=="object"){c.next=13;break}return c.prev=3,c.next=6,s;case 6:return o=c.sent,c.abrupt("return",o!==!1);case 10:return c.prev=10,c.t0=c.catch(3),c.abrupt("return",!1);case 13:return c.abrupt("return",s);case 14:case"end":return c.stop()}},e,null,[[3,10]])})),Yd.apply(this,arguments)}function Qs(e,t){var r=e.interceptors.request.use(function(i){var s=ug(i,t);return s.lastRequestTime=Date.now(),i}),n=e.interceptors.response.use(null,function(){var i=(0,f4.default)($u.default.mark(function s(o){var a,c,u,l,f,h,y,b;return $u.default.wrap(function(T){for(;;)switch(T.prev=T.next){case 0:if(a=o.config,a){T.next=3;break}return T.abrupt("return",Promise.reject(o));case 3:return c=ug(a,t),T.next=6,Jk(c,o);case 6:if(!T.sent){T.next=21;break}if(c.retryCount+=1,u=c.retryDelay,l=c.shouldResetTimeout,f=c.onRetry,h=u(c.retryCount,o),Xk(e,a),!(!l&&a.timeout&&c.lastRequestTime)){T.next=17;break}if(y=Date.now()-c.lastRequestTime,b=a.timeout-y-h,!(b<=0)){T.next=16;break}return T.abrupt("return",Promise.reject(o));case 16:a.timeout=b;case 17:return a.transformRequest=[function(P){return P}],T.next=20,f(c.retryCount,o,a);case 20:return T.abrupt("return",new Promise(function(P){return setTimeout(function(){return P(e(a))},h)}));case 21:return T.abrupt("return",Promise.reject(o));case 22:case"end":return T.stop()}},s)}));return function(s){return i.apply(this,arguments)}}());return{requestInterceptorId:r,responseInterceptorId:n}}Qs.isNetworkError=t0;Qs.isSafeRequestError=h4;Qs.isIdempotentRequestError=r0;Qs.isNetworkOrIdempotentRequestError=n0;Qs.exponentialDelay=p4;Qs.isRetryableError=El;const g4=Zr.default;Qp.exports=g4;Qp.exports.default=g4;var Yk=Qp.exports,Cl={},wo=null;typeof WebSocket<"u"?wo=WebSocket:typeof MozWebSocket<"u"?wo=MozWebSocket:typeof Dr<"u"?wo=Dr.WebSocket||Dr.MozWebSocket:typeof window<"u"?wo=window.WebSocket||window.MozWebSocket:typeof self<"u"&&(wo=self.WebSocket||self.MozWebSocket);var Zk=wo,Qk=Dr&&Dr.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Cl,"__esModule",{value:!0});Cl.ResilientWebSocket=void 0;const e9=Qk(Zk),t9=3e4+3e3;class r9{constructor(t,r){vt(this,"endpoint");vt(this,"wsClient");vt(this,"wsUserClosed");vt(this,"wsFailedAttempts");vt(this,"pingTimeout");vt(this,"logger");vt(this,"onError");vt(this,"onMessage");vt(this,"onReconnect");this.endpoint=t,this.logger=r,this.wsFailedAttempts=0,this.onError=n=>{var i;(i=this.logger)==null||i.error(n)},this.wsUserClosed=!0,this.onMessage=()=>{},this.onReconnect=()=>{}}async send(t){var r,n,i;(r=this.logger)==null||r.info(`Sending ${t}`),await this.waitForMaybeReadyWebSocket(),this.wsClient===void 0?(n=this.logger)==null||n.error("Couldn't connect to the websocket server. Error callback is called."):(i=this.wsClient)==null||i.send(t)}async startWebSocket(){var t;this.wsClient===void 0&&((t=this.logger)==null||t.info("Creating Web Socket client"),this.wsClient=new e9.default(this.endpoint),this.wsUserClosed=!1,this.wsClient.onopen=()=>{this.wsFailedAttempts=0,this.wsClient.on!==void 0&&this.heartbeat()},this.wsClient.onerror=r=>{this.onError(r.error)},this.wsClient.onmessage=r=>{this.onMessage(r.data)},this.wsClient.onclose=async()=>{var r,n;if(this.pingTimeout!==void 0&&clearInterval(this.pingTimeout),this.wsUserClosed===!1){this.wsFailedAttempts+=1,this.wsClient=void 0;const i=n9(this.wsFailedAttempts);(r=this.logger)==null||r.error(`Connection closed unexpectedly or because of timeout. Reconnecting after ${i}ms.`),await lg(i),this.restartUnexpectedClosedWebsocket()}else(n=this.logger)==null||n.info("The connection has been closed successfully.")},this.wsClient.on!==void 0&&this.wsClient.on("ping",this.heartbeat.bind(this)))}heartbeat(){var t;(t=this.logger)==null||t.info("Heartbeat"),this.pingTimeout!==void 0&&clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{var r,n;(r=this.logger)==null||r.warn("Connection timed out. Reconnecting..."),(n=this.wsClient)==null||n.terminate(),this.restartUnexpectedClosedWebsocket()},t9)}async waitForMaybeReadyWebSocket(){let t=0;for(;this.wsClient!==void 0&&this.wsClient.readyState!==this.wsClient.OPEN;)if(t>5e3){this.wsClient.close();return}else t+=10,await lg(10)}async restartUnexpectedClosedWebsocket(){var t;if(this.wsUserClosed!==!0){if(await this.startWebSocket(),await this.waitForMaybeReadyWebSocket(),this.wsClient===void 0){(t=this.logger)==null||t.error("Couldn't reconnect to websocket. Error callback is called.");return}this.onReconnect()}}closeWebSocket(){if(this.wsClient!==void 0){const t=this.wsClient;this.wsClient=void 0,t.close()}this.wsUserClosed=!0}}Cl.ResilientWebSocket=r9;async function lg(e){return new Promise(t=>setTimeout(t,e))}function n9(e){return 2**e*100}var Bo={};Object.defineProperty(Bo,"__esModule",{value:!0});Bo.removeLeading0xIfExists=Bo.makeWebsocketUrl=void 0;function i9(e){const t=new URL("ws",e),r=t.protocol==="https:";return t.protocol=r?"wss:":"ws:",t.toString()}Bo.makeWebsocketUrl=i9;function s9(e){return e.startsWith("0x")?e.substring(2):e}Bo.removeLeading0xIfExists=s9;var v4=Dr&&Dr.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(hl,"__esModule",{value:!0});hl.PriceServiceConnection=void 0;const Gf=qp,o9=v4(u4),fg=v4(Yk),a9=Cl,Hf=Bo;class c9{constructor(t,r){vt(this,"httpClient");vt(this,"priceFeedCallbacks");vt(this,"wsClient");vt(this,"wsEndpoint");vt(this,"logger");vt(this,"priceFeedRequestConfig");vt(this,"onWsError");var n,i,s;this.httpClient=o9.default.create({baseURL:t,timeout:(r==null?void 0:r.timeout)||5e3}),(0,fg.default)(this.httpClient,{retries:(r==null?void 0:r.httpRetries)||3,retryDelay:fg.default.exponentialDelay}),this.priceFeedRequestConfig={binary:(n=r==null?void 0:r.priceFeedRequestConfig)==null?void 0:n.binary,verbose:((i=r==null?void 0:r.priceFeedRequestConfig)==null?void 0:i.verbose)??(r==null?void 0:r.verbose),allowOutOfOrder:(s=r==null?void 0:r.priceFeedRequestConfig)==null?void 0:s.allowOutOfOrder},this.priceFeedCallbacks=new Map,this.logger=(r==null?void 0:r.logger)||{trace:()=>{},debug:()=>{},info:()=>{},warn:console.warn,error:console.error},this.onWsError=o=>{this.logger.error(o),typeof Tn<"u"&&typeof Tn.exit=="function"?(this.logger.error("Halting the process due to the websocket error"),Tn.exit(1)):this.logger.error("Cannot halt process. Please handle the websocket error.")},this.wsEndpoint=(0,Hf.makeWebsocketUrl)(t)}async getLatestPriceFeeds(t){return t.length===0?[]:(await this.httpClient.get("/api/latest_price_feeds",{params:{ids:t,verbose:this.priceFeedRequestConfig.verbose,binary:this.priceFeedRequestConfig.binary}})).data.map(i=>Gf.PriceFeed.fromJson(i))}async getLatestVaas(t){return(await this.httpClient.get("/api/latest_vaas",{params:{ids:t}})).data}async getVaa(t,r){const n=await this.httpClient.get("/api/get_vaa",{params:{id:t,publish_time:r}});return[n.data.vaa,n.data.publishTime]}async getPriceFeed(t,r){const n=await this.httpClient.get("/api/get_price_feed",{params:{id:t,publish_time:r,verbose:this.priceFeedRequestConfig.verbose,binary:this.priceFeedRequestConfig.binary}});return Gf.PriceFeed.fromJson(n.data)}async getPriceFeedIds(){return(await this.httpClient.get("/api/price_feed_ids")).data}async subscribePriceFeedUpdates(t,r){var s;this.wsClient===void 0&&await this.startWebSocket(),t=t.map(o=>(0,Hf.removeLeading0xIfExists)(o));const n=[];for(const o of t)this.priceFeedCallbacks.has(o)||(this.priceFeedCallbacks.set(o,new Set),n.push(o)),this.priceFeedCallbacks.get(o).add(r);const i={ids:n,type:"subscribe",verbose:this.priceFeedRequestConfig.verbose,binary:this.priceFeedRequestConfig.binary,allow_out_of_order:this.priceFeedRequestConfig.allowOutOfOrder};await((s=this.wsClient)==null?void 0:s.send(JSON.stringify(i)))}async unsubscribePriceFeedUpdates(t,r){var s;this.wsClient===void 0&&await this.startWebSocket(),t=t.map(o=>(0,Hf.removeLeading0xIfExists)(o));const n=[];for(const o of t)if(this.priceFeedCallbacks.has(o)){let a=!1;r===void 0?(this.priceFeedCallbacks.delete(o),a=!0):(this.priceFeedCallbacks.get(o).delete(r),this.priceFeedCallbacks.get(o).size===0&&(this.priceFeedCallbacks.delete(o),a=!0)),a&&n.push(o)}const i={ids:n,type:"unsubscribe"};await((s=this.wsClient)==null?void 0:s.send(JSON.stringify(i))),this.priceFeedCallbacks.size===0&&this.closeWebSocket()}async startWebSocket(){if(this.wsEndpoint===void 0)throw new Error("Websocket endpoint is undefined.");this.wsClient=new a9.ResilientWebSocket(this.wsEndpoint,this.logger),this.wsClient.onError=this.onWsError,this.wsClient.onReconnect=()=>{var t;if(this.priceFeedCallbacks.size>0){const r={ids:Array.from(this.priceFeedCallbacks.keys()),type:"subscribe",verbose:this.priceFeedRequestConfig.verbose,binary:this.priceFeedRequestConfig.binary,allow_out_of_order:this.priceFeedRequestConfig.allowOutOfOrder};this.logger.info("Resubscribing to existing price feeds."),(t=this.wsClient)==null||t.send(JSON.stringify(r))}},this.wsClient.onMessage=t=>{this.logger.info(`Received message ${t.toString()}`);let r;try{r=JSON.parse(t.toString())}catch(n){this.logger.error(`Error parsing message ${t.toString()} as JSON.`),this.logger.error(n),this.onWsError(n);return}if(r.type==="response")r.status==="error"&&(this.logger.error(`Error response from the websocket server ${r.error}.`),this.onWsError(new Error(r.error)));else if(r.type==="price_update"){let n;try{n=Gf.PriceFeed.fromJson(r.price_feed)}catch(i){this.logger.error(`Error parsing price feeds from message ${t.toString()}.`),this.logger.error(i),this.onWsError(i);return}if(this.priceFeedCallbacks.has(n.id))for(const i of this.priceFeedCallbacks.get(n.id))i(n)}else this.logger.warn(`Ignoring unsupported server response ${t.toString()}.`)},await this.wsClient.startWebSocket()}closeWebSocket(){var t;(t=this.wsClient)==null||t.closeWebSocket(),this.wsClient=void 0,this.priceFeedCallbacks.clear()}}hl.PriceServiceConnection=c9;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.parseAccumulatorUpdateData=e.isAccumulatorUpdateData=e.Price=e.PriceFeed=e.PriceFeedMetadata=e.PriceServiceConnection=void 0;var t=hl;Object.defineProperty(e,"PriceServiceConnection",{enumerable:!0,get:function(){return t.PriceServiceConnection}});var r=qp;Object.defineProperty(e,"PriceFeedMetadata",{enumerable:!0,get:function(){return r.PriceFeedMetadata}}),Object.defineProperty(e,"PriceFeed",{enumerable:!0,get:function(){return r.PriceFeed}}),Object.defineProperty(e,"Price",{enumerable:!0,get:function(){return r.Price}}),Object.defineProperty(e,"isAccumulatorUpdateData",{enumerable:!0,get:function(){return r.isAccumulatorUpdateData}}),Object.defineProperty(e,"parseAccumulatorUpdateData",{enumerable:!0,get:function(){return r.parseAccumulatorUpdateData}})})(Vp);Object.defineProperty(dl,"__esModule",{value:!0});dl.SuiPriceServiceConnection=void 0;const u9=Vp,l9=ml();class f9 extends u9.PriceServiceConnection{async getPriceFeedsUpdateData(t){return(await this.getLatestVaas(t)).map(n=>l9.Buffer.from(n,"base64"))}}dl.SuiPriceServiceConnection=f9;var Ml={};Object.defineProperty(Ml,"__esModule",{value:!0});Ml.SuiPythClient=void 0;const $c=S2,oo=ai,d9=ml(),Kf=16*1024;class h9{constructor(t,r,n){vt(this,"provider");vt(this,"pythStateId");vt(this,"wormholeStateId");vt(this,"pythPackageId");vt(this,"wormholePackageId");vt(this,"priceTableInfo");vt(this,"priceFeedObjectIdCache",new Map);vt(this,"baseUpdateFee");this.provider=t,this.pythStateId=r,this.wormholeStateId=n,this.pythPackageId=void 0,this.wormholePackageId=void 0}async getBaseUpdateFee(){if(this.baseUpdateFee===void 0){const t=await this.provider.getObject({id:this.pythStateId,options:{showContent:!0}});if(!t.data||!t.data.content||t.data.content.dataType!=="moveObject")throw new Error("Unable to fetch pyth state object");this.baseUpdateFee=t.data.content.fields.base_update_fee}return this.baseUpdateFee}async getPackageId(t){const r=await this.provider.getObject({id:t,options:{showContent:!0}}).then(n=>{var i,s,o;if(((s=(i=n.data)==null?void 0:i.content)==null?void 0:s.dataType)=="moveObject")return n.data.content.fields;throw console.log((o=n.data)==null?void 0:o.content),new Error(`Cannot fetch package id for object ${t}`)});if("upgrade_cap"in r)return r.upgrade_cap.fields.package;throw new Error("upgrade_cap not found")}async verifyVaas(t,r){const n=await this.getWormholePackageId(),i=[];for(const s of t){const[o]=r.moveCall({target:`${n}::vaa::parse_and_verify`,arguments:[r.object(this.wormholeStateId),r.pure(oo.bcs.vector(oo.bcs.U8).serialize(Array.from(s),{maxSize:Kf}).toBytes()),r.object($c.SUI_CLOCK_OBJECT_ID)]});i.push(o)}return i}async updatePriceFeeds(t,r,n){const i=await this.getPythPackageId();let s;if(r.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");const o=this.extractVaaBytesFromAccumulatorMessage(r[0]),a=await this.verifyVaas([o],t);[s]=t.moveCall({target:`${i}::pyth::create_authenticated_price_infos_using_accumulator`,arguments:[t.object(this.pythStateId),t.pure(oo.bcs.vector(oo.bcs.U8).serialize(Array.from(r[0]),{maxSize:Kf}).toBytes()),a[0],t.object($c.SUI_CLOCK_OBJECT_ID)]});const c=[],u=await this.getBaseUpdateFee(),l=t.splitCoins(t.gas,n.map(()=>t.pure.u64(u)));let f=0;for(const h of n){const y=await this.getPriceFeedObjectId(h);if(!y)throw new Error(`Price feed ${h} not found, please create it first`);c.push(y),[s]=t.moveCall({target:`${i}::pyth::update_single_price_feed`,arguments:[t.object(this.pythStateId),s,t.object(y),l[f],t.object($c.SUI_CLOCK_OBJECT_ID)]}),f++}return t.moveCall({target:`${i}::hot_potato_vector::destroy`,arguments:[s],typeArguments:[`${i}::price_info::PriceInfo`]}),c}async createPriceFeed(t,r){const n=await this.getPythPackageId();if(r.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");const i=this.extractVaaBytesFromAccumulatorMessage(r[0]),s=await this.verifyVaas([i],t);t.moveCall({target:`${n}::pyth::create_price_feeds_using_accumulator`,arguments:[t.object(this.pythStateId),t.pure(oo.bcs.vector(oo.bcs.U8).serialize(Array.from(r[0]),{maxSize:Kf}).toBytes()),s[0],t.object($c.SUI_CLOCK_OBJECT_ID)]})}async getWormholePackageId(){return this.wormholePackageId||(this.wormholePackageId=await this.getPackageId(this.wormholeStateId)),this.wormholePackageId}async getPythPackageId(){return this.pythPackageId||(this.pythPackageId=await this.getPackageId(this.pythStateId)),this.pythPackageId}async getPriceFeedObjectId(t){const r=t.replace("0x","");if(!this.priceFeedObjectIdCache.has(r)){const{id:n,fieldType:i}=await this.getPriceTableInfo(),s=await this.provider.getDynamicFieldObject({parentId:n,name:{type:`${i}::price_identifier::PriceIdentifier`,value:{bytes:Array.from(d9.Buffer.from(r,"hex"))}}});if(!s.data||!s.data.content)return;if(s.data.content.dataType!=="moveObject")throw new Error("Price feed type mismatch");this.priceFeedObjectIdCache.set(r,s.data.content.fields.value)}return this.priceFeedObjectIdCache.get(r)}async getPriceTableInfo(){if(this.priceTableInfo===void 0){const t=await this.provider.getDynamicFieldObject({parentId:this.pythStateId,name:{type:"vector<u8>",value:"price_info"}});if(!t.data||!t.data.type)throw new Error("Price Table not found, contract may not be initialized");let r=t.data.type.replace("0x2::table::Table<","");r=r.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>",""),this.priceTableInfo={id:t.data.objectId,fieldType:r}}return this.priceTableInfo}extractVaaBytesFromAccumulatorMessage(t){const n=7+t.readUint8(6)+1,i=t.readUint16BE(n),s=n+2;return t.subarray(s,s+i)}}Ml.SuiPythClient=h9;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.PriceFeed=e.Price=e.SuiPythClient=e.SuiPriceServiceConnection=void 0;var t=dl;Object.defineProperty(e,"SuiPriceServiceConnection",{enumerable:!0,get:function(){return t.SuiPriceServiceConnection}});var r=Ml;Object.defineProperty(e,"SuiPythClient",{enumerable:!0,get:function(){return r.SuiPythClient}});var n=Vp;Object.defineProperty(e,"Price",{enumerable:!0,get:function(){return n.Price}}),Object.defineProperty(e,"PriceFeed",{enumerable:!0,get:function(){return n.PriceFeed}})})(Dx);var dg=PM,Zd=S2,p9=Co,Bc=Dx,m9=Object.create,i0=Object.defineProperty,g9=Object.defineProperties,v9=Object.getOwnPropertyDescriptor,y9=Object.getOwnPropertyDescriptors,y4=Object.getOwnPropertyNames,hg=Object.getOwnPropertySymbols,b9=Object.getPrototypeOf,b4=Object.prototype.hasOwnProperty,w9=Object.prototype.propertyIsEnumerable,pg=(e,t,r)=>t in e?i0(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,_9=(e,t)=>{for(var r in t||(t={}))b4.call(t,r)&&pg(e,r,t[r]);if(hg)for(var r of hg(t))w9.call(t,r)&&pg(e,r,t[r]);return e},x9=(e,t)=>g9(e,y9(t)),S9=(e=>typeof Kn<"u"?Kn:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof Kn<"u"?Kn:t)[r]}):e)(function(e){if(typeof Kn<"u")return Kn.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),E9=(e,t)=>function(){return t||(0,e[y4(e)[0]])((t={exports:{}}).exports,t),t.exports},C9=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of y4(t))!b4.call(e,i)&&i!==r&&i0(e,i,{get:()=>t[i],enumerable:!(n=v9(t,i))||n.enumerable});return e},Qo=(e,t,r)=>(r=e!=null?m9(b9(e)):{},C9(!e||!e.__esModule?i0(r,"default",{value:e,enumerable:!0}):r,e)),_t=(e,t,r)=>new Promise((n,i)=>{var s=c=>{try{a(r.next(c))}catch(u){i(u)}},o=c=>{try{a(r.throw(c))}catch(u){i(u)}},a=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,o);a((r=r.apply(e,t)).next())}),ea=E9({"node_modules/bn.js/lib/bn.js"(e,t){(function(r,n){function i(p,d){if(!p)throw new Error(d||"Assertion failed")}function s(p,d){p.super_=d;var m=function(){};m.prototype=d.prototype,p.prototype=new m,p.prototype.constructor=p}function o(p,d,m){if(o.isBN(p))return p;this.negative=0,this.words=null,this.length=0,this.red=null,p!==null&&((d==="le"||d==="be")&&(m=d,d=10),this._init(p||0,d||10,m||"be"))}typeof r=="object"?r.exports=o:n.BN=o,o.BN=o,o.wordSize=26;var a;try{typeof window<"u"&&typeof window.Buffer<"u"?a=window.Buffer:a=S9("buffer").Buffer}catch{}o.isBN=function(d){return d instanceof o?!0:d!==null&&typeof d=="object"&&d.constructor.wordSize===o.wordSize&&Array.isArray(d.words)},o.max=function(d,m){return d.cmp(m)>0?d:m},o.min=function(d,m){return d.cmp(m)<0?d:m},o.prototype._init=function(d,m,x){if(typeof d=="number")return this._initNumber(d,m,x);if(typeof d=="object")return this._initArray(d,m,x);m==="hex"&&(m=16),i(m===(m|0)&&m>=2&&m<=36),d=d.toString().replace(/\s+/g,"");var M=0;d[0]==="-"&&(M++,this.negative=1),M<d.length&&(m===16?this._parseHex(d,M,x):(this._parseBase(d,m,M),x==="le"&&this._initArray(this.toArray(),m,x)))},o.prototype._initNumber=function(d,m,x){d<0&&(this.negative=1,d=-d),d<67108864?(this.words=[d&67108863],this.length=1):d<4503599627370496?(this.words=[d&67108863,d/67108864&67108863],this.length=2):(i(d<9007199254740992),this.words=[d&67108863,d/67108864&67108863,1],this.length=3),x==="le"&&this._initArray(this.toArray(),m,x)},o.prototype._initArray=function(d,m,x){if(i(typeof d.length=="number"),d.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(d.length/3),this.words=new Array(this.length);for(var M=0;M<this.length;M++)this.words[M]=0;var E,O,C=0;if(x==="be")for(M=d.length-1,E=0;M>=0;M-=3)O=d[M]|d[M-1]<<8|d[M-2]<<16,this.words[E]|=O<<C&67108863,this.words[E+1]=O>>>26-C&67108863,C+=24,C>=26&&(C-=26,E++);else if(x==="le")for(M=0,E=0;M<d.length;M+=3)O=d[M]|d[M+1]<<8|d[M+2]<<16,this.words[E]|=O<<C&67108863,this.words[E+1]=O>>>26-C&67108863,C+=24,C>=26&&(C-=26,E++);return this._strip()};function c(p,d){var m=p.charCodeAt(d);if(m>=48&&m<=57)return m-48;if(m>=65&&m<=70)return m-55;if(m>=97&&m<=102)return m-87;i(!1,"Invalid character in "+p)}function u(p,d,m){var x=c(p,m);return m-1>=d&&(x|=c(p,m-1)<<4),x}o.prototype._parseHex=function(d,m,x){this.length=Math.ceil((d.length-m)/6),this.words=new Array(this.length);for(var M=0;M<this.length;M++)this.words[M]=0;var E=0,O=0,C;if(x==="be")for(M=d.length-1;M>=m;M-=2)C=u(d,m,M)<<E,this.words[O]|=C&67108863,E>=18?(E-=18,O+=1,this.words[O]|=C>>>26):E+=8;else{var g=d.length-m;for(M=g%2===0?m+1:m;M<d.length;M+=2)C=u(d,m,M)<<E,this.words[O]|=C&67108863,E>=18?(E-=18,O+=1,this.words[O]|=C>>>26):E+=8}this._strip()};function l(p,d,m,x){for(var M=0,E=0,O=Math.min(p.length,m),C=d;C<O;C++){var g=p.charCodeAt(C)-48;M*=x,g>=49?E=g-49+10:g>=17?E=g-17+10:E=g,i(g>=0&&E<x,"Invalid character"),M+=E}return M}o.prototype._parseBase=function(d,m,x){this.words=[0],this.length=1;for(var M=0,E=1;E<=67108863;E*=m)M++;M--,E=E/m|0;for(var O=d.length-x,C=O%M,g=Math.min(O,O-C)+x,v=0,j=x;j<g;j+=M)v=l(d,j,j+M,m),this.imuln(E),this.words[0]+v<67108864?this.words[0]+=v:this._iaddn(v);if(C!==0){var ee=1;for(v=l(d,j,d.length,m),j=0;j<C;j++)ee*=m;this.imuln(ee),this.words[0]+v<67108864?this.words[0]+=v:this._iaddn(v)}this._strip()},o.prototype.copy=function(d){d.words=new Array(this.length);for(var m=0;m<this.length;m++)d.words[m]=this.words[m];d.length=this.length,d.negative=this.negative,d.red=this.red};function f(p,d){p.words=d.words,p.length=d.length,p.negative=d.negative,p.red=d.red}if(o.prototype._move=function(d){f(d,this)},o.prototype.clone=function(){var d=new o(null);return this.copy(d),d},o.prototype._expand=function(d){for(;this.length<d;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=h}catch{o.prototype.inspect=h}else o.prototype.inspect=h;function h(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var y=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],b=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],w=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(d,m){d=d||10,m=m|0||1;var x;if(d===16||d==="hex"){x="";for(var M=0,E=0,O=0;O<this.length;O++){var C=this.words[O],g=((C<<M|E)&16777215).toString(16);E=C>>>24-M&16777215,M+=2,M>=26&&(M-=26,O--),E!==0||O!==this.length-1?x=y[6-g.length]+g+x:x=g+x}for(E!==0&&(x=E.toString(16)+x);x.length%m!==0;)x="0"+x;return this.negative!==0&&(x="-"+x),x}if(d===(d|0)&&d>=2&&d<=36){var v=b[d],j=w[d];x="";var ee=this.clone();for(ee.negative=0;!ee.isZero();){var ie=ee.modrn(j).toString(d);ee=ee.idivn(j),ee.isZero()?x=ie+x:x=y[v-ie.length]+ie+x}for(this.isZero()&&(x="0"+x);x.length%m!==0;)x="0"+x;return this.negative!==0&&(x="-"+x),x}i(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var d=this.words[0];return this.length===2?d+=this.words[1]*67108864:this.length===3&&this.words[2]===1?d+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-d:d},o.prototype.toJSON=function(){return this.toString(16,2)},a&&(o.prototype.toBuffer=function(d,m){return this.toArrayLike(a,d,m)}),o.prototype.toArray=function(d,m){return this.toArrayLike(Array,d,m)};var T=function(d,m){return d.allocUnsafe?d.allocUnsafe(m):new d(m)};o.prototype.toArrayLike=function(d,m,x){this._strip();var M=this.byteLength(),E=x||Math.max(1,M);i(M<=E,"byte array longer than desired length"),i(E>0,"Requested array length <= 0");var O=T(d,E),C=m==="le"?"LE":"BE";return this["_toArrayLike"+C](O,M),O},o.prototype._toArrayLikeLE=function(d,m){for(var x=0,M=0,E=0,O=0;E<this.length;E++){var C=this.words[E]<<O|M;d[x++]=C&255,x<d.length&&(d[x++]=C>>8&255),x<d.length&&(d[x++]=C>>16&255),O===6?(x<d.length&&(d[x++]=C>>24&255),M=0,O=0):(M=C>>>24,O+=2)}if(x<d.length)for(d[x++]=M;x<d.length;)d[x++]=0},o.prototype._toArrayLikeBE=function(d,m){for(var x=d.length-1,M=0,E=0,O=0;E<this.length;E++){var C=this.words[E]<<O|M;d[x--]=C&255,x>=0&&(d[x--]=C>>8&255),x>=0&&(d[x--]=C>>16&255),O===6?(x>=0&&(d[x--]=C>>24&255),M=0,O=0):(M=C>>>24,O+=2)}if(x>=0)for(d[x--]=M;x>=0;)d[x--]=0},Math.clz32?o.prototype._countBits=function(d){return 32-Math.clz32(d)}:o.prototype._countBits=function(d){var m=d,x=0;return m>=4096&&(x+=13,m>>>=13),m>=64&&(x+=7,m>>>=7),m>=8&&(x+=4,m>>>=4),m>=2&&(x+=2,m>>>=2),x+m},o.prototype._zeroBits=function(d){if(d===0)return 26;var m=d,x=0;return m&8191||(x+=13,m>>>=13),m&127||(x+=7,m>>>=7),m&15||(x+=4,m>>>=4),m&3||(x+=2,m>>>=2),m&1||x++,x},o.prototype.bitLength=function(){var d=this.words[this.length-1],m=this._countBits(d);return(this.length-1)*26+m};function P(p){for(var d=new Array(p.bitLength()),m=0;m<d.length;m++){var x=m/26|0,M=m%26;d[m]=p.words[x]>>>M&1}return d}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var d=0,m=0;m<this.length;m++){var x=this._zeroBits(this.words[m]);if(d+=x,x!==26)break}return d},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(d){return this.negative!==0?this.abs().inotn(d).iaddn(1):this.clone()},o.prototype.fromTwos=function(d){return this.testn(d-1)?this.notn(d).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(d){for(;this.length<d.length;)this.words[this.length++]=0;for(var m=0;m<d.length;m++)this.words[m]=this.words[m]|d.words[m];return this._strip()},o.prototype.ior=function(d){return i((this.negative|d.negative)===0),this.iuor(d)},o.prototype.or=function(d){return this.length>d.length?this.clone().ior(d):d.clone().ior(this)},o.prototype.uor=function(d){return this.length>d.length?this.clone().iuor(d):d.clone().iuor(this)},o.prototype.iuand=function(d){var m;this.length>d.length?m=d:m=this;for(var x=0;x<m.length;x++)this.words[x]=this.words[x]&d.words[x];return this.length=m.length,this._strip()},o.prototype.iand=function(d){return i((this.negative|d.negative)===0),this.iuand(d)},o.prototype.and=function(d){return this.length>d.length?this.clone().iand(d):d.clone().iand(this)},o.prototype.uand=function(d){return this.length>d.length?this.clone().iuand(d):d.clone().iuand(this)},o.prototype.iuxor=function(d){var m,x;this.length>d.length?(m=this,x=d):(m=d,x=this);for(var M=0;M<x.length;M++)this.words[M]=m.words[M]^x.words[M];if(this!==m)for(;M<m.length;M++)this.words[M]=m.words[M];return this.length=m.length,this._strip()},o.prototype.ixor=function(d){return i((this.negative|d.negative)===0),this.iuxor(d)},o.prototype.xor=function(d){return this.length>d.length?this.clone().ixor(d):d.clone().ixor(this)},o.prototype.uxor=function(d){return this.length>d.length?this.clone().iuxor(d):d.clone().iuxor(this)},o.prototype.inotn=function(d){i(typeof d=="number"&&d>=0);var m=Math.ceil(d/26)|0,x=d%26;this._expand(m),x>0&&m--;for(var M=0;M<m;M++)this.words[M]=~this.words[M]&67108863;return x>0&&(this.words[M]=~this.words[M]&67108863>>26-x),this._strip()},o.prototype.notn=function(d){return this.clone().inotn(d)},o.prototype.setn=function(d,m){i(typeof d=="number"&&d>=0);var x=d/26|0,M=d%26;return this._expand(x+1),m?this.words[x]=this.words[x]|1<<M:this.words[x]=this.words[x]&~(1<<M),this._strip()},o.prototype.iadd=function(d){var m;if(this.negative!==0&&d.negative===0)return this.negative=0,m=this.isub(d),this.negative^=1,this._normSign();if(this.negative===0&&d.negative!==0)return d.negative=0,m=this.isub(d),d.negative=1,m._normSign();var x,M;this.length>d.length?(x=this,M=d):(x=d,M=this);for(var E=0,O=0;O<M.length;O++)m=(x.words[O]|0)+(M.words[O]|0)+E,this.words[O]=m&67108863,E=m>>>26;for(;E!==0&&O<x.length;O++)m=(x.words[O]|0)+E,this.words[O]=m&67108863,E=m>>>26;if(this.length=x.length,E!==0)this.words[this.length]=E,this.length++;else if(x!==this)for(;O<x.length;O++)this.words[O]=x.words[O];return this},o.prototype.add=function(d){var m;return d.negative!==0&&this.negative===0?(d.negative=0,m=this.sub(d),d.negative^=1,m):d.negative===0&&this.negative!==0?(this.negative=0,m=d.sub(this),this.negative=1,m):this.length>d.length?this.clone().iadd(d):d.clone().iadd(this)},o.prototype.isub=function(d){if(d.negative!==0){d.negative=0;var m=this.iadd(d);return d.negative=1,m._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(d),this.negative=1,this._normSign();var x=this.cmp(d);if(x===0)return this.negative=0,this.length=1,this.words[0]=0,this;var M,E;x>0?(M=this,E=d):(M=d,E=this);for(var O=0,C=0;C<E.length;C++)m=(M.words[C]|0)-(E.words[C]|0)+O,O=m>>26,this.words[C]=m&67108863;for(;O!==0&&C<M.length;C++)m=(M.words[C]|0)+O,O=m>>26,this.words[C]=m&67108863;if(O===0&&C<M.length&&M!==this)for(;C<M.length;C++)this.words[C]=M.words[C];return this.length=Math.max(this.length,C),M!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(d){return this.clone().isub(d)};function k(p,d,m){m.negative=d.negative^p.negative;var x=p.length+d.length|0;m.length=x,x=x-1|0;var M=p.words[0]|0,E=d.words[0]|0,O=M*E,C=O&67108863,g=O/67108864|0;m.words[0]=C;for(var v=1;v<x;v++){for(var j=g>>>26,ee=g&67108863,ie=Math.min(v,d.length-1),de=Math.max(0,v-p.length+1);de<=ie;de++){var ye=v-de|0;M=p.words[ye]|0,E=d.words[de]|0,O=M*E+ee,j+=O/67108864|0,ee=O&67108863}m.words[v]=ee|0,g=j|0}return g!==0?m.words[v]=g|0:m.length--,m._strip()}var N=function(d,m,x){var M=d.words,E=m.words,O=x.words,C=0,g,v,j,ee=M[0]|0,ie=ee&8191,de=ee>>>13,ye=M[1]|0,Ee=ye&8191,Se=ye>>>13,Ge=M[2]|0,Ue=Ge&8191,dt=Ge>>>13,ht=M[3]|0,$e=ht&8191,mt=ht>>>13,xe=M[4]|0,ge=xe&8191,Te=xe>>>13,qe=M[5]|0,De=qe&8191,Oe=qe>>>13,Ie=M[6]|0,Fe=Ie&8191,lt=Ie>>>13,ft=M[7]|0,He=ft&8191,jt=ft>>>13,St=M[8]|0,Ze=St&8191,At=St>>>13,Nt=M[9]|0,nt=Nt&8191,Et=Nt>>>13,Tt=E[0]|0,st=Tt&8191,kt=Tt>>>13,It=E[1]|0,it=It&8191,bt=It>>>13,Ct=E[2]|0,Ye=Ct&8191,gt=Ct>>>13,Pt=E[3]|0,ot=Pt&8191,wt=Pt>>>13,Ut=E[4]|0,R=Ut&8191,S=Ut>>>13,A=E[5]|0,B=A&8191,K=A>>>13,Z=E[6]|0,te=Z&8191,Be=Z>>>13,tt=E[7]|0,Ne=tt&8191,z=tt>>>13,oe=E[8]|0,pe=oe&8191,ke=oe>>>13,Ke=E[9]|0,Re=Ke&8191,ze=Ke>>>13;x.negative=d.negative^m.negative,x.length=19,g=Math.imul(ie,st),v=Math.imul(ie,kt),v=v+Math.imul(de,st)|0,j=Math.imul(de,kt);var at=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(at>>>26)|0,at&=67108863,g=Math.imul(Ee,st),v=Math.imul(Ee,kt),v=v+Math.imul(Se,st)|0,j=Math.imul(Se,kt),g=g+Math.imul(ie,it)|0,v=v+Math.imul(ie,bt)|0,v=v+Math.imul(de,it)|0,j=j+Math.imul(de,bt)|0;var Ht=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,g=Math.imul(Ue,st),v=Math.imul(Ue,kt),v=v+Math.imul(dt,st)|0,j=Math.imul(dt,kt),g=g+Math.imul(Ee,it)|0,v=v+Math.imul(Ee,bt)|0,v=v+Math.imul(Se,it)|0,j=j+Math.imul(Se,bt)|0,g=g+Math.imul(ie,Ye)|0,v=v+Math.imul(ie,gt)|0,v=v+Math.imul(de,Ye)|0,j=j+Math.imul(de,gt)|0;var Rt=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,g=Math.imul($e,st),v=Math.imul($e,kt),v=v+Math.imul(mt,st)|0,j=Math.imul(mt,kt),g=g+Math.imul(Ue,it)|0,v=v+Math.imul(Ue,bt)|0,v=v+Math.imul(dt,it)|0,j=j+Math.imul(dt,bt)|0,g=g+Math.imul(Ee,Ye)|0,v=v+Math.imul(Ee,gt)|0,v=v+Math.imul(Se,Ye)|0,j=j+Math.imul(Se,gt)|0,g=g+Math.imul(ie,ot)|0,v=v+Math.imul(ie,wt)|0,v=v+Math.imul(de,ot)|0,j=j+Math.imul(de,wt)|0;var Dt=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,g=Math.imul(ge,st),v=Math.imul(ge,kt),v=v+Math.imul(Te,st)|0,j=Math.imul(Te,kt),g=g+Math.imul($e,it)|0,v=v+Math.imul($e,bt)|0,v=v+Math.imul(mt,it)|0,j=j+Math.imul(mt,bt)|0,g=g+Math.imul(Ue,Ye)|0,v=v+Math.imul(Ue,gt)|0,v=v+Math.imul(dt,Ye)|0,j=j+Math.imul(dt,gt)|0,g=g+Math.imul(Ee,ot)|0,v=v+Math.imul(Ee,wt)|0,v=v+Math.imul(Se,ot)|0,j=j+Math.imul(Se,wt)|0,g=g+Math.imul(ie,R)|0,v=v+Math.imul(ie,S)|0,v=v+Math.imul(de,R)|0,j=j+Math.imul(de,S)|0;var er=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(er>>>26)|0,er&=67108863,g=Math.imul(De,st),v=Math.imul(De,kt),v=v+Math.imul(Oe,st)|0,j=Math.imul(Oe,kt),g=g+Math.imul(ge,it)|0,v=v+Math.imul(ge,bt)|0,v=v+Math.imul(Te,it)|0,j=j+Math.imul(Te,bt)|0,g=g+Math.imul($e,Ye)|0,v=v+Math.imul($e,gt)|0,v=v+Math.imul(mt,Ye)|0,j=j+Math.imul(mt,gt)|0,g=g+Math.imul(Ue,ot)|0,v=v+Math.imul(Ue,wt)|0,v=v+Math.imul(dt,ot)|0,j=j+Math.imul(dt,wt)|0,g=g+Math.imul(Ee,R)|0,v=v+Math.imul(Ee,S)|0,v=v+Math.imul(Se,R)|0,j=j+Math.imul(Se,S)|0,g=g+Math.imul(ie,B)|0,v=v+Math.imul(ie,K)|0,v=v+Math.imul(de,B)|0,j=j+Math.imul(de,K)|0;var br=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(br>>>26)|0,br&=67108863,g=Math.imul(Fe,st),v=Math.imul(Fe,kt),v=v+Math.imul(lt,st)|0,j=Math.imul(lt,kt),g=g+Math.imul(De,it)|0,v=v+Math.imul(De,bt)|0,v=v+Math.imul(Oe,it)|0,j=j+Math.imul(Oe,bt)|0,g=g+Math.imul(ge,Ye)|0,v=v+Math.imul(ge,gt)|0,v=v+Math.imul(Te,Ye)|0,j=j+Math.imul(Te,gt)|0,g=g+Math.imul($e,ot)|0,v=v+Math.imul($e,wt)|0,v=v+Math.imul(mt,ot)|0,j=j+Math.imul(mt,wt)|0,g=g+Math.imul(Ue,R)|0,v=v+Math.imul(Ue,S)|0,v=v+Math.imul(dt,R)|0,j=j+Math.imul(dt,S)|0,g=g+Math.imul(Ee,B)|0,v=v+Math.imul(Ee,K)|0,v=v+Math.imul(Se,B)|0,j=j+Math.imul(Se,K)|0,g=g+Math.imul(ie,te)|0,v=v+Math.imul(ie,Be)|0,v=v+Math.imul(de,te)|0,j=j+Math.imul(de,Be)|0;var ir=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(ir>>>26)|0,ir&=67108863,g=Math.imul(He,st),v=Math.imul(He,kt),v=v+Math.imul(jt,st)|0,j=Math.imul(jt,kt),g=g+Math.imul(Fe,it)|0,v=v+Math.imul(Fe,bt)|0,v=v+Math.imul(lt,it)|0,j=j+Math.imul(lt,bt)|0,g=g+Math.imul(De,Ye)|0,v=v+Math.imul(De,gt)|0,v=v+Math.imul(Oe,Ye)|0,j=j+Math.imul(Oe,gt)|0,g=g+Math.imul(ge,ot)|0,v=v+Math.imul(ge,wt)|0,v=v+Math.imul(Te,ot)|0,j=j+Math.imul(Te,wt)|0,g=g+Math.imul($e,R)|0,v=v+Math.imul($e,S)|0,v=v+Math.imul(mt,R)|0,j=j+Math.imul(mt,S)|0,g=g+Math.imul(Ue,B)|0,v=v+Math.imul(Ue,K)|0,v=v+Math.imul(dt,B)|0,j=j+Math.imul(dt,K)|0,g=g+Math.imul(Ee,te)|0,v=v+Math.imul(Ee,Be)|0,v=v+Math.imul(Se,te)|0,j=j+Math.imul(Se,Be)|0,g=g+Math.imul(ie,Ne)|0,v=v+Math.imul(ie,z)|0,v=v+Math.imul(de,Ne)|0,j=j+Math.imul(de,z)|0;var Kt=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,g=Math.imul(Ze,st),v=Math.imul(Ze,kt),v=v+Math.imul(At,st)|0,j=Math.imul(At,kt),g=g+Math.imul(He,it)|0,v=v+Math.imul(He,bt)|0,v=v+Math.imul(jt,it)|0,j=j+Math.imul(jt,bt)|0,g=g+Math.imul(Fe,Ye)|0,v=v+Math.imul(Fe,gt)|0,v=v+Math.imul(lt,Ye)|0,j=j+Math.imul(lt,gt)|0,g=g+Math.imul(De,ot)|0,v=v+Math.imul(De,wt)|0,v=v+Math.imul(Oe,ot)|0,j=j+Math.imul(Oe,wt)|0,g=g+Math.imul(ge,R)|0,v=v+Math.imul(ge,S)|0,v=v+Math.imul(Te,R)|0,j=j+Math.imul(Te,S)|0,g=g+Math.imul($e,B)|0,v=v+Math.imul($e,K)|0,v=v+Math.imul(mt,B)|0,j=j+Math.imul(mt,K)|0,g=g+Math.imul(Ue,te)|0,v=v+Math.imul(Ue,Be)|0,v=v+Math.imul(dt,te)|0,j=j+Math.imul(dt,Be)|0,g=g+Math.imul(Ee,Ne)|0,v=v+Math.imul(Ee,z)|0,v=v+Math.imul(Se,Ne)|0,j=j+Math.imul(Se,z)|0,g=g+Math.imul(ie,pe)|0,v=v+Math.imul(ie,ke)|0,v=v+Math.imul(de,pe)|0,j=j+Math.imul(de,ke)|0;var vr=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(vr>>>26)|0,vr&=67108863,g=Math.imul(nt,st),v=Math.imul(nt,kt),v=v+Math.imul(Et,st)|0,j=Math.imul(Et,kt),g=g+Math.imul(Ze,it)|0,v=v+Math.imul(Ze,bt)|0,v=v+Math.imul(At,it)|0,j=j+Math.imul(At,bt)|0,g=g+Math.imul(He,Ye)|0,v=v+Math.imul(He,gt)|0,v=v+Math.imul(jt,Ye)|0,j=j+Math.imul(jt,gt)|0,g=g+Math.imul(Fe,ot)|0,v=v+Math.imul(Fe,wt)|0,v=v+Math.imul(lt,ot)|0,j=j+Math.imul(lt,wt)|0,g=g+Math.imul(De,R)|0,v=v+Math.imul(De,S)|0,v=v+Math.imul(Oe,R)|0,j=j+Math.imul(Oe,S)|0,g=g+Math.imul(ge,B)|0,v=v+Math.imul(ge,K)|0,v=v+Math.imul(Te,B)|0,j=j+Math.imul(Te,K)|0,g=g+Math.imul($e,te)|0,v=v+Math.imul($e,Be)|0,v=v+Math.imul(mt,te)|0,j=j+Math.imul(mt,Be)|0,g=g+Math.imul(Ue,Ne)|0,v=v+Math.imul(Ue,z)|0,v=v+Math.imul(dt,Ne)|0,j=j+Math.imul(dt,z)|0,g=g+Math.imul(Ee,pe)|0,v=v+Math.imul(Ee,ke)|0,v=v+Math.imul(Se,pe)|0,j=j+Math.imul(Se,ke)|0,g=g+Math.imul(ie,Re)|0,v=v+Math.imul(ie,ze)|0,v=v+Math.imul(de,Re)|0,j=j+Math.imul(de,ze)|0;var mn=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(mn>>>26)|0,mn&=67108863,g=Math.imul(nt,it),v=Math.imul(nt,bt),v=v+Math.imul(Et,it)|0,j=Math.imul(Et,bt),g=g+Math.imul(Ze,Ye)|0,v=v+Math.imul(Ze,gt)|0,v=v+Math.imul(At,Ye)|0,j=j+Math.imul(At,gt)|0,g=g+Math.imul(He,ot)|0,v=v+Math.imul(He,wt)|0,v=v+Math.imul(jt,ot)|0,j=j+Math.imul(jt,wt)|0,g=g+Math.imul(Fe,R)|0,v=v+Math.imul(Fe,S)|0,v=v+Math.imul(lt,R)|0,j=j+Math.imul(lt,S)|0,g=g+Math.imul(De,B)|0,v=v+Math.imul(De,K)|0,v=v+Math.imul(Oe,B)|0,j=j+Math.imul(Oe,K)|0,g=g+Math.imul(ge,te)|0,v=v+Math.imul(ge,Be)|0,v=v+Math.imul(Te,te)|0,j=j+Math.imul(Te,Be)|0,g=g+Math.imul($e,Ne)|0,v=v+Math.imul($e,z)|0,v=v+Math.imul(mt,Ne)|0,j=j+Math.imul(mt,z)|0,g=g+Math.imul(Ue,pe)|0,v=v+Math.imul(Ue,ke)|0,v=v+Math.imul(dt,pe)|0,j=j+Math.imul(dt,ke)|0,g=g+Math.imul(Ee,Re)|0,v=v+Math.imul(Ee,ze)|0,v=v+Math.imul(Se,Re)|0,j=j+Math.imul(Se,ze)|0;var Fr=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,g=Math.imul(nt,Ye),v=Math.imul(nt,gt),v=v+Math.imul(Et,Ye)|0,j=Math.imul(Et,gt),g=g+Math.imul(Ze,ot)|0,v=v+Math.imul(Ze,wt)|0,v=v+Math.imul(At,ot)|0,j=j+Math.imul(At,wt)|0,g=g+Math.imul(He,R)|0,v=v+Math.imul(He,S)|0,v=v+Math.imul(jt,R)|0,j=j+Math.imul(jt,S)|0,g=g+Math.imul(Fe,B)|0,v=v+Math.imul(Fe,K)|0,v=v+Math.imul(lt,B)|0,j=j+Math.imul(lt,K)|0,g=g+Math.imul(De,te)|0,v=v+Math.imul(De,Be)|0,v=v+Math.imul(Oe,te)|0,j=j+Math.imul(Oe,Be)|0,g=g+Math.imul(ge,Ne)|0,v=v+Math.imul(ge,z)|0,v=v+Math.imul(Te,Ne)|0,j=j+Math.imul(Te,z)|0,g=g+Math.imul($e,pe)|0,v=v+Math.imul($e,ke)|0,v=v+Math.imul(mt,pe)|0,j=j+Math.imul(mt,ke)|0,g=g+Math.imul(Ue,Re)|0,v=v+Math.imul(Ue,ze)|0,v=v+Math.imul(dt,Re)|0,j=j+Math.imul(dt,ze)|0;var gn=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(gn>>>26)|0,gn&=67108863,g=Math.imul(nt,ot),v=Math.imul(nt,wt),v=v+Math.imul(Et,ot)|0,j=Math.imul(Et,wt),g=g+Math.imul(Ze,R)|0,v=v+Math.imul(Ze,S)|0,v=v+Math.imul(At,R)|0,j=j+Math.imul(At,S)|0,g=g+Math.imul(He,B)|0,v=v+Math.imul(He,K)|0,v=v+Math.imul(jt,B)|0,j=j+Math.imul(jt,K)|0,g=g+Math.imul(Fe,te)|0,v=v+Math.imul(Fe,Be)|0,v=v+Math.imul(lt,te)|0,j=j+Math.imul(lt,Be)|0,g=g+Math.imul(De,Ne)|0,v=v+Math.imul(De,z)|0,v=v+Math.imul(Oe,Ne)|0,j=j+Math.imul(Oe,z)|0,g=g+Math.imul(ge,pe)|0,v=v+Math.imul(ge,ke)|0,v=v+Math.imul(Te,pe)|0,j=j+Math.imul(Te,ke)|0,g=g+Math.imul($e,Re)|0,v=v+Math.imul($e,ze)|0,v=v+Math.imul(mt,Re)|0,j=j+Math.imul(mt,ze)|0;var fi=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(fi>>>26)|0,fi&=67108863,g=Math.imul(nt,R),v=Math.imul(nt,S),v=v+Math.imul(Et,R)|0,j=Math.imul(Et,S),g=g+Math.imul(Ze,B)|0,v=v+Math.imul(Ze,K)|0,v=v+Math.imul(At,B)|0,j=j+Math.imul(At,K)|0,g=g+Math.imul(He,te)|0,v=v+Math.imul(He,Be)|0,v=v+Math.imul(jt,te)|0,j=j+Math.imul(jt,Be)|0,g=g+Math.imul(Fe,Ne)|0,v=v+Math.imul(Fe,z)|0,v=v+Math.imul(lt,Ne)|0,j=j+Math.imul(lt,z)|0,g=g+Math.imul(De,pe)|0,v=v+Math.imul(De,ke)|0,v=v+Math.imul(Oe,pe)|0,j=j+Math.imul(Oe,ke)|0,g=g+Math.imul(ge,Re)|0,v=v+Math.imul(ge,ze)|0,v=v+Math.imul(Te,Re)|0,j=j+Math.imul(Te,ze)|0;var di=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(di>>>26)|0,di&=67108863,g=Math.imul(nt,B),v=Math.imul(nt,K),v=v+Math.imul(Et,B)|0,j=Math.imul(Et,K),g=g+Math.imul(Ze,te)|0,v=v+Math.imul(Ze,Be)|0,v=v+Math.imul(At,te)|0,j=j+Math.imul(At,Be)|0,g=g+Math.imul(He,Ne)|0,v=v+Math.imul(He,z)|0,v=v+Math.imul(jt,Ne)|0,j=j+Math.imul(jt,z)|0,g=g+Math.imul(Fe,pe)|0,v=v+Math.imul(Fe,ke)|0,v=v+Math.imul(lt,pe)|0,j=j+Math.imul(lt,ke)|0,g=g+Math.imul(De,Re)|0,v=v+Math.imul(De,ze)|0,v=v+Math.imul(Oe,Re)|0,j=j+Math.imul(Oe,ze)|0;var vn=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(vn>>>26)|0,vn&=67108863,g=Math.imul(nt,te),v=Math.imul(nt,Be),v=v+Math.imul(Et,te)|0,j=Math.imul(Et,Be),g=g+Math.imul(Ze,Ne)|0,v=v+Math.imul(Ze,z)|0,v=v+Math.imul(At,Ne)|0,j=j+Math.imul(At,z)|0,g=g+Math.imul(He,pe)|0,v=v+Math.imul(He,ke)|0,v=v+Math.imul(jt,pe)|0,j=j+Math.imul(jt,ke)|0,g=g+Math.imul(Fe,Re)|0,v=v+Math.imul(Fe,ze)|0,v=v+Math.imul(lt,Re)|0,j=j+Math.imul(lt,ze)|0;var hi=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(hi>>>26)|0,hi&=67108863,g=Math.imul(nt,Ne),v=Math.imul(nt,z),v=v+Math.imul(Et,Ne)|0,j=Math.imul(Et,z),g=g+Math.imul(Ze,pe)|0,v=v+Math.imul(Ze,ke)|0,v=v+Math.imul(At,pe)|0,j=j+Math.imul(At,ke)|0,g=g+Math.imul(He,Re)|0,v=v+Math.imul(He,ze)|0,v=v+Math.imul(jt,Re)|0,j=j+Math.imul(jt,ze)|0;var pi=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(pi>>>26)|0,pi&=67108863,g=Math.imul(nt,pe),v=Math.imul(nt,ke),v=v+Math.imul(Et,pe)|0,j=Math.imul(Et,ke),g=g+Math.imul(Ze,Re)|0,v=v+Math.imul(Ze,ze)|0,v=v+Math.imul(At,Re)|0,j=j+Math.imul(At,ze)|0;var $=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+($>>>26)|0,$&=67108863,g=Math.imul(nt,Re),v=Math.imul(nt,ze),v=v+Math.imul(Et,Re)|0,j=Math.imul(Et,ze);var H=(C+g|0)+((v&8191)<<13)|0;return C=(j+(v>>>13)|0)+(H>>>26)|0,H&=67108863,O[0]=at,O[1]=Ht,O[2]=Rt,O[3]=Dt,O[4]=er,O[5]=br,O[6]=ir,O[7]=Kt,O[8]=vr,O[9]=mn,O[10]=Fr,O[11]=gn,O[12]=fi,O[13]=di,O[14]=vn,O[15]=hi,O[16]=pi,O[17]=$,O[18]=H,C!==0&&(O[19]=C,x.length++),x};Math.imul||(N=k);function F(p,d,m){m.negative=d.negative^p.negative,m.length=p.length+d.length;for(var x=0,M=0,E=0;E<m.length-1;E++){var O=M;M=0;for(var C=x&67108863,g=Math.min(E,d.length-1),v=Math.max(0,E-p.length+1);v<=g;v++){var j=E-v,ee=p.words[j]|0,ie=d.words[v]|0,de=ee*ie,ye=de&67108863;O=O+(de/67108864|0)|0,ye=ye+C|0,C=ye&67108863,O=O+(ye>>>26)|0,M+=O>>>26,O&=67108863}m.words[E]=C,x=O,O=M}return x!==0?m.words[E]=x:m.length--,m._strip()}function L(p,d,m){return F(p,d,m)}o.prototype.mulTo=function(d,m){var x,M=this.length+d.length;return this.length===10&&d.length===10?x=N(this,d,m):M<63?x=k(this,d,m):M<1024?x=F(this,d,m):x=L(this,d,m),x},o.prototype.mul=function(d){var m=new o(null);return m.words=new Array(this.length+d.length),this.mulTo(d,m)},o.prototype.mulf=function(d){var m=new o(null);return m.words=new Array(this.length+d.length),L(this,d,m)},o.prototype.imul=function(d){return this.clone().mulTo(d,this)},o.prototype.imuln=function(d){var m=d<0;m&&(d=-d),i(typeof d=="number"),i(d<67108864);for(var x=0,M=0;M<this.length;M++){var E=(this.words[M]|0)*d,O=(E&67108863)+(x&67108863);x>>=26,x+=E/67108864|0,x+=O>>>26,this.words[M]=O&67108863}return x!==0&&(this.words[M]=x,this.length++),m?this.ineg():this},o.prototype.muln=function(d){return this.clone().imuln(d)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(d){var m=P(d);if(m.length===0)return new o(1);for(var x=this,M=0;M<m.length&&m[M]===0;M++,x=x.sqr());if(++M<m.length)for(var E=x.sqr();M<m.length;M++,E=E.sqr())m[M]!==0&&(x=x.mul(E));return x},o.prototype.iushln=function(d){i(typeof d=="number"&&d>=0);var m=d%26,x=(d-m)/26,M=67108863>>>26-m<<26-m,E;if(m!==0){var O=0;for(E=0;E<this.length;E++){var C=this.words[E]&M,g=(this.words[E]|0)-C<<m;this.words[E]=g|O,O=C>>>26-m}O&&(this.words[E]=O,this.length++)}if(x!==0){for(E=this.length-1;E>=0;E--)this.words[E+x]=this.words[E];for(E=0;E<x;E++)this.words[E]=0;this.length+=x}return this._strip()},o.prototype.ishln=function(d){return i(this.negative===0),this.iushln(d)},o.prototype.iushrn=function(d,m,x){i(typeof d=="number"&&d>=0);var M;m?M=(m-m%26)/26:M=0;var E=d%26,O=Math.min((d-E)/26,this.length),C=67108863^67108863>>>E<<E,g=x;if(M-=O,M=Math.max(0,M),g){for(var v=0;v<O;v++)g.words[v]=this.words[v];g.length=O}if(O!==0)if(this.length>O)for(this.length-=O,v=0;v<this.length;v++)this.words[v]=this.words[v+O];else this.words[0]=0,this.length=1;var j=0;for(v=this.length-1;v>=0&&(j!==0||v>=M);v--){var ee=this.words[v]|0;this.words[v]=j<<26-E|ee>>>E,j=ee&C}return g&&j!==0&&(g.words[g.length++]=j),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(d,m,x){return i(this.negative===0),this.iushrn(d,m,x)},o.prototype.shln=function(d){return this.clone().ishln(d)},o.prototype.ushln=function(d){return this.clone().iushln(d)},o.prototype.shrn=function(d){return this.clone().ishrn(d)},o.prototype.ushrn=function(d){return this.clone().iushrn(d)},o.prototype.testn=function(d){i(typeof d=="number"&&d>=0);var m=d%26,x=(d-m)/26,M=1<<m;if(this.length<=x)return!1;var E=this.words[x];return!!(E&M)},o.prototype.imaskn=function(d){i(typeof d=="number"&&d>=0);var m=d%26,x=(d-m)/26;if(i(this.negative===0,"imaskn works only with positive numbers"),this.length<=x)return this;if(m!==0&&x++,this.length=Math.min(x,this.length),m!==0){var M=67108863^67108863>>>m<<m;this.words[this.length-1]&=M}return this._strip()},o.prototype.maskn=function(d){return this.clone().imaskn(d)},o.prototype.iaddn=function(d){return i(typeof d=="number"),i(d<67108864),d<0?this.isubn(-d):this.negative!==0?this.length===1&&(this.words[0]|0)<=d?(this.words[0]=d-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(d),this.negative=1,this):this._iaddn(d)},o.prototype._iaddn=function(d){this.words[0]+=d;for(var m=0;m<this.length&&this.words[m]>=67108864;m++)this.words[m]-=67108864,m===this.length-1?this.words[m+1]=1:this.words[m+1]++;return this.length=Math.max(this.length,m+1),this},o.prototype.isubn=function(d){if(i(typeof d=="number"),i(d<67108864),d<0)return this.iaddn(-d);if(this.negative!==0)return this.negative=0,this.iaddn(d),this.negative=1,this;if(this.words[0]-=d,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var m=0;m<this.length&&this.words[m]<0;m++)this.words[m]+=67108864,this.words[m+1]-=1;return this._strip()},o.prototype.addn=function(d){return this.clone().iaddn(d)},o.prototype.subn=function(d){return this.clone().isubn(d)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(d,m,x){var M=d.length+x,E;this._expand(M);var O,C=0;for(E=0;E<d.length;E++){O=(this.words[E+x]|0)+C;var g=(d.words[E]|0)*m;O-=g&67108863,C=(O>>26)-(g/67108864|0),this.words[E+x]=O&67108863}for(;E<this.length-x;E++)O=(this.words[E+x]|0)+C,C=O>>26,this.words[E+x]=O&67108863;if(C===0)return this._strip();for(i(C===-1),C=0,E=0;E<this.length;E++)O=-(this.words[E]|0)+C,C=O>>26,this.words[E]=O&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(d,m){var x=this.length-d.length,M=this.clone(),E=d,O=E.words[E.length-1]|0,C=this._countBits(O);x=26-C,x!==0&&(E=E.ushln(x),M.iushln(x),O=E.words[E.length-1]|0);var g=M.length-E.length,v;if(m!=="mod"){v=new o(null),v.length=g+1,v.words=new Array(v.length);for(var j=0;j<v.length;j++)v.words[j]=0}var ee=M.clone()._ishlnsubmul(E,1,g);ee.negative===0&&(M=ee,v&&(v.words[g]=1));for(var ie=g-1;ie>=0;ie--){var de=(M.words[E.length+ie]|0)*67108864+(M.words[E.length+ie-1]|0);for(de=Math.min(de/O|0,67108863),M._ishlnsubmul(E,de,ie);M.negative!==0;)de--,M.negative=0,M._ishlnsubmul(E,1,ie),M.isZero()||(M.negative^=1);v&&(v.words[ie]=de)}return v&&v._strip(),M._strip(),m!=="div"&&x!==0&&M.iushrn(x),{div:v||null,mod:M}},o.prototype.divmod=function(d,m,x){if(i(!d.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var M,E,O;return this.negative!==0&&d.negative===0?(O=this.neg().divmod(d,m),m!=="mod"&&(M=O.div.neg()),m!=="div"&&(E=O.mod.neg(),x&&E.negative!==0&&E.iadd(d)),{div:M,mod:E}):this.negative===0&&d.negative!==0?(O=this.divmod(d.neg(),m),m!=="mod"&&(M=O.div.neg()),{div:M,mod:O.mod}):this.negative&d.negative?(O=this.neg().divmod(d.neg(),m),m!=="div"&&(E=O.mod.neg(),x&&E.negative!==0&&E.isub(d)),{div:O.div,mod:E}):d.length>this.length||this.cmp(d)<0?{div:new o(0),mod:this}:d.length===1?m==="div"?{div:this.divn(d.words[0]),mod:null}:m==="mod"?{div:null,mod:new o(this.modrn(d.words[0]))}:{div:this.divn(d.words[0]),mod:new o(this.modrn(d.words[0]))}:this._wordDiv(d,m)},o.prototype.div=function(d){return this.divmod(d,"div",!1).div},o.prototype.mod=function(d){return this.divmod(d,"mod",!1).mod},o.prototype.umod=function(d){return this.divmod(d,"mod",!0).mod},o.prototype.divRound=function(d){var m=this.divmod(d);if(m.mod.isZero())return m.div;var x=m.div.negative!==0?m.mod.isub(d):m.mod,M=d.ushrn(1),E=d.andln(1),O=x.cmp(M);return O<0||E===1&&O===0?m.div:m.div.negative!==0?m.div.isubn(1):m.div.iaddn(1)},o.prototype.modrn=function(d){var m=d<0;m&&(d=-d),i(d<=67108863);for(var x=(1<<26)%d,M=0,E=this.length-1;E>=0;E--)M=(x*M+(this.words[E]|0))%d;return m?-M:M},o.prototype.modn=function(d){return this.modrn(d)},o.prototype.idivn=function(d){var m=d<0;m&&(d=-d),i(d<=67108863);for(var x=0,M=this.length-1;M>=0;M--){var E=(this.words[M]|0)+x*67108864;this.words[M]=E/d|0,x=E%d}return this._strip(),m?this.ineg():this},o.prototype.divn=function(d){return this.clone().idivn(d)},o.prototype.egcd=function(d){i(d.negative===0),i(!d.isZero());var m=this,x=d.clone();m.negative!==0?m=m.umod(d):m=m.clone();for(var M=new o(1),E=new o(0),O=new o(0),C=new o(1),g=0;m.isEven()&&x.isEven();)m.iushrn(1),x.iushrn(1),++g;for(var v=x.clone(),j=m.clone();!m.isZero();){for(var ee=0,ie=1;!(m.words[0]&ie)&&ee<26;++ee,ie<<=1);if(ee>0)for(m.iushrn(ee);ee-- >0;)(M.isOdd()||E.isOdd())&&(M.iadd(v),E.isub(j)),M.iushrn(1),E.iushrn(1);for(var de=0,ye=1;!(x.words[0]&ye)&&de<26;++de,ye<<=1);if(de>0)for(x.iushrn(de);de-- >0;)(O.isOdd()||C.isOdd())&&(O.iadd(v),C.isub(j)),O.iushrn(1),C.iushrn(1);m.cmp(x)>=0?(m.isub(x),M.isub(O),E.isub(C)):(x.isub(m),O.isub(M),C.isub(E))}return{a:O,b:C,gcd:x.iushln(g)}},o.prototype._invmp=function(d){i(d.negative===0),i(!d.isZero());var m=this,x=d.clone();m.negative!==0?m=m.umod(d):m=m.clone();for(var M=new o(1),E=new o(0),O=x.clone();m.cmpn(1)>0&&x.cmpn(1)>0;){for(var C=0,g=1;!(m.words[0]&g)&&C<26;++C,g<<=1);if(C>0)for(m.iushrn(C);C-- >0;)M.isOdd()&&M.iadd(O),M.iushrn(1);for(var v=0,j=1;!(x.words[0]&j)&&v<26;++v,j<<=1);if(v>0)for(x.iushrn(v);v-- >0;)E.isOdd()&&E.iadd(O),E.iushrn(1);m.cmp(x)>=0?(m.isub(x),M.isub(E)):(x.isub(m),E.isub(M))}var ee;return m.cmpn(1)===0?ee=M:ee=E,ee.cmpn(0)<0&&ee.iadd(d),ee},o.prototype.gcd=function(d){if(this.isZero())return d.abs();if(d.isZero())return this.abs();var m=this.clone(),x=d.clone();m.negative=0,x.negative=0;for(var M=0;m.isEven()&&x.isEven();M++)m.iushrn(1),x.iushrn(1);do{for(;m.isEven();)m.iushrn(1);for(;x.isEven();)x.iushrn(1);var E=m.cmp(x);if(E<0){var O=m;m=x,x=O}else if(E===0||x.cmpn(1)===0)break;m.isub(x)}while(!0);return x.iushln(M)},o.prototype.invm=function(d){return this.egcd(d).a.umod(d)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(d){return this.words[0]&d},o.prototype.bincn=function(d){i(typeof d=="number");var m=d%26,x=(d-m)/26,M=1<<m;if(this.length<=x)return this._expand(x+1),this.words[x]|=M,this;for(var E=M,O=x;E!==0&&O<this.length;O++){var C=this.words[O]|0;C+=E,E=C>>>26,C&=67108863,this.words[O]=C}return E!==0&&(this.words[O]=E,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(d){var m=d<0;if(this.negative!==0&&!m)return-1;if(this.negative===0&&m)return 1;this._strip();var x;if(this.length>1)x=1;else{m&&(d=-d),i(d<=67108863,"Number is too big");var M=this.words[0]|0;x=M===d?0:M<d?-1:1}return this.negative!==0?-x|0:x},o.prototype.cmp=function(d){if(this.negative!==0&&d.negative===0)return-1;if(this.negative===0&&d.negative!==0)return 1;var m=this.ucmp(d);return this.negative!==0?-m|0:m},o.prototype.ucmp=function(d){if(this.length>d.length)return 1;if(this.length<d.length)return-1;for(var m=0,x=this.length-1;x>=0;x--){var M=this.words[x]|0,E=d.words[x]|0;if(M!==E){M<E?m=-1:M>E&&(m=1);break}}return m},o.prototype.gtn=function(d){return this.cmpn(d)===1},o.prototype.gt=function(d){return this.cmp(d)===1},o.prototype.gten=function(d){return this.cmpn(d)>=0},o.prototype.gte=function(d){return this.cmp(d)>=0},o.prototype.ltn=function(d){return this.cmpn(d)===-1},o.prototype.lt=function(d){return this.cmp(d)===-1},o.prototype.lten=function(d){return this.cmpn(d)<=0},o.prototype.lte=function(d){return this.cmp(d)<=0},o.prototype.eqn=function(d){return this.cmpn(d)===0},o.prototype.eq=function(d){return this.cmp(d)===0},o.red=function(d){return new V(d)},o.prototype.toRed=function(d){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),d.convertTo(this)._forceRed(d)},o.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(d){return this.red=d,this},o.prototype.forceRed=function(d){return i(!this.red,"Already a number in reduction context"),this._forceRed(d)},o.prototype.redAdd=function(d){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,d)},o.prototype.redIAdd=function(d){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,d)},o.prototype.redSub=function(d){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,d)},o.prototype.redISub=function(d){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,d)},o.prototype.redShl=function(d){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,d)},o.prototype.redMul=function(d){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,d),this.red.mul(this,d)},o.prototype.redIMul=function(d){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,d),this.red.imul(this,d)},o.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(d){return i(this.red&&!d.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,d)};var G={k256:null,p224:null,p192:null,p25519:null};function q(p,d){this.name=p,this.p=new o(d,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}q.prototype._tmp=function(){var d=new o(null);return d.words=new Array(Math.ceil(this.n/13)),d},q.prototype.ireduce=function(d){var m=d,x;do this.split(m,this.tmp),m=this.imulK(m),m=m.iadd(this.tmp),x=m.bitLength();while(x>this.n);var M=x<this.n?-1:m.ucmp(this.p);return M===0?(m.words[0]=0,m.length=1):M>0?m.isub(this.p):m.strip!==void 0?m.strip():m._strip(),m},q.prototype.split=function(d,m){d.iushrn(this.n,0,m)},q.prototype.imulK=function(d){return d.imul(this.k)};function X(){q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(X,q),X.prototype.split=function(d,m){for(var x=4194303,M=Math.min(d.length,9),E=0;E<M;E++)m.words[E]=d.words[E];if(m.length=M,d.length<=9){d.words[0]=0,d.length=1;return}var O=d.words[9];for(m.words[m.length++]=O&x,E=10;E<d.length;E++){var C=d.words[E]|0;d.words[E-10]=(C&x)<<4|O>>>22,O=C}O>>>=22,d.words[E-10]=O,O===0&&d.length>10?d.length-=10:d.length-=9},X.prototype.imulK=function(d){d.words[d.length]=0,d.words[d.length+1]=0,d.length+=2;for(var m=0,x=0;x<d.length;x++){var M=d.words[x]|0;m+=M*977,d.words[x]=m&67108863,m=M*64+(m/67108864|0)}return d.words[d.length-1]===0&&(d.length--,d.words[d.length-1]===0&&d.length--),d};function ne(){q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(ne,q);function ae(){q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(ae,q);function ce(){q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(ce,q),ce.prototype.imulK=function(d){for(var m=0,x=0;x<d.length;x++){var M=(d.words[x]|0)*19+m,E=M&67108863;M>>>=26,d.words[x]=E,m=M}return m!==0&&(d.words[d.length++]=m),d},o._prime=function(d){if(G[d])return G[d];var m;if(d==="k256")m=new X;else if(d==="p224")m=new ne;else if(d==="p192")m=new ae;else if(d==="p25519")m=new ce;else throw new Error("Unknown prime "+d);return G[d]=m,m};function V(p){if(typeof p=="string"){var d=o._prime(p);this.m=d.p,this.prime=d}else i(p.gtn(1),"modulus must be greater than 1"),this.m=p,this.prime=null}V.prototype._verify1=function(d){i(d.negative===0,"red works only with positives"),i(d.red,"red works only with red numbers")},V.prototype._verify2=function(d,m){i((d.negative|m.negative)===0,"red works only with positives"),i(d.red&&d.red===m.red,"red works only with red numbers")},V.prototype.imod=function(d){return this.prime?this.prime.ireduce(d)._forceRed(this):(f(d,d.umod(this.m)._forceRed(this)),d)},V.prototype.neg=function(d){return d.isZero()?d.clone():this.m.sub(d)._forceRed(this)},V.prototype.add=function(d,m){this._verify2(d,m);var x=d.add(m);return x.cmp(this.m)>=0&&x.isub(this.m),x._forceRed(this)},V.prototype.iadd=function(d,m){this._verify2(d,m);var x=d.iadd(m);return x.cmp(this.m)>=0&&x.isub(this.m),x},V.prototype.sub=function(d,m){this._verify2(d,m);var x=d.sub(m);return x.cmpn(0)<0&&x.iadd(this.m),x._forceRed(this)},V.prototype.isub=function(d,m){this._verify2(d,m);var x=d.isub(m);return x.cmpn(0)<0&&x.iadd(this.m),x},V.prototype.shl=function(d,m){return this._verify1(d),this.imod(d.ushln(m))},V.prototype.imul=function(d,m){return this._verify2(d,m),this.imod(d.imul(m))},V.prototype.mul=function(d,m){return this._verify2(d,m),this.imod(d.mul(m))},V.prototype.isqr=function(d){return this.imul(d,d.clone())},V.prototype.sqr=function(d){return this.mul(d,d)},V.prototype.sqrt=function(d){if(d.isZero())return d.clone();var m=this.m.andln(3);if(i(m%2===1),m===3){var x=this.m.add(new o(1)).iushrn(2);return this.pow(d,x)}for(var M=this.m.subn(1),E=0;!M.isZero()&&M.andln(1)===0;)E++,M.iushrn(1);i(!M.isZero());var O=new o(1).toRed(this),C=O.redNeg(),g=this.m.subn(1).iushrn(1),v=this.m.bitLength();for(v=new o(2*v*v).toRed(this);this.pow(v,g).cmp(C)!==0;)v.redIAdd(C);for(var j=this.pow(v,M),ee=this.pow(d,M.addn(1).iushrn(1)),ie=this.pow(d,M),de=E;ie.cmp(O)!==0;){for(var ye=ie,Ee=0;ye.cmp(O)!==0;Ee++)ye=ye.redSqr();i(Ee<de);var Se=this.pow(j,new o(1).iushln(de-Ee-1));ee=ee.redMul(Se),j=Se.redSqr(),ie=ie.redMul(j),de=Ee}return ee},V.prototype.invm=function(d){var m=d._invmp(this.m);return m.negative!==0?(m.negative=0,this.imod(m).redNeg()):this.imod(m)},V.prototype.pow=function(d,m){if(m.isZero())return new o(1).toRed(this);if(m.cmpn(1)===0)return d.clone();var x=4,M=new Array(1<<x);M[0]=new o(1).toRed(this),M[1]=d;for(var E=2;E<M.length;E++)M[E]=this.mul(M[E-1],d);var O=M[0],C=0,g=0,v=m.bitLength()%26;for(v===0&&(v=26),E=m.length-1;E>=0;E--){for(var j=m.words[E],ee=v-1;ee>=0;ee--){var ie=j>>ee&1;if(O!==M[0]&&(O=this.sqr(O)),ie===0&&C===0){g=0;continue}C<<=1,C|=ie,g++,!(g!==x&&(E!==0||ee!==0))&&(O=this.mul(O,M[C]),g=0,C=0)}v=26}return O},V.prototype.convertTo=function(d){var m=d.umod(this.m);return m===d?m.clone():m},V.prototype.convertFrom=function(d){var m=d.clone();return m.red=null,m},o.mont=function(d){return new D(d)};function D(p){V.call(this,p),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}s(D,V),D.prototype.convertTo=function(d){return this.imod(d.ushln(this.shift))},D.prototype.convertFrom=function(d){var m=this.imod(d.mul(this.rinv));return m.red=null,m},D.prototype.imul=function(d,m){if(d.isZero()||m.isZero())return d.words[0]=0,d.length=1,d;var x=d.imul(m),M=x.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),E=x.isub(M).iushrn(this.shift),O=E;return E.cmp(this.m)>=0?O=E.isub(this.m):E.cmpn(0)<0&&(O=E.iadd(this.m)),O._forceRed(this)},D.prototype.mul=function(d,m){if(d.isZero()||m.isZero())return new o(0)._forceRed(this);var x=d.mul(m),M=x.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),E=x.isub(M).iushrn(this.shift),O=E;return E.cmp(this.m)>=0?O=E.isub(this.m):E.cmpn(0)<0&&(O=E.iadd(this.m)),O._forceRed(this)},D.prototype.invm=function(d){var m=this.imod(d._invmp(this.m).mul(this.r2));return m._forceRed(this)}})(typeof t>"u"||t,e)}}),Ao=9e15,ys=1e9,Qd="0123456789abcdef",Bu="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Lu="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",eh={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ao,maxE:Ao,crypto:!1},w4,Ti,ct=!0,Al="[DecimalError] ",us=Al+"Invalid argument: ",_4=Al+"Precision limit exceeded",x4=Al+"crypto unavailable",S4="[object Decimal]",Or=Math.floor,pr=Math.pow,M9=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,A9=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,T9=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,E4=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,In=1e7,Qe=7,O9=9007199254740991,I9=Bu.length-1,th=Lu.length-1,be={toStringTag:S4};be.absoluteValue=be.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Xe(e)};be.ceil=function(){return Xe(new this.constructor(this),this.e+1,2)};be.clampedTo=be.clamp=function(e,t){var r,n=this,i=n.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(us+t);return r=n.cmp(e),r<0?e:n.cmp(t)>0?t:new i(n)};be.comparedTo=be.cmp=function(e){var t,r,n,i,s=this,o=s.d,a=(e=new s.constructor(e)).d,c=s.s,u=e.s;if(!o||!a)return!c||!u?NaN:c!==u?c:o===a?0:!o^c<0?1:-1;if(!o[0]||!a[0])return o[0]?c:a[0]?-u:0;if(c!==u)return c;if(s.e!==e.e)return s.e>e.e^c<0?1:-1;for(n=o.length,i=a.length,t=0,r=n<i?n:i;t<r;++t)if(o[t]!==a[t])return o[t]>a[t]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};be.cosine=be.cos=function(){var e,t,r=this,n=r.constructor;return r.d?r.d[0]?(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+Qe,n.rounding=1,r=P9(n,O4(n,r)),n.precision=e,n.rounding=t,Xe(Ti==2||Ti==3?r.neg():r,e,t,!0)):new n(1):new n(NaN)};be.cubeRoot=be.cbrt=function(){var e,t,r,n,i,s,o,a,c,u,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(ct=!1,s=l.s*pr(l.s*l,1/3),!s||Math.abs(s)==1/0?(r=xr(l.d),e=l.e,(s=(e-r.length+1)%3)&&(r+=s==1||s==-2?"0":"00"),s=pr(r,1/3),e=Or((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?r="5e"+e:(r=s.toExponential(),r=r.slice(0,r.indexOf("e")+1)+e),n=new f(r),n.s=l.s):n=new f(s.toString()),o=(e=f.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=Vt(u.plus(l).times(a),u.plus(c),o+2,1),xr(a.d).slice(0,o)===(r=xr(n.d)).slice(0,o))if(r=r.slice(o-3,o+1),r=="9999"||!i&&r=="4999"){if(!i&&(Xe(a,e+1,0),a.times(a).times(a).eq(l))){n=a;break}o+=4,i=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(Xe(n,e+1,1),t=!n.times(n).times(n).eq(l));break}return ct=!0,Xe(n,e,f.rounding,t)};be.decimalPlaces=be.dp=function(){var e,t=this.d,r=NaN;if(t){if(e=t.length-1,r=(e-Or(this.e/Qe))*Qe,e=t[e],e)for(;e%10==0;e/=10)r--;r<0&&(r=0)}return r};be.dividedBy=be.div=function(e){return Vt(this,new this.constructor(e))};be.dividedToIntegerBy=be.divToInt=function(e){var t=this,r=t.constructor;return Xe(Vt(t,new r(e),0,1,1),r.precision,r.rounding)};be.equals=be.eq=function(e){return this.cmp(e)===0};be.floor=function(){return Xe(new this.constructor(this),this.e+1,3)};be.greaterThan=be.gt=function(e){return this.cmp(e)>0};be.greaterThanOrEqualTo=be.gte=function(e){var t=this.cmp(e);return t==1||t===0};be.hyperbolicCosine=be.cosh=function(){var e,t,r,n,i,s=this,o=s.constructor,a=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return a;r=o.precision,n=o.rounding,o.precision=r+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(e=Math.ceil(i/3),t=(1/Ol(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=Lo(o,1,s.times(t),new o(1),!0);for(var c,u=e,l=new o(8);u--;)c=s.times(s),s=a.minus(c.times(l.minus(c.times(l))));return Xe(s,o.precision=r,o.rounding=n,!0)};be.hyperbolicSine=be.sinh=function(){var e,t,r,n,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(t=s.precision,r=s.rounding,s.precision=t+Math.max(i.e,i.sd())+4,s.rounding=1,n=i.d.length,n<3)i=Lo(s,2,i,i,!0);else{e=1.4*Math.sqrt(n),e=e>16?16:e|0,i=i.times(1/Ol(5,e)),i=Lo(s,2,i,i,!0);for(var o,a=new s(5),c=new s(16),u=new s(20);e--;)o=i.times(i),i=i.times(a.plus(o.times(c.times(o).plus(u))))}return s.precision=t,s.rounding=r,Xe(i,t,r,!0)};be.hyperbolicTangent=be.tanh=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+7,n.rounding=1,Vt(r.sinh(),r.cosh(),n.precision=e,n.rounding=t)):new n(r.s)};be.inverseCosine=be.acos=function(){var e,t=this,r=t.constructor,n=t.abs().cmp(1),i=r.precision,s=r.rounding;return n!==-1?n===0?t.isNeg()?Mn(r,i,s):new r(0):new r(NaN):t.isZero()?Mn(r,i+4,s).times(.5):(r.precision=i+6,r.rounding=1,t=t.asin(),e=Mn(r,i+4,s).times(.5),r.precision=i,r.rounding=s,e.minus(t))};be.inverseHyperbolicCosine=be.acosh=function(){var e,t,r=this,n=r.constructor;return r.lte(1)?new n(r.eq(1)?0:NaN):r.isFinite()?(e=n.precision,t=n.rounding,n.precision=e+Math.max(Math.abs(r.e),r.sd())+4,n.rounding=1,ct=!1,r=r.times(r).minus(1).sqrt().plus(r),ct=!0,n.precision=e,n.rounding=t,r.ln()):new n(r)};be.inverseHyperbolicSine=be.asinh=function(){var e,t,r=this,n=r.constructor;return!r.isFinite()||r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+2*Math.max(Math.abs(r.e),r.sd())+6,n.rounding=1,ct=!1,r=r.times(r).plus(1).sqrt().plus(r),ct=!0,n.precision=e,n.rounding=t,r.ln())};be.inverseHyperbolicTangent=be.atanh=function(){var e,t,r,n,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=s.precision,t=s.rounding,n=i.sd(),Math.max(n,e)<2*-i.e-1?Xe(new s(i),e,t,!0):(s.precision=r=n-i.e,i=Vt(i.plus(1),new s(1).minus(i),r+e,1),s.precision=e+4,s.rounding=1,i=i.ln(),s.precision=e,s.rounding=t,i.times(.5))):new s(NaN)};be.inverseSine=be.asin=function(){var e,t,r,n,i=this,s=i.constructor;return i.isZero()?new s(i):(t=i.abs().cmp(1),r=s.precision,n=s.rounding,t!==-1?t===0?(e=Mn(s,r+4,n).times(.5),e.s=i.s,e):new s(NaN):(s.precision=r+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=r,s.rounding=n,i.times(2)))};be.inverseTangent=be.atan=function(){var e,t,r,n,i,s,o,a,c,u=this,l=u.constructor,f=l.precision,h=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&f+4<=th)return o=Mn(l,f+4,h).times(.25),o.s=u.s,o}else{if(!u.s)return new l(NaN);if(f+4<=th)return o=Mn(l,f+4,h).times(.5),o.s=u.s,o}for(l.precision=a=f+10,l.rounding=1,r=Math.min(28,a/Qe+2|0),e=r;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(ct=!1,t=Math.ceil(a/Qe),n=1,c=u.times(u),o=new l(u),i=u;e!==-1;)if(i=i.times(c),s=o.minus(i.div(n+=2)),i=i.times(c),o=s.plus(i.div(n+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===s.d[e]&&e--;);return r&&(o=o.times(2<<r-1)),ct=!0,Xe(o,l.precision=f,l.rounding=h,!0)};be.isFinite=function(){return!!this.d};be.isInteger=be.isInt=function(){return!!this.d&&Or(this.e/Qe)>this.d.length-2};be.isNaN=function(){return!this.s};be.isNegative=be.isNeg=function(){return this.s<0};be.isPositive=be.isPos=function(){return this.s>0};be.isZero=function(){return!!this.d&&this.d[0]===0};be.lessThan=be.lt=function(e){return this.cmp(e)<0};be.lessThanOrEqualTo=be.lte=function(e){return this.cmp(e)<1};be.logarithm=be.log=function(e){var t,r,n,i,s,o,a,c,u=this,l=u.constructor,f=l.precision,h=l.rounding,y=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),r=e.d,e.s<0||!r||!r[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(r=u.d,u.s<0||!r||!r[0]||u.eq(1))return new l(r&&!r[0]?-1/0:u.s!=1?NaN:r?0:1/0);if(t)if(r.length>1)s=!0;else{for(i=r[0];i%10===0;)i/=10;s=i!==1}if(ct=!1,a=f+y,o=ts(u,a),n=t?Fu(l,a+10):ts(e,a),c=Vt(o,n,a,1),nc(c.d,i=f,h))do if(a+=10,o=ts(u,a),n=t?Fu(l,a+10):ts(e,a),c=Vt(o,n,a,1),!s){+xr(c.d).slice(i+1,i+15)+1==1e14&&(c=Xe(c,f+1,0));break}while(nc(c.d,i+=10,h));return ct=!0,Xe(c,f,h)};be.minus=be.sub=function(e){var t,r,n,i,s,o,a,c,u,l,f,h,y=this,b=y.constructor;if(e=new b(e),!y.d||!e.d)return!y.s||!e.s?e=new b(NaN):y.d?e.s=-e.s:e=new b(e.d||y.s!==e.s?y:NaN),e;if(y.s!=e.s)return e.s=-e.s,y.plus(e);if(u=y.d,h=e.d,a=b.precision,c=b.rounding,!u[0]||!h[0]){if(h[0])e.s=-e.s;else if(u[0])e=new b(y);else return new b(c===3?-0:0);return ct?Xe(e,a,c):e}if(r=Or(e.e/Qe),l=Or(y.e/Qe),u=u.slice(),s=l-r,s){for(f=s<0,f?(t=u,s=-s,o=h.length):(t=h,r=l,o=u.length),n=Math.max(Math.ceil(a/Qe),o)+2,s>n&&(s=n,t.length=1),t.reverse(),n=s;n--;)t.push(0);t.reverse()}else{for(n=u.length,o=h.length,f=n<o,f&&(o=n),n=0;n<o;n++)if(u[n]!=h[n]){f=u[n]<h[n];break}s=0}for(f&&(t=u,u=h,h=t,e.s=-e.s),o=u.length,n=h.length-o;n>0;--n)u[o++]=0;for(n=h.length;n>s;){if(u[--n]<h[n]){for(i=n;i&&u[--i]===0;)u[i]=In-1;--u[i],u[n]+=In}u[n]-=h[n]}for(;u[--o]===0;)u.pop();for(;u[0]===0;u.shift())--r;return u[0]?(e.d=u,e.e=Tl(u,r),ct?Xe(e,a,c):e):new b(c===3?-0:0)};be.modulo=be.mod=function(e){var t,r=this,n=r.constructor;return e=new n(e),!r.d||!e.s||e.d&&!e.d[0]?new n(NaN):!e.d||r.d&&!r.d[0]?Xe(new n(r),n.precision,n.rounding):(ct=!1,n.modulo==9?(t=Vt(r,e.abs(),0,3,1),t.s*=e.s):t=Vt(r,e,0,n.modulo,1),t=t.times(e),ct=!0,r.minus(t))};be.naturalExponential=be.exp=function(){return rh(this)};be.naturalLogarithm=be.ln=function(){return ts(this)};be.negated=be.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Xe(e)};be.plus=be.add=function(e){var t,r,n,i,s,o,a,c,u,l,f=this,h=f.constructor;if(e=new h(e),!f.d||!e.d)return!f.s||!e.s?e=new h(NaN):f.d||(e=new h(e.d||f.s===e.s?f:NaN)),e;if(f.s!=e.s)return e.s=-e.s,f.minus(e);if(u=f.d,l=e.d,a=h.precision,c=h.rounding,!u[0]||!l[0])return l[0]||(e=new h(f)),ct?Xe(e,a,c):e;if(s=Or(f.e/Qe),n=Or(e.e/Qe),u=u.slice(),i=s-n,i){for(i<0?(r=u,i=-i,o=l.length):(r=l,n=s,o=u.length),s=Math.ceil(a/Qe),o=s>o?s+1:o+1,i>o&&(i=o,r.length=1),r.reverse();i--;)r.push(0);r.reverse()}for(o=u.length,i=l.length,o-i<0&&(i=o,r=l,l=u,u=r),t=0;i;)t=(u[--i]=u[i]+l[i]+t)/In|0,u[i]%=In;for(t&&(u.unshift(t),++n),o=u.length;u[--o]==0;)u.pop();return e.d=u,e.e=Tl(u,n),ct?Xe(e,a,c):e};be.precision=be.sd=function(e){var t,r=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(us+e);return r.d?(t=C4(r.d),e&&r.e+1>t&&(t=r.e+1)):t=NaN,t};be.round=function(){var e=this,t=e.constructor;return Xe(new t(e),e.e+1,t.rounding)};be.sine=be.sin=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+Qe,n.rounding=1,r=k9(n,O4(n,r)),n.precision=e,n.rounding=t,Xe(Ti>2?r.neg():r,e,t,!0)):new n(NaN)};be.squareRoot=be.sqrt=function(){var e,t,r,n,i,s,o=this,a=o.d,c=o.e,u=o.s,l=o.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?o:1/0);for(ct=!1,u=Math.sqrt(+o),u==0||u==1/0?(t=xr(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=Or((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),n=new l(t)):n=new l(u.toString()),r=(c=l.precision)+3;;)if(s=n,n=s.plus(Vt(o,s,r+2,1)).times(.5),xr(s.d).slice(0,r)===(t=xr(n.d)).slice(0,r))if(t=t.slice(r-3,r+1),t=="9999"||!i&&t=="4999"){if(!i&&(Xe(s,c+1,0),s.times(s).eq(o))){n=s;break}r+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(Xe(n,c+1,1),e=!n.times(n).eq(o));break}return ct=!0,Xe(n,c,l.rounding,e)};be.tangent=be.tan=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+10,n.rounding=1,r=r.sin(),r.s=1,r=Vt(r,new n(1).minus(r.times(r)).sqrt(),e+10,0),n.precision=e,n.rounding=t,Xe(Ti==2||Ti==4?r.neg():r,e,t,!0)):new n(NaN)};be.times=be.mul=function(e){var t,r,n,i,s,o,a,c,u,l=this,f=l.constructor,h=l.d,y=(e=new f(e)).d;if(e.s*=l.s,!h||!h[0]||!y||!y[0])return new f(!e.s||h&&!h[0]&&!y||y&&!y[0]&&!h?NaN:!h||!y?e.s/0:e.s*0);for(r=Or(l.e/Qe)+Or(e.e/Qe),c=h.length,u=y.length,c<u&&(s=h,h=y,y=s,o=c,c=u,u=o),s=[],o=c+u,n=o;n--;)s.push(0);for(n=u;--n>=0;){for(t=0,i=c+n;i>n;)a=s[i]+y[n]*h[i-n-1]+t,s[i--]=a%In|0,t=a/In|0;s[i]=(s[i]+t)%In|0}for(;!s[--o];)s.pop();return t?++r:s.shift(),e.d=s,e.e=Tl(s,r),ct?Xe(e,f.precision,f.rounding):e};be.toBinary=function(e,t){return s0(this,2,e,t)};be.toDecimalPlaces=be.toDP=function(e,t){var r=this,n=r.constructor;return r=new n(r),e===void 0?r:(qr(e,0,ys),t===void 0?t=n.rounding:qr(t,0,8),Xe(r,e+r.e+1,t))};be.toExponential=function(e,t){var r,n=this,i=n.constructor;return e===void 0?r=ri(n,!0):(qr(e,0,ys),t===void 0?t=i.rounding:qr(t,0,8),n=Xe(new i(n),e+1,t),r=ri(n,!0,e+1)),n.isNeg()&&!n.isZero()?"-"+r:r};be.toFixed=function(e,t){var r,n,i=this,s=i.constructor;return e===void 0?r=ri(i):(qr(e,0,ys),t===void 0?t=s.rounding:qr(t,0,8),n=Xe(new s(i),e+i.e+1,t),r=ri(n,!1,e+n.e+1)),i.isNeg()&&!i.isZero()?"-"+r:r};be.toFraction=function(e){var t,r,n,i,s,o,a,c,u,l,f,h,y=this,b=y.d,w=y.constructor;if(!b)return new w(y);if(u=r=new w(1),n=c=new w(0),t=new w(n),s=t.e=C4(b)-y.e-1,o=s%Qe,t.d[0]=pr(10,o<0?Qe+o:o),e==null)e=s>0?t:u;else{if(a=new w(e),!a.isInt()||a.lt(u))throw Error(us+a);e=a.gt(t)?s>0?t:u:a}for(ct=!1,a=new w(xr(b)),l=w.precision,w.precision=s=b.length*Qe*2;f=Vt(a,t,0,1,1),i=r.plus(f.times(n)),i.cmp(e)!=1;)r=n,n=i,i=u,u=c.plus(f.times(i)),c=i,i=t,t=a.minus(f.times(i)),a=i;return i=Vt(e.minus(r),n,0,1,1),c=c.plus(i.times(u)),r=r.plus(i.times(n)),c.s=u.s=y.s,h=Vt(u,n,s,1).minus(y).abs().cmp(Vt(c,r,s,1).minus(y).abs())<1?[u,n]:[c,r],w.precision=l,ct=!0,h};be.toHexadecimal=be.toHex=function(e,t){return s0(this,16,e,t)};be.toNearest=function(e,t){var r=this,n=r.constructor;if(r=new n(r),e==null){if(!r.d)return r;e=new n(1),t=n.rounding}else{if(e=new n(e),t===void 0?t=n.rounding:qr(t,0,8),!r.d)return e.s?r:e;if(!e.d)return e.s&&(e.s=r.s),e}return e.d[0]?(ct=!1,r=Vt(r,e,0,t,1).times(e),ct=!0,Xe(r)):(e.s=r.s,r=e),r};be.toNumber=function(){return+this};be.toOctal=function(e,t){return s0(this,8,e,t)};be.toPower=be.pow=function(e){var t,r,n,i,s,o,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(pr(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,s=c.rounding,e.eq(1))return Xe(a,n,s);if(t=Or(e.e/Qe),t>=e.d.length-1&&(r=u<0?-u:u)<=O9)return i=M4(c,a,r,n),e.s<0?new c(1).div(i):Xe(i,n,s);if(o=a.s,o<0){if(t<e.d.length-1)return new c(NaN);if(e.d[t]&1||(o=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=o,a}return r=pr(+a,u),t=r==0||!isFinite(r)?Or(u*(Math.log("0."+xr(a.d))/Math.LN10+a.e+1)):new c(r+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(ct=!1,c.rounding=a.s=1,r=Math.min(12,(t+"").length),i=rh(e.times(ts(a,n+r)),n),i.d&&(i=Xe(i,n+5,1),nc(i.d,n,s)&&(t=n+10,i=Xe(rh(e.times(ts(a,t+r)),t),t+5,1),+xr(i.d).slice(n+1,n+15)+1==1e14&&(i=Xe(i,n+1,0)))),i.s=o,ct=!0,c.rounding=s,Xe(i,n,s))};be.toPrecision=function(e,t){var r,n=this,i=n.constructor;return e===void 0?r=ri(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(qr(e,1,ys),t===void 0?t=i.rounding:qr(t,0,8),n=Xe(new i(n),e,t),r=ri(n,e<=n.e||n.e<=i.toExpNeg,e)),n.isNeg()&&!n.isZero()?"-"+r:r};be.toSignificantDigits=be.toSD=function(e,t){var r=this,n=r.constructor;return e===void 0?(e=n.precision,t=n.rounding):(qr(e,1,ys),t===void 0?t=n.rounding:qr(t,0,8)),Xe(new n(r),e,t)};be.toString=function(){var e=this,t=e.constructor,r=ri(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+r:r};be.truncated=be.trunc=function(){return Xe(new this.constructor(this),this.e+1,1)};be.valueOf=be.toJSON=function(){var e=this,t=e.constructor,r=ri(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+r:r};function xr(e){var t,r,n,i=e.length-1,s="",o=e[0];if(i>0){for(s+=o,t=1;t<i;t++)n=e[t]+"",r=Qe-n.length,r&&(s+=Zi(r)),s+=n;o=e[t],n=o+"",r=Qe-n.length,r&&(s+=Zi(r))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function qr(e,t,r){if(e!==~~e||e<t||e>r)throw Error(us+e)}function nc(e,t,r,n){var i,s,o,a;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Qe,i=0):(i=Math.ceil((t+1)/Qe),t%=Qe),s=pr(10,Qe-t),a=e[i]%s|0,n==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),o=r<4&&a==99999||r>3&&a==49999||a==5e4||a==0):o=(r<4&&a+1==s||r>3&&a+1==s/2)&&(e[i+1]/s/100|0)==pr(10,t-2)-1||(a==s/2||a==0)&&(e[i+1]/s/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),o=(n||r<4)&&a==9999||!n&&r>3&&a==4999):o=((n||r<4)&&a+1==s||!n&&r>3&&a+1==s/2)&&(e[i+1]/s/1e3|0)==pr(10,t-3)-1,o}function lu(e,t,r){for(var n,i=[0],s,o=0,a=e.length;o<a;){for(s=i.length;s--;)i[s]*=t;for(i[0]+=Qd.indexOf(e.charAt(o++)),n=0;n<i.length;n++)i[n]>r-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/r|0,i[n]%=r)}return i.reverse()}function P9(e,t){var r,n,i;if(t.isZero())return t;n=t.d.length,n<32?(r=Math.ceil(n/3),i=(1/Ol(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),e.precision+=r,t=Lo(e,1,t.times(i),new e(1));for(var s=r;s--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=r,t}var Vt=function(){function e(n,i,s){var o,a=0,c=n.length;for(n=n.slice();c--;)o=n[c]*i+a,n[c]=o%s|0,a=o/s|0;return a&&n.unshift(a),n}function t(n,i,s,o){var a,c;if(s!=o)c=s>o?1:-1;else for(a=c=0;a<s;a++)if(n[a]!=i[a]){c=n[a]>i[a]?1:-1;break}return c}function r(n,i,s,o){for(var a=0;s--;)n[s]-=a,a=n[s]<i[s]?1:0,n[s]=a*o+n[s]-i[s];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,s,o,a,c){var u,l,f,h,y,b,w,T,P,k,N,F,L,G,q,X,ne,ae,ce,V,D=n.constructor,p=n.s==i.s?1:-1,d=n.d,m=i.d;if(!d||!d[0]||!m||!m[0])return new D(!n.s||!i.s||(d?m&&d[0]==m[0]:!m)?NaN:d&&d[0]==0||!m?p*0:p/0);for(c?(y=1,l=n.e-i.e):(c=In,y=Qe,l=Or(n.e/y)-Or(i.e/y)),ce=m.length,ne=d.length,P=new D(p),k=P.d=[],f=0;m[f]==(d[f]||0);f++);if(m[f]>(d[f]||0)&&l--,s==null?(G=s=D.precision,o=D.rounding):a?G=s+(n.e-i.e)+1:G=s,G<0)k.push(1),b=!0;else{if(G=G/y+2|0,f=0,ce==1){for(h=0,m=m[0],G++;(f<ne||h)&&G--;f++)q=h*c+(d[f]||0),k[f]=q/m|0,h=q%m|0;b=h||f<ne}else{for(h=c/(m[0]+1)|0,h>1&&(m=e(m,h,c),d=e(d,h,c),ce=m.length,ne=d.length),X=ce,N=d.slice(0,ce),F=N.length;F<ce;)N[F++]=0;V=m.slice(),V.unshift(0),ae=m[0],m[1]>=c/2&&++ae;do h=0,u=t(m,N,ce,F),u<0?(L=N[0],ce!=F&&(L=L*c+(N[1]||0)),h=L/ae|0,h>1?(h>=c&&(h=c-1),w=e(m,h,c),T=w.length,F=N.length,u=t(w,N,T,F),u==1&&(h--,r(w,ce<T?V:m,T,c))):(h==0&&(u=h=1),w=m.slice()),T=w.length,T<F&&w.unshift(0),r(N,w,F,c),u==-1&&(F=N.length,u=t(m,N,ce,F),u<1&&(h++,r(N,ce<F?V:m,F,c))),F=N.length):u===0&&(h++,N=[0]),k[f++]=h,u&&N[0]?N[F++]=d[X]||0:(N=[d[X]],F=1);while((X++<ne||N[0]!==void 0)&&G--);b=N[0]!==void 0}k[0]||k.shift()}if(y==1)P.e=l,w4=b;else{for(f=1,h=k[0];h>=10;h/=10)f++;P.e=f+l*y-1,Xe(P,a?s+P.e+1:s,o,b)}return P}}();function Xe(e,t,r,n){var i,s,o,a,c,u,l,f,h,y=e.constructor;e:if(t!=null){if(f=e.d,!f)return e;for(i=1,a=f[0];a>=10;a/=10)i++;if(s=t-i,s<0)s+=Qe,o=t,l=f[h=0],c=l/pr(10,i-o-1)%10|0;else if(h=Math.ceil((s+1)/Qe),a=f.length,h>=a)if(n){for(;a++<=h;)f.push(0);l=c=0,i=1,s%=Qe,o=s-Qe+1}else break e;else{for(l=a=f[h],i=1;a>=10;a/=10)i++;s%=Qe,o=s-Qe+i,c=o<0?0:l/pr(10,i-o-1)%10|0}if(n=n||t<0||f[h+1]!==void 0||(o<0?l:l%pr(10,i-o-1)),u=r<4?(c||n)&&(r==0||r==(e.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(s>0?o>0?l/pr(10,i-o):0:f[h-1])%10&1||r==(e.s<0?8:7)),t<1||!f[0])return f.length=0,u?(t-=e.e+1,f[0]=pr(10,(Qe-t%Qe)%Qe),e.e=-t||0):f[0]=e.e=0,e;if(s==0?(f.length=h,a=1,h--):(f.length=h+1,a=pr(10,Qe-s),f[h]=o>0?(l/pr(10,i-o)%pr(10,o)|0)*a:0),u)for(;;)if(h==0){for(s=1,o=f[0];o>=10;o/=10)s++;for(o=f[0]+=a,a=1;o>=10;o/=10)a++;s!=a&&(e.e++,f[0]==In&&(f[0]=1));break}else{if(f[h]+=a,f[h]!=In)break;f[h--]=0,a=1}for(s=f.length;f[--s]===0;)f.pop()}return ct&&(e.e>y.maxE?(e.d=null,e.e=NaN):e.e<y.minE&&(e.e=0,e.d=[0])),e}function ri(e,t,r){if(!e.isFinite())return T4(e);var n,i=e.e,s=xr(e.d),o=s.length;return t?(r&&(n=r-o)>0?s=s.charAt(0)+"."+s.slice(1)+Zi(n):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):i<0?(s="0."+Zi(-i-1)+s,r&&(n=r-o)>0&&(s+=Zi(n))):i>=o?(s+=Zi(i+1-o),r&&(n=r-i-1)>0&&(s=s+"."+Zi(n))):((n=i+1)<o&&(s=s.slice(0,n)+"."+s.slice(n)),r&&(n=r-o)>0&&(i+1===o&&(s+="."),s+=Zi(n))),s}function Tl(e,t){var r=e[0];for(t*=Qe;r>=10;r/=10)t++;return t}function Fu(e,t,r){if(t>I9)throw ct=!0,r&&(e.precision=r),Error(_4);return Xe(new e(Bu),t,1,!0)}function Mn(e,t,r){if(t>th)throw Error(_4);return Xe(new e(Lu),t,r,!0)}function C4(e){var t=e.length-1,r=t*Qe+1;if(t=e[t],t){for(;t%10==0;t/=10)r--;for(t=e[0];t>=10;t/=10)r++}return r}function Zi(e){for(var t="";e--;)t+="0";return t}function M4(e,t,r,n){var i,s=new e(1),o=Math.ceil(n/Qe+4);for(ct=!1;;){if(r%2&&(s=s.times(t),gg(s.d,o)&&(i=!0)),r=Or(r/2),r===0){r=s.d.length-1,i&&s.d[r]===0&&++s.d[r];break}t=t.times(t),gg(t.d,o)}return ct=!0,s}function mg(e){return e.d[e.d.length-1]&1}function A4(e,t,r){for(var n,i=new e(t[0]),s=0;++s<t.length;)if(n=new e(t[s]),n.s)i[r](n)&&(i=n);else{i=n;break}return i}function rh(e,t){var r,n,i,s,o,a,c,u=0,l=0,f=0,h=e.constructor,y=h.rounding,b=h.precision;if(!e.d||!e.d[0]||e.e>17)return new h(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(ct=!1,c=b):c=t,a=new h(.03125);e.e>-2;)e=e.times(a),f+=5;for(n=Math.log(pr(2,f))/Math.LN10*2+5|0,c+=n,r=s=o=new h(1),h.precision=c;;){if(s=Xe(s.times(e),c,1),r=r.times(++l),a=o.plus(Vt(s,r,c,1)),xr(a.d).slice(0,c)===xr(o.d).slice(0,c)){for(i=f;i--;)o=Xe(o.times(o),c,1);if(t==null)if(u<3&&nc(o.d,c-n,y,u))h.precision=c+=10,r=s=a=new h(1),l=0,u++;else return Xe(o,h.precision=b,y,ct=!0);else return h.precision=b,o}o=a}}function ts(e,t){var r,n,i,s,o,a,c,u,l,f,h,y=1,b=10,w=e,T=w.d,P=w.constructor,k=P.rounding,N=P.precision;if(w.s<0||!T||!T[0]||!w.e&&T[0]==1&&T.length==1)return new P(T&&!T[0]?-1/0:w.s!=1?NaN:T?0:w);if(t==null?(ct=!1,l=N):l=t,P.precision=l+=b,r=xr(T),n=r.charAt(0),Math.abs(s=w.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)w=w.times(e),r=xr(w.d),n=r.charAt(0),y++;s=w.e,n>1?(w=new P("0."+r),s++):w=new P(n+"."+r.slice(1))}else return u=Fu(P,l+2,N).times(s+""),w=ts(new P(n+"."+r.slice(1)),l-b).plus(u),P.precision=N,t==null?Xe(w,N,k,ct=!0):w;for(f=w,c=o=w=Vt(w.minus(1),w.plus(1),l,1),h=Xe(w.times(w),l,1),i=3;;){if(o=Xe(o.times(h),l,1),u=c.plus(Vt(o,new P(i),l,1)),xr(u.d).slice(0,l)===xr(c.d).slice(0,l))if(c=c.times(2),s!==0&&(c=c.plus(Fu(P,l+2,N).times(s+""))),c=Vt(c,new P(y),l,1),t==null)if(nc(c.d,l-b,k,a))P.precision=l+=b,u=o=w=Vt(f.minus(1),f.plus(1),l,1),h=Xe(w.times(w),l,1),i=a=1;else return Xe(c,P.precision=N,k,ct=!0);else return P.precision=N,c;c=u,i+=2}}function T4(e){return String(e.s*e.s/0)}function nh(e,t){var r,n,i;for((r=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(r<0&&(r=n),r+=+t.slice(n+1),t=t.substring(0,n)):r<0&&(r=t.length),n=0;t.charCodeAt(n)===48;n++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(n,i),t){if(i-=n,e.e=r=r-n-1,e.d=[],n=(r+1)%Qe,r<0&&(n+=Qe),n<i){for(n&&e.d.push(+t.slice(0,n)),i-=Qe;n<i;)e.d.push(+t.slice(n,n+=Qe));t=t.slice(n),n=Qe-t.length}else n-=i;for(;n--;)t+="0";e.d.push(+t),ct&&(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 j9(e,t){var r,n,i,s,o,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),E4.test(t))return nh(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(A9.test(t))r=16,t=t.toLowerCase();else if(M9.test(t))r=2;else if(T9.test(t))r=8;else throw Error(us+t);for(s=t.search(/p/i),s>0?(c=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),o=s>=0,n=e.constructor,o&&(t=t.replace(".",""),a=t.length,s=a-s,i=M4(n,new n(r),s,s*2)),u=lu(t,r,In),l=u.length-1,s=l;u[s]===0;--s)u.pop();return s<0?new n(e.s*0):(e.e=Tl(u,l),e.d=u,ct=!1,o&&(e=Vt(e,i,a*4)),c&&(e=e.times(Math.abs(c)<54?pr(2,c):Sc.pow(2,c))),ct=!0,e)}function k9(e,t){var r,n=t.d.length;if(n<3)return t.isZero()?t:Lo(e,2,t,t);r=1.4*Math.sqrt(n),r=r>16?16:r|0,t=t.times(1/Ol(5,r)),t=Lo(e,2,t,t);for(var i,s=new e(5),o=new e(16),a=new e(20);r--;)i=t.times(t),t=t.times(s.plus(i.times(o.times(i).minus(a))));return t}function Lo(e,t,r,n,i){var s,o,a,c,u=e.precision,l=Math.ceil(u/Qe);for(ct=!1,c=r.times(r),a=new e(n);;){if(o=Vt(a.times(c),new e(t++*t++),u,1),a=i?n.plus(o):n.minus(o),n=Vt(o.times(c),new e(t++*t++),u,1),o=a.plus(n),o.d[l]!==void 0){for(s=l;o.d[s]===a.d[s]&&s--;);if(s==-1)break}s=a,a=n,n=o,o=s}return ct=!0,o.d.length=l+1,o}function Ol(e,t){for(var r=e;--t;)r*=e;return r}function O4(e,t){var r,n=t.s<0,i=Mn(e,e.precision,1),s=i.times(.5);if(t=t.abs(),t.lte(s))return Ti=n?4:1,t;if(r=t.divToInt(i),r.isZero())Ti=n?3:2;else{if(t=t.minus(r.times(i)),t.lte(s))return Ti=mg(r)?n?2:3:n?4:1,t;Ti=mg(r)?n?1:4:n?3:2}return t.minus(i).abs()}function s0(e,t,r,n){var i,s,o,a,c,u,l,f,h,y=e.constructor,b=r!==void 0;if(b?(qr(r,1,ys),n===void 0?n=y.rounding:qr(n,0,8)):(r=y.precision,n=y.rounding),!e.isFinite())l=T4(e);else{for(l=ri(e),o=l.indexOf("."),b?(i=2,t==16?r=r*4-3:t==8&&(r=r*3-2)):i=t,o>=0&&(l=l.replace(".",""),h=new y(1),h.e=l.length-o,h.d=lu(ri(h),10,i),h.e=h.d.length),f=lu(l,10,i),s=c=f.length;f[--c]==0;)f.pop();if(!f[0])l=b?"0p+0":"0";else{if(o<0?s--:(e=new y(e),e.d=f,e.e=s,e=Vt(e,h,r,n,0,i),f=e.d,s=e.e,u=w4),o=f[r],a=i/2,u=u||f[r+1]!==void 0,u=n<4?(o!==void 0||u)&&(n===0||n===(e.s<0?3:2)):o>a||o===a&&(n===4||u||n===6&&f[r-1]&1||n===(e.s<0?8:7)),f.length=r,u)for(;++f[--r]>i-1;)f[r]=0,r||(++s,f.unshift(1));for(c=f.length;!f[c-1];--c);for(o=0,l="";o<c;o++)l+=Qd.charAt(f[o]);if(b){if(c>1)if(t==16||t==8){for(o=t==16?4:3,--c;c%o;c++)l+="0";for(f=lu(l,i,t),c=f.length;!f[c-1];--c);for(o=1,l="1.";o<c;o++)l+=Qd.charAt(f[o])}else l=l.charAt(0)+"."+l.slice(1);l=l+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)l="0"+l;l="0."+l}else if(++s>c)for(s-=c;s--;)l+="0";else s<c&&(l=l.slice(0,s)+"."+l.slice(s))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function gg(e,t){if(e.length>t)return e.length=t,!0}function R9(e){return new this(e).abs()}function N9(e){return new this(e).acos()}function D9(e){return new this(e).acosh()}function $9(e,t){return new this(e).plus(t)}function B9(e){return new this(e).asin()}function L9(e){return new this(e).asinh()}function F9(e){return new this(e).atan()}function U9(e){return new this(e).atanh()}function z9(e,t){e=new this(e),t=new this(t);var r,n=this.precision,i=this.rounding,s=n+4;return!e.s||!t.s?r=new this(NaN):!e.d&&!t.d?(r=Mn(this,s,1).times(t.s>0?.25:.75),r.s=e.s):!t.d||e.isZero()?(r=t.s<0?Mn(this,n,i):new this(0),r.s=e.s):!e.d||t.isZero()?(r=Mn(this,s,1).times(.5),r.s=e.s):t.s<0?(this.precision=s,this.rounding=1,r=this.atan(Vt(e,t,s,1)),t=Mn(this,s,1),this.precision=n,this.rounding=i,r=e.s<0?r.minus(t):r.plus(t)):r=this.atan(Vt(e,t,s,1)),r}function V9(e){return new this(e).cbrt()}function q9(e){return Xe(e=new this(e),e.e+1,2)}function W9(e,t,r){return new this(e).clamp(t,r)}function G9(e){if(!e||typeof e!="object")throw Error(Al+"Object expected");var t,r,n,i=e.defaults===!0,s=["precision",1,ys,"rounding",0,8,"toExpNeg",-Ao,0,"toExpPos",0,Ao,"maxE",0,Ao,"minE",-Ao,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(r=s[t],i&&(this[r]=eh[r]),(n=e[r])!==void 0)if(Or(n)===n&&n>=s[t+1]&&n<=s[t+2])this[r]=n;else throw Error(us+r+": "+n);if(r="crypto",i&&(this[r]=eh[r]),(n=e[r])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(x4);else this[r]=!1;else throw Error(us+r+": "+n);return this}function H9(e){return new this(e).cos()}function K9(e){return new this(e).cosh()}function I4(e){var t,r,n;function i(s){var o,a,c,u=this;if(!(u instanceof i))return new i(s);if(u.constructor=i,vg(s)){u.s=s.s,ct?!s.d||s.e>i.maxE?(u.e=NaN,u.d=null):s.e<i.minE?(u.e=0,u.d=[0]):(u.e=s.e,u.d=s.d.slice()):(u.e=s.e,u.d=s.d?s.d.slice():s.d);return}if(c=typeof s,c==="number"){if(s===0){u.s=1/s<0?-1:1,u.e=0,u.d=[0];return}if(s<0?(s=-s,u.s=-1):u.s=1,s===~~s&&s<1e7){for(o=0,a=s;a>=10;a/=10)o++;ct?o>i.maxE?(u.e=NaN,u.d=null):o<i.minE?(u.e=0,u.d=[0]):(u.e=o,u.d=[s]):(u.e=o,u.d=[s]);return}else if(s*0!==0){s||(u.s=NaN),u.e=NaN,u.d=null;return}return nh(u,s.toString())}else if(c!=="string")throw Error(us+s);return(a=s.charCodeAt(0))===45?(s=s.slice(1),u.s=-1):(a===43&&(s=s.slice(1)),u.s=1),E4.test(s)?nh(u,s):j9(u,s)}if(i.prototype=be,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=G9,i.clone=I4,i.isDecimal=vg,i.abs=R9,i.acos=N9,i.acosh=D9,i.add=$9,i.asin=B9,i.asinh=L9,i.atan=F9,i.atanh=U9,i.atan2=z9,i.cbrt=V9,i.ceil=q9,i.clamp=W9,i.cos=H9,i.cosh=K9,i.div=X9,i.exp=J9,i.floor=Y9,i.hypot=Z9,i.ln=Q9,i.log=eR,i.log10=rR,i.log2=tR,i.max=nR,i.min=iR,i.mod=sR,i.mul=oR,i.pow=aR,i.random=cR,i.round=uR,i.sign=lR,i.sin=fR,i.sinh=dR,i.sqrt=hR,i.sub=pR,i.sum=mR,i.tan=gR,i.tanh=vR,i.trunc=yR,e===void 0&&(e={}),e&&e.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<n.length;)e.hasOwnProperty(r=n[t++])||(e[r]=this[r]);return i.config(e),i}function X9(e,t){return new this(e).div(t)}function J9(e){return new this(e).exp()}function Y9(e){return Xe(e=new this(e),e.e+1,3)}function Z9(){var e,t,r=new this(0);for(ct=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)r.d&&(r=r.plus(t.times(t)));else{if(t.s)return ct=!0,new this(1/0);r=t}return ct=!0,r.sqrt()}function vg(e){return e instanceof Sc||e&&e.toStringTag===S4||!1}function Q9(e){return new this(e).ln()}function eR(e,t){return new this(e).log(t)}function tR(e){return new this(e).log(2)}function rR(e){return new this(e).log(10)}function nR(){return A4(this,arguments,"lt")}function iR(){return A4(this,arguments,"gt")}function sR(e,t){return new this(e).mod(t)}function oR(e,t){return new this(e).mul(t)}function aR(e,t){return new this(e).pow(t)}function cR(e){var t,r,n,i,s=0,o=new this(1),a=[];if(e===void 0?e=this.precision:qr(e,1,ys),n=Math.ceil(e/Qe),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));s<n;)i=t[s],i>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:a[s++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(n*=4);s<n;)i=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,s):(a.push(i%1e7),s+=4);s=n/4}else throw Error(x4);else for(;s<n;)a[s++]=Math.random()*1e7|0;for(n=a[--s],e%=Qe,n&&e&&(i=pr(10,Qe-e),a[s]=(n/i|0)*i);a[s]===0;s--)a.pop();if(s<0)r=0,a=[0];else{for(r=-1;a[0]===0;r-=Qe)a.shift();for(n=1,i=a[0];i>=10;i/=10)n++;n<Qe&&(r-=Qe-n)}return o.e=r,o.d=a,o}function uR(e){return Xe(e=new this(e),e.e+1,this.rounding)}function lR(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function fR(e){return new this(e).sin()}function dR(e){return new this(e).sinh()}function hR(e){return new this(e).sqrt()}function pR(e,t){return new this(e).sub(t)}function mR(){var e=0,t=arguments,r=new this(t[e]);for(ct=!1;r.s&&++e<t.length;)r=r.plus(t[e]);return ct=!0,Xe(r,this.precision,this.rounding)}function gR(e){return new this(e).tan()}function vR(e){return new this(e).tanh()}function yR(e){return Xe(e=new this(e),e.e+1,1)}be[Symbol.for("nodejs.util.inspect.custom")]=be.toString;be[Symbol.toStringTag]="Decimal";var Sc=be.constructor=I4(eh);Bu=new Sc(Bu);Lu=new Sc(Lu);var fu=Sc,rs=Qo(ea()),Xf=Qo(ea()),bR=class{constructor(e){if(e!==0)throw new Error("Aftermath only supported on mainnet");this.slippage="900000000000000000",this.poolRegistry="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",this.protocolFeeVault="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",this.treasury="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",this.insuranceFund="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",this.referrealVault="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278"}amountLimit(e){return new Xf.default(e).mul(new Xf.default(this.slippage)).div(new Xf.default("1000000000000000000")).toString()}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o];if(r.extendedDetails==null)throw new Error("Extended details not supported");if(r.extendedDetails.aftermathLpSupplyType==null)throw new Error("LP supply type not supported");const f=[t.object(r.id),t.object(this.poolRegistry),t.object(this.protocolFeeVault),t.object(this.treasury),t.object(this.insuranceFund),t.object(this.referrealVault),t.pure.u64(this.amountLimit(r.amountOut)),t.pure.u64(this.slippage),n],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::aftermath::${c}`,typeArguments:[u,l,r.extendedDetails.aftermathLpSupplyType],arguments:f})})}},yg="0x000000000000000000000000000000000000000000000000000000000000dee9",wR=class{constructor(e){if(e!==0)throw new Error("Aftermath only supported on mainnet")}getAccountCap(e,t){return _t(this,null,function*(){let r=50,n=null;for(;;){const i=e.getOwnedObjects({owner:t,cursor:n,limit:r,filter:{MoveModule:{package:yg,module:"custodian_v2"}}});if(i!=null&&i.data!=null){if(i.data.length!==0)return i.data[0].data.objectId;if(i.data.length<50)break}else break}return null})}getOrCreateAccountCap(e,t,r){return _t(this,null,function*(){let n=yield this.getAccountCap(t,r);return n!==null?{accountCap:e.object(n),isCreate:!1}:{accountCap:e.moveCall({target:`${yg}::clob_v2::create_account`,typeArguments:[],arguments:[]}),isCreate:!0}})}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=yield this.getOrCreateAccountCap(t,e.client,e.signer),h=[t.object(r.id),n,f.accountCap,t.object(ni)],y=yr(e.publishedAtV2(),i),b=t.moveCall({target:`${y}::deepbook::${c}`,typeArguments:[u,l],arguments:h});return f.isCreate&&t.transferObjects([f.accountCap],e.signer),b})}},_R=class{constructor(e){if(e!==0)throw new Error("Kriya amm only supported on mainnet")}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(r.id),n],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::kriya_amm::${c}`,typeArguments:[u,l],arguments:f})})}},xR=class{constructor(e){if(e!==0)throw new Error("Kriya clmm only supported on mainnet");this.version="0xf5145a7ac345ca8736cf8c76047d00d6d378f30e81be6f6eb557184d9de93c78"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(r.id),n,t.object(this.version),t.object(ni)],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::kriya_clmm::${c}`,typeArguments:[u,l],arguments:f})})}},SR=class{constructor(e){if(e!==0)throw new Error("Flowx only supported on mainnet");this.container="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.container),n],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::flowx_amm::${c}`,typeArguments:[u,l],arguments:f})})}},ER=class{constructor(e){if(e!==0)throw new Error("Flowx clmm only supported on mainnet");this.versioned="0x67624a1533b5aff5d0dfcf5e598684350efd38134d2d245f475524c03a64e656",this.poolRegistry="0x27565d24a4cd51127ac90e4074a841bbe356cca7bf5759ddc14a975be1632abc"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.poolRegistry),t.pure.u64(r.feeRate*1e6),n,t.object(this.versioned),t.object(ni)],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::flowx_clmm::${c}`,typeArguments:[u,l],arguments:f})})}},CR=class{constructor(e){if(e!==0)throw new Error("Turbos only supported on mainnet");this.versioned="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o];if(r.extendedDetails==null)throw new Error("Extended details not supported");if(r.extendedDetails.turbosFeeType==null)throw new Error("Turbos fee type not supported");const f=[t.object(r.id),n,t.object(ni),t.object(this.versioned)],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::turbos::${c}`,typeArguments:[u,l,r.extendedDetails.turbosFeeType],arguments:f})})}},bg=class{constructor(e,t){this.globalConfig=e===0?"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f":"0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e",this.partner=t??(e===0?"0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b":"0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5")}flash_swap(e,t,r,n,i){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["flash_swap_a2b",o,a]:["flash_swap_b2a",a,o];let f=n?r.amountIn:r.amountOut;const h=[t.object(this.globalConfig),t.object(r.id),t.object(this.partner),t.pure.u64(f),t.pure.bool(n),t.object(ni)],y=yr(e.publishedAtV2(),i),b=t.moveCall({target:`${y}::cetus::${c}`,typeArguments:[u,l],arguments:h});return{targetCoin:b[0],flashReceipt:b[1],payAmount:b[2]}}repay_flash_swap(e,t,r,n,i,s){const{direction:o,from:a,target:c}=r,[u,l,f]=o?["repay_flash_swap_a2b",a,c]:["repay_flash_swap_b2a",c,a],h=[t.object(this.globalConfig),t.object(r.id),t.object(this.partner),n,i],y=yr(e.publishedAtV2(),s);return t.moveCall({target:`${y}::cetus::${u}`,typeArguments:[l,f],arguments:h})[0]}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.globalConfig),t.object(r.id),t.object(this.partner),n,t.object(ni)],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::cetus::${c}`,typeArguments:[u,l],arguments:f})})}};function wg(e,...t){const r=Array.isArray(t[t.length-1])?t.pop():[];let i=[e,...t].filter(Boolean).join("::");return r&&r.length&&(i+=`<${r.join(", ")}>`),i}function MR(e){return e.split("::")[0]}function Gs(e){var t;try{let r=e.replace(/\s/g,"");const n=r.match(/(<.+>)$/),i=(t=n==null?void 0:n[0])==null?void 0:t.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(i){r=r.slice(0,r.indexOf("<"));const c=Gs(r),u=x9(_9({},c),{type_arguments:i.map(l=>Gs(l).source_address)});return u.type_arguments=u.type_arguments.map(l=>Wn.isSuiCoin(l)?l:Gs(l).source_address),u.source_address=wg(u.full_address,u.type_arguments),u}const s=r.split("::"),a={full_address:r,address:r===P4||r===OR?"0x2":Zd.normalizeSuiObjectId(s[0]),module:s[1],name:s[2],type_arguments:[],source_address:""};return a.full_address=`${a.address}::${a.module}::${a.name}`,a.source_address=wg(a.full_address,a.type_arguments),a}catch{return{full_address:e,address:"",module:"",name:"",type_arguments:[],source_address:e}}}function _g(e){return Gs(e).source_address}var AR="0x2::coin::Coin",TR=/^0x2::coin::Coin<(.+)>$/,P4="0x2::sui::SUI",OR="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Wn=class Xi{static getCoinTypeArg(t){const r=t.type.match(TR);return r?r[1]:null}static isSUI(t){const r=Xi.getCoinTypeArg(t);return r?Xi.getCoinSymbol(r)==="SUI":!1}static getCoinSymbol(t){return t.substring(t.lastIndexOf(":")+1)}static getBalance(t){return BigInt(t.fields.balance)}static totalBalance(t,r){let n=BigInt(0);return t.forEach(i=>{r===i.coinAddress&&(n+=BigInt(i.balance))}),n}static getID(t){return t.fields.id.id}static getCoinTypeFromArg(t){return`${AR}<${t}>`}static getCoinAssets(t,r){const n=[];return r.forEach(i=>{_g(i.coinAddress)===_g(t)&&n.push(i)}),n}static isSuiCoin(t){return Gs(t).full_address===P4}static selectCoinObjectIdGreaterThanOrEqual(t,r,n=[]){const i=Xi.selectCoinAssetGreaterThanOrEqual(t,r,n),s=i.selectedCoins.map(c=>c.coinObjectId),o=i.remainingCoins,a=i.selectedCoins.map(c=>c.balance.toString());return{objectArray:s,remainCoins:o,amountArray:a}}static selectCoinAssetGreaterThanOrEqual(t,r,n=[]){const i=Xi.sortByBalance(t.filter(u=>!n.includes(u.coinObjectId))),s=Xi.calculateTotalBalance(i);if(s<r)return{selectedCoins:[],remainingCoins:i};if(s===r)return{selectedCoins:i,remainingCoins:[]};let o=BigInt(0);const a=[],c=[...i];for(;o<s;){const u=r-o,l=c.findIndex(h=>h.balance>=u);if(l!==-1){a.push(c[l]),c.splice(l,1);break}const f=c.pop();f.balance>0&&(a.push(f),o+=f.balance)}return{selectedCoins:Xi.sortByBalance(a),remainingCoins:Xi.sortByBalance(c)}}static sortByBalance(t){return t.sort((r,n)=>r.balance<n.balance?-1:r.balance>n.balance?1:0)}static sortByBalanceDes(t){return t.sort((r,n)=>r.balance>n.balance?-1:r.balance<n.balance?0:1)}static calculateTotalBalance(t){return t.reduce((r,n)=>r+n.balance,BigInt(0))}};function Jf(e){switch(e){case 1e4:return"Calculate error";case 10001:return"Input number too large can not fit in target type";case 10002:return"No router";case 10003:return"Insufficient Liquidity";case 10004:return"Target token is detected as a HoneyPot scam";default:return"Unknown error"}}function ls(e){const t=e.indexOf("::");if(t===-1)return e;const r=e.substring(0,t),n=e.substring(t);if(!r.startsWith("0x"))return e;const i=r.substring(2);return i.length>64?e:`0x${i.padStart(64,"0")}${n}`}function IR(e,t){e=ls(e),t=ls(t);const r=Math.min(e.length,t.length);for(let n=0;n<r;n++){if(e[n]>t[n])return!0;if(e[n]<t[n])return!1}return!0}function j4(e,t){return e.moveCall({target:"0x2::coin::zero",typeArguments:[t]})}function Yf(e,t,r,n){const i=Wn.getCoinAssets(n,t);if(r===BigInt(0))return Wn.isSuiCoin(n)||i.length===0&&!Wn.isSuiCoin(n)?{targetCoin:j4(e,n),isMintZeroCoin:!0,targetCoinAmount:0}:{targetCoin:e.object(i[0].coinObjectId),isMintZeroCoin:!1,targetCoinAmount:Number(i[0].balance.toString())};if(Wn.calculateTotalBalance(i)<r)throw new AggregateError("Insufficient balance when build merge coin, coinType: "+n,"InsufficientBalance"+n);if(Wn.isSuiCoin(n))return{targetCoin:e.splitCoins(e.gas,[e.pure.u64(r.toString())]),isMintZeroCoin:!0,targetCoinAmount:Number(r.toString())};let o=Wn.sortByBalance(i);o.slice(0,3).reduce((h,y)=>h+y.balance,BigInt(0))<BigInt(r)&&(o=Wn.sortByBalanceDes(i));let c=Wn.selectCoinObjectIdGreaterThanOrEqual(o,r);const[u,...l]=c.objectArray;return l.length>0&&e.mergeCoins(u,l.map(h=>e.object(h))),{targetCoin:e.splitCoins(e.object(u),[e.pure.u64(r.toString())]),isMintZeroCoin:!1,targetCoinAmount:Number(r.toString())}}function PR(e,t=!0){return _t(this,null,function*(){console.log("inputs",e.getData().inputs),e.getData().commands.forEach((r,n)=>{t&&console.log(`transaction ${n}: `,JSON.stringify(r,null,2))})})}function jR(e){return!(!e.startsWith("0x")||e.length!==66)}var ao=Qo(ea()),ns=Qo(ea()),Ec=Qo(ea()),Ci=new Ec.default(0);new Ec.default(1);var kR=new Ec.default(2);kR.pow(new Ec.default(128));var RR=new Ec.default("18446744073709551615"),an=1e9;function NR(e,t,r){let n=Ci;return t?n=e.mul(new ns.default(an-r*an)).div(new ns.default(an)):n=e.mul(new ns.default(an+r*an)).div(new ns.default(an)),Number(n.toString())}function DR(e,t,r){let n=Ci;return t?n=e.mul(new ns.default(an-r*an)).div(new ns.default(an)):n=e.mul(new ns.default(an+r*an)).div(new ns.default(an)),n}function $R(e,t,r){return new fu(e).mul(fu.pow(2,-64)).pow(2).mul(fu.pow(10,t-r))}function BR(e,t,r,n){return _t(this,null,function*(){var i,s,o,a,c;const{from:u,target:l,amount:f,byAmountIn:h,pools:y}=t,b=ls(u),w=ls(l),T=new p9.Transaction,P=IR(b,w),k=n===0?"0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10":"0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293",N=P?b:w,F=P?w:b,L=[N,F];console.log("typeArguments",L,k);for(let C=0;C<y.length;C++){const g=[T.object(y[C]),T.pure.bool(P),T.pure.bool(h),T.pure.u64(f.toString())];T.moveCall({target:`${k}::fetcher_script::calculate_swap_result`,arguments:g,typeArguments:L})}if(!jR(r))throw new AggregateError("Aggregator package not set","InvalidWallet");PR(T);const G=yield e.devInspectTransactionBlock({transactionBlock:T,sender:r});if(G.error!=null)throw console.log("simulateRes.error",G.error),new AggregateError("Aggregator package not set","SimulateError");const q=(i=G.events)==null?void 0:i.filter(C=>C.type.includes("CalculatedSwapResultEvent"));if(q.length===0||q.length!==y.length)throw new AggregateError("Simulate event result error","simulateEventError");let X=h?Ci:RR,ne=0;for(let C=0;C<q.length;C+=1)if(!q[C].parsedJson.data.is_exceed)if(t.byAmountIn){const g=new ao.BN(q[C].parsedJson.data.amount_out);g.gt(X)&&(ne=C,X=g)}else{const g=new ao.BN(q[C].parsedJson.data.amount_out);g.lt(X)&&(ne=C,X=g)}const ae=q[ne].parsedJson.data;console.log("event",JSON.stringify(ae,null,2));const ce=ae.step_results[0].current_sqrt_price,[V,D]=yield Promise.all([e.getCoinMetadata({coinType:N}).then(C=>C==null?void 0:C.decimals),e.getCoinMetadata({coinType:F}).then(C=>C==null?void 0:C.decimals)]);if(V==null||D==null)throw new AggregateError("Simulate event result error","CannotGetDecimals");const p=$R(ce,V,D),d=Number(ae.fee_rate)/1e6,m=new ao.BN((s=ae.amount_in)!=null?s:0),x=new ao.BN((o=ae.fee_amount)!=null?o:0),M=m.add(x),E={amountIn:M,amountOut:new ao.BN((a=ae.amount_out)!=null?a:0),routes:[{path:[{id:y[ne],direction:P,provider:"CETUS",from:b,target:w,feeRate:d,amountIn:ae.amount_in,amountOut:ae.amount_out,extendedDetails:{afterSqrtPrice:ae.after_sqrt_price}}],amountIn:M,amountOut:new ao.BN((c=ae.amount_out)!=null?c:0),initialPrice:p}],insufficientLiquidity:!1,byAmountIn:t.byAmountIn};return{isExceed:ae.is_exceed,routeData:E}})}var LR=class{constructor(e){if(e!==0)throw new Error("Haedal only supported on mainnet")}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s}=r;if(!s)throw new Error("Haedal not support b2a swap");const o="swap_a2b",a=[t.object(r.id),t.object("0x5"),n],c=yr(e.publishedAtV2(),i);return t.moveCall({target:`${c}::haedal::${o}`,typeArguments:[],arguments:a})})}},FR=class{constructor(e){if(e!==0)throw new Error("Afsui only supported on mainnet");this.stakedSuiVault="0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",this.safe="0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",this.referVault="0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",this.validator="0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s}=r;if(!s)throw new Error("Afsui not support b2a swap");const o="swap_a2b",a=[t.object(this.stakedSuiVault),t.object(this.safe),t.object("0x5"),t.object(this.referVault),t.object(this.validator),n],c=yr(e.publishedAtV2(),i);return t.moveCall({target:`${c}::afsui::${o}`,typeArguments:[],arguments:a})})}},UR=class{constructor(e){if(e!==0)throw new Error("Volo only supported on mainnet");this.nativePool="0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",this.metadata="0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s}=r;if(!s)throw new Error("Volo not support b2a swap");const o="swap_a2b",a=[t.object(this.nativePool),t.object(this.metadata),t.object("0x5"),n],c=yr(e.publishedAtV2(),i);return t.moveCall({target:`${c}::volo::${o}`,typeArguments:[],arguments:a})})}},zR=class{constructor(e){if(e!==0)throw new Error("Bluemove only supported on mainnet");this.dexInfo="0x3f2d9f724f4a1ce5e71676448dc452be9a6243dac9c5b975a588c8c867066e92"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.dexInfo),n],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::bluemove::${c}`,typeArguments:[u,l],arguments:f})})}},VR=class{constructor(e){this.deepbookV3Config=e===0?"0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c":"0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"}swap(e,t,r,n,i,s){return _t(this,null,function*(){const{direction:o,from:a,target:c}=r,[u,l,f]=o?["swap_a2b",a,c]:["swap_b2a",c,a];let h;s?h=s:h=j4(t,e.deepbookv3DeepFeeType());const y=[t.object(this.deepbookV3Config),t.object(r.id),n,h,t.object(ni)],b=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${b}::deepbookv3::${u}`,typeArguments:[l,f],arguments:y})})}},qR=class{constructor(e){if(e!==0)throw new Error("Scallop only supported on mainnet");this.version=e===0?"0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7":"0x0",this.market=e===0?"0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9":"0x0"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",o,a];if(r.extendedDetails==null)throw new Error("Extended details not supported");if(r.extendedDetails.scallopScoinTreasury==null)throw new Error("Scallop coin treasury not supported");const f=[t.object(this.version),t.object(this.market),t.object(r.extendedDetails.scallopScoinTreasury),n,t.object(ni)],h=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${h}::scallop::${c}`,typeArguments:[u,l],arguments:f})})}},xg=class{constructor(e){if(e!==0)throw new Error("Suilend only supported on mainnet");this.sui_system_state=e===0?"0x0000000000000000000000000000000000000000000000000000000000000005":"0x0"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u]=s?["swap_a2b",a]:["swap_b2a",o],l=[t.object(r.id),t.object(this.sui_system_state),n],f=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${f}::suilend::${c}`,typeArguments:[u],arguments:l})})}},WR=class{constructor(e){if(e!==0)throw new Error("Bluefin only supported on mainnet");this.globalConfig="0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.globalConfig),t.object(r.id),n,t.object(ni)],h=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${h}::bluefin::${c}`,typeArguments:[u,l],arguments:f})})}},GR=class{constructor(e,t){if(e===1){this.connection=new Bc.SuiPriceServiceConnection("https://hermes-beta.pyth.network");const r="0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",n="0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";this.pythClient=new Bc.SuiPythClient(t,n,r)}else{this.connection=new Bc.SuiPriceServiceConnection("https://hermes.pyth.network");const r="0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",n="0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";this.pythClient=new Bc.SuiPythClient(t,n,r)}}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o];let f,h;if(r.extendedDetails==null)throw new Error("Extended details not supported haedal pmm");if(!r.extendedDetails.haedalPmmBasePriceSeed||!r.extendedDetails.haedalPmmQuotePriceSeed)throw new Error("Base price seed or quote price seed not supported");f=r.extendedDetails.haedalPmmBasePriceSeed,h=r.extendedDetails.haedalPmmQuotePriceSeed;const y=[f,h],b=yield this.connection.getPriceFeedsUpdateData(y),w=yield this.pythClient.updatePriceFeeds(t,b,y),T=[t.object(r.id),t.object(w[0]),t.object(w[1]),n,t.object(ni)],P=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${P}::haedalpmm::${c}`,typeArguments:[u,l],arguments:T})})}},HR=class{constructor(e){if(e!==0)throw new Error("Alphafi only supported on mainnet");this.sui_system_state=e===0?"0x0000000000000000000000000000000000000000000000000000000000000005":"0x0"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u]=s?["swap_a2b",a]:["swap_b2a",o],l=[t.object(r.id),t.object(this.sui_system_state),n],f=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${f}::alphafi::${c}`,typeArguments:[u],arguments:l})})}},k4="CETUS",KR="DEEPBOOK",XR="KRIYA",JR="FLOWX",YR="FLOWXV3",ZR="KRIYAV3",R4="TURBOS",ih="AFTERMATH",QR="HAEDAL",eN="VOLO",tN="AFSUI",rN="BLUEMOVE",N4="DEEPBOOKV3",D4="SCALLOP",nN="SUILEND",iN="BLUEFIN",$4="HAEDALPMM",sN="ALPHAFI",oN="SPRINGSUI",aN="https://api-sui.cetus.zone/router_v2";function Sg(e){return Array.isArray(e.routers)}function Zf(e){return Array.isArray(e.routers)}var cN=class{constructor(e,t,r,n){this.endpoint=e?dN(e):aN,this.client=r||new dg.SuiClient({url:dg.getFullnodeUrl("mainnet")}),this.signer=t||"",this.env=n||0,this.allCoins=new Map}getCoins(e,t=!0){return _t(this,null,function*(){if(this.signer==="")throw new Error("Signer is required, but not provided.");let r=null,n=50;if(!t){const s=this.allCoins.get(e);if(s)return s}const i=[];for(;;){const s=yield this.client.getCoins({owner:this.signer,coinType:e,cursor:r,limit:n});for(const o of s.data)i.push({coinAddress:Gs(o.coinType).source_address,coinObjectId:o.coinObjectId,balance:BigInt(o.balance)});if(s.data.length<n)break;r=s.data[n-1].coinObjectId}return this.allCoins.set(e,i),i})}findRouters(e){return _t(this,null,function*(){return hN(this.endpoint,e)})}expectInputSwap(e,t,r,n,i,s,o){return _t(this,null,function*(){if(r.length===0)throw new Error("No router found");const a=r.map(b=>b.amountIn.toString()),c=r[0].path[0].from,u=r[0].path[r[0].path.length-1].target,l=e.splitCoins(t,a),f=[];for(let b=0;b<r.length;b++){if(r[b].path.length===0)throw new Error("Empty path");let w=l[b];for(const T of r[b].path)w=yield this.newDex(T.provider,i).swap(this,e,T,w,o,s);f.push(w)}const h=yr(this.publishedAtV2(),o);return this.transferOrDestoryCoin(e,t,c,this.publishedAtV2()),this.checkCoinThresholdAndMergeCoin(e,f,u,n,h)})}expectOutputSwap(e,t,r,n,i){return _t(this,null,function*(){const s=[],o=[],a=[],c=new bg(this.env,n),u=yr(this.publishedAtV2(),i);for(let f=0;f<r.length;f++){const h=r[f];for(let b=h.path.length-1;b>=0;b--){const w=h.path[b],T=c.flash_swap(this,e,w,!1);s.unshift(T.targetCoin),o.unshift(T.flashReceipt)}let y=t;for(let b=0;b<h.path.length;b++){const w=h.path[b],T=c.repay_flash_swap(this,e,w,y,o[b]);y=s[b],b===0?t=T:this.transferOrDestoryCoin(e,T,w.from,u),b===h.path.length-1&&a.push(y)}}const l=r[0].path[0].from;if(this.transferOrDestoryCoin(e,t,l,u),a.length>1){const f=e.makeMoveVec({elements:a.slice(1)});e.moveCall({target:`${Zd.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,typeArguments:[r[0].path[r[0].path.length-1].target],arguments:[a[0],f]})}return a[0]})}swapInPools(e){return _t(this,null,function*(){let t;try{t=yield BR(this.client,e,this.signer,this.env)}catch(r){return console.error("swapInPools error:",r),null}return t})}routerSwap(e){return _t(this,null,function*(){const{routers:t,inputCoin:r,slippage:n,txb:i,partner:s,deepbookv3DeepFee:o}=e,a=Array.isArray(t)?t:t.routes,c=Sg(e)?e.byAmountIn:e.routers.byAmountIn,u=a.reduce((T,P)=>T.add(P.amountIn),new rs.default(0)),l=a.reduce((T,P)=>T.add(P.amountOut),new rs.default(0)),f=DR(c?l:u,c,n),h=Sg(e)?void 0:e.routers.packages;console.log("packages11",h);const y=yr(this.publishedAtV2(),h);if(c)return yield this.expectInputSwap(i,r,a,f,s,o,h);const b=i.splitCoins(r,[f.toString()]);return this.transferOrDestoryCoin(i,r,a[0].path[0].from,y),yield this.expectOutputSwap(i,b[0],a,s)})}fastRouterSwap(e){return _t(this,null,function*(){const{routers:t,slippage:r,txb:n,partner:i,refreshAllCoins:s,payDeepFeeAmount:o}=e,a=Array.isArray(t)?t:t.routes,c=a[0].path[0].from;let u=yield this.getCoins(c,s);const l=a[0].path[a[0].path.length-1].target,f=a.reduce((F,L)=>F.add(L.amountIn),new rs.default(0)),h=a.reduce((F,L)=>F.add(L.amountOut),new rs.default(0)),y=Zf(e)?e.byAmountIn:e.routers.byAmountIn,b=NR(y?h:f,y,r),T=Yf(n,u,BigInt((y?f:b).toString()),c);let P;if(o&&o>0){let F=yield this.getCoins(this.deepbookv3DeepFeeType());P=Yf(n,F,BigInt(o),this.deepbookv3DeepFeeType()).targetCoin}const k=Zf(e)?{routers:a,inputCoin:T.targetCoin,slippage:r,byAmountIn:y,txb:n,partner:i,deepbookv3DeepFee:P}:{routers:e.routers,inputCoin:T.targetCoin,slippage:r,byAmountIn:y,txb:n,partner:i,deepbookv3DeepFee:P},N=yield this.routerSwap(k);if(Wn.isSuiCoin(l))n.mergeCoins(n.gas,[N]);else{let F=yield this.getCoins(l,s);const L=Yf(n,F,BigInt(0),l),G=Zf(e)?void 0:e.routers.packages,q=yr(this.publishedAtV2(),G);n.mergeCoins(L.targetCoin,[N]),L.isMintZeroCoin&&this.transferOrDestoryCoin(n,L.targetCoin,l,q)}})}publishedAtV2(){return this.env===0?"0x3fb42ddf908af45f9fc3c59eab227888ff24ba2e137b3b55bf80920fd47e11af":"0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"}publishedAtV2Extend(){return this.env===0?"0xf2fcea41dc217385019828375764fa06d9bd25e8e4726ba1962680849fb8d613":"0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"}deepbookv3DeepFeeType(){return this.env===0?"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP":"0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"}transferOrDestoryCoin(e,t,r,n){e.moveCall({target:`${n}::utils::transfer_or_destroy_coin`,typeArguments:[r],arguments:[t]})}checkCoinThresholdAndMergeCoin(e,t,r,n,i){let s=t[0];if(t.length>1){let o=e.makeMoveVec({elements:t.slice(1)});e.moveCall({target:`${Zd.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,typeArguments:[r],arguments:[t[0],o]}),s=t[0]}return e.moveCall({target:`${i}::utils::check_coin_threshold`,typeArguments:[r],arguments:[s,e.pure.u64(n.toString())]}),s}newDex(e,t){switch(e){case k4:return new bg(this.env,t);case KR:return new wR(this.env);case N4:return new VR(this.env);case XR:return new _R(this.env);case ZR:return new xR(this.env);case JR:return new SR(this.env);case YR:return new ER(this.env);case R4:return new CR(this.env);case ih:return new bR(this.env);case QR:return new LR(this.env);case tN:return new FR(this.env);case eN:return new UR(this.env);case rN:return new zR(this.env);case D4:return new qR(this.env);case nN:return new xg(this.env);case oN:return new xg(this.env);case iN:return new WR(this.env);case $4:return new GR(this.env,this.client);case sN:return new HR(this.env);default:throw new Error(`Unsupported dex ${e}`)}}signAndExecuteTransaction(e,t){return _t(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:e,signer:t,options:{showEffects:!0,showEvents:!0,showInput:!0,showBalanceChanges:!0}})})}devInspectTransactionBlock(e){return _t(this,null,function*(){return yield this.client.devInspectTransactionBlock({transactionBlock:e,sender:this.signer})})}sendTransaction(e,t){return _t(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:e,signer:t})})}getDeepbookV3Config(){return _t(this,null,function*(){const e=yield gN(this.endpoint);return e?e.data:null})}};function uN(e,t){let r=0;for(const s of e.routes)for(const o of s.path)o.extended_details&&o.extended_details.deepbookv3_deep_fee&&(r+=Number(o.extended_details.deepbookv3_deep_fee));let n;if(e.packages!=null){n=new Map;for(const[s,o]of Object.entries(e.packages))n.set(s,o)}return{amountIn:new rs.default(e.amount_in.toString()),amountOut:new rs.default(e.amount_out.toString()),byAmountIn:t,insufficientLiquidity:!1,routes:e.routes.map(s=>({path:s.path.map(o=>{var a,c,u,l,f,h,y;let b;o.provider===ih&&(b=o.extended_details.aftermath_pool_flatness===0?"v2":"v3");let w;return(o.provider===R4||o.provider===ih||o.provider===k4||o.provider===N4||o.provider===D4||o.provider===$4)&&(w={aftermathLpSupplyType:(a=o.extended_details)==null?void 0:a.aftermath_lp_supply_type,turbosFeeType:(c=o.extended_details)==null?void 0:c.turbos_fee_type,afterSqrtPrice:(u=o.extended_details)==null?void 0:u.after_sqrt_price,deepbookv3DeepFee:(l=o.extended_details)==null?void 0:l.deepbookv3_deep_fee,scallopScoinTreasury:(f=o.extended_details)==null?void 0:f.scallop_scoin_treasury,haedalPmmBasePriceSeed:(h=o.extended_details)==null?void 0:h.haedal_pmm_base_price_seed,haedalPmmQuotePriceSeed:(y=o.extended_details)==null?void 0:y.haedal_pmm_quote_price_seed}),{id:o.id,direction:o.direction,provider:o.provider,from:o.from,target:o.target,feeRate:o.fee_rate,amountIn:o.amount_in,amountOut:o.amount_out,extendedDetails:w,version:b}}),amountIn:new rs.default(s.amount_in.toString()),amountOut:new rs.default(s.amount_out.toString()),initialPrice:new fu(s.initial_price.toString())})),totalDeepFee:r,packages:n}}var ni="0x0000000000000000000000000000000000000000000000000000000000000006",lN="aggregator_v2",fN="aggregator_v2_extend";function yr(e,t){var r;return t instanceof Map&&(r=t.get(lN))!=null?r:e}function ta(e,t){var r;return t instanceof Map&&(r=t.get(fN))!=null?r:e}Qo(ea());function dN(e){return e.endsWith("/find_routes")?e.replace("/find_routes",""):e}function hN(e,t){return _t(this,null,function*(){let r;if(t.liquidityChanges&&t.liquidityChanges.length>0?r=yield mN(e,t):r=yield pN(e,t),!r)return null;if(!r.ok)return{amountIn:Ci,amountOut:Ci,routes:[],byAmountIn:t.byAmountIn,insufficientLiquidity:!1,error:{code:10001,msg:Jf(10001)}};const n=yield r.json(),i=n.msg==="liquidity is not enough";return n.msg&&n.msg.indexOf("HoneyPot scam")>-1?{amountIn:Ci,amountOut:Ci,routes:[],byAmountIn:t.byAmountIn,insufficientLiquidity:i,error:{code:10004,msg:Jf(10004)}}:n.data!=null?uN(n.data,t.byAmountIn):{amountIn:Ci,amountOut:Ci,routes:[],insufficientLiquidity:i,byAmountIn:t.byAmountIn,error:{code:10003,msg:Jf(10003)}}})}function pN(e,t){return _t(this,null,function*(){try{const{from:r,target:n,amount:i,byAmountIn:s,depth:o,splitAlgorithm:a,splitFactor:c,splitCount:u,providers:l}=t,f=ls(r),h=ls(n);let y=`${e}/find_routes?from=${f}&target=${h}&amount=${i.toString()}&by_amount_in=${s}`;return o&&(y+=`&depth=${o}`),a&&(y+=`&split_algorithm=${a}`),c&&(y+=`&split_factor=${c}`),u&&(y+=`&split_count=${u}`),l&&l.length>0&&(y+=`&providers=${l.join(",")}`),y+="&v=1000319",yield fetch(y)}catch(r){return console.error(r),null}})}function mN(e,t){return _t(this,null,function*(){const{from:r,target:n,amount:i,byAmountIn:s,depth:o,splitAlgorithm:a,splitFactor:c,splitCount:u,providers:l,liquidityChanges:f}=t,h=ls(r),y=ls(n),b=`${e}/find_routes`,w=l==null?void 0:l.join(","),T={from:h,target:y,amount:Number(i.toString()),by_amount_in:s,depth:o,split_algorithm:a,split_factor:c,split_count:u,providers:w,liquidity_changes:f.map(P=>({pool:P.poolID,tick_lower:P.ticklower,tick_upper:P.tickUpper,delta_liquidity:P.deltaLiquidity}))};try{return yield fetch(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)})}catch(P){return console.error("Error:",P),null}})}function gN(e){return _t(this,null,function*(){const t=`${e}/deepbookv3_config`;try{return(yield fetch(t)).json()}catch(r){return console.error("Error:",r),null}})}var B4=(e=>(e[e.Mainnet=0]="Mainnet",e[e.Testnet=1]="Testnet",e))(B4||{}),L4=cN,vN=B4,Eg=MR,Ga=Gs;const F4="0x2::sui::SUI",yN="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";function U4(e){return Tr(e).full_address===F4}function Cg(e,...t){const r=Array.isArray(t[t.length-1])?t.pop():[];let i=[e,...t].filter(Boolean).join("::");return r&&r.length&&(i+=`<${r.join(", ")}>`),i}function Tr(e){var t;try{let r=e.replace(/\s/g,"");const n=r.match(/(<.+>)$/),i=(t=n==null?void 0:n[0])==null?void 0:t.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(i){r=r.slice(0,r.indexOf("<"));const u={...Tr(r),type_arguments:i.map(l=>Tr(l).source_address)};return u.type_arguments=u.type_arguments.map(l=>U4(l)?l:Tr(l).source_address),u.source_address=Cg(u.full_address,u.type_arguments),u}const s=r.split("::"),a={full_address:r,address:r===F4||r===yN?"0x2":Ai(s[0]),module:s[1],name:s[2],type_arguments:[],source_address:""};return a.full_address=`${a.address}::${a.module}::${a.name}`,a.source_address=Cg(a.full_address,a.type_arguments),a}catch{return{full_address:e,address:"",module:"",name:"",type_arguments:[],source_address:e}}}function bN(e){return e.startsWith("0x")?`${e.slice(2)}`:e}const Ni=(e,t=!0)=>{const r=e.split("::"),n=r.shift();let i=Ai(n);return t&&(i=bN(i)),`${i}::${r.join("::")}`};/*!
38
+ `+s):n.stack=s}catch{}}throw n}}_request(t,r){typeof t=="string"?(r=r||{},r.url=t):r=t||{},r=Ks(this.defaults,r);const{transitional:n,paramsSerializer:i,headers:s}=r;n!==void 0&&cu.assertOptions(n,{silentJSONParsing:zn.transitional(zn.boolean),forcedJSONParsing:zn.transitional(zn.boolean),clarifyTimeoutError:zn.transitional(zn.boolean)},!1),i!=null&&(fe.isFunction(i)?r.paramsSerializer={serialize:i}:cu.assertOptions(i,{encode:zn.function,serialize:zn.function},!0)),cu.assertOptions(r,{baseUrl:zn.spelling("baseURL"),withXsrfToken:zn.spelling("withXSRFToken")},!0),r.method=(r.method||this.defaults.method||"get").toLowerCase();let o=s&&fe.merge(s.common,s[r.method]);s&&fe.forEach(["delete","get","head","post","put","patch","common"],b=>{delete s[b]}),r.headers=On.concat(o,s);const a=[];let c=!0;this.interceptors.request.forEach(function(w){typeof w.runWhen=="function"&&w.runWhen(r)===!1||(c=c&&w.synchronous,a.unshift(w.fulfilled,w.rejected))});const u=[];this.interceptors.response.forEach(function(w){u.push(w.fulfilled,w.rejected)});let l,f=0,h;if(!c){const b=[Zm.bind(this),void 0];for(b.unshift.apply(b,a),b.push.apply(b,u),h=b.length,l=Promise.resolve(r);f<h;)l=l.then(b[f++],b[f++]);return l}h=a.length;let y=r;for(f=0;f<h;){const b=a[f++],w=a[f++];try{y=b(y)}catch(T){w.call(this,T);break}}try{l=Zm.call(this,y)}catch(b){return Promise.reject(b)}for(f=0,h=u.length;f<h;)l=l.then(u[f++],u[f++]);return l}getUri(t){t=Ks(this.defaults,t);const r=r4(t.baseURL,t.url);return Yx(r,t.params,t.paramsSerializer)}}fe.forEach(["delete","get","head","options"],function(t){Du.prototype[t]=function(r,n){return this.request(Ks(n||{},{method:t,url:r,data:(n||{}).data}))}});fe.forEach(["post","put","patch"],function(t){function r(n){return function(s,o,a){return this.request(Ks(a||{},{method:t,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:o}))}}Du.prototype[t]=r(),Du.prototype[t+"Form"]=r(!0)});var uu=Du;class Zp{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let r;this.promise=new Promise(function(s){r=s});const n=this;this.promise.then(i=>{if(!n._listeners)return;let s=n._listeners.length;for(;s-- >0;)n._listeners[s](i);n._listeners=null}),this.promise.then=i=>{let s;const o=new Promise(a=>{n.subscribe(a),s=a}).then(i);return o.cancel=function(){n.unsubscribe(s)},o},t(function(s,o,a){n.reason||(n.reason=new Zo(s,o,a),r(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const r=this._listeners.indexOf(t);r!==-1&&this._listeners.splice(r,1)}toAbortSignal(){const t=new AbortController,r=n=>{t.abort(n)};return this.subscribe(r),t.signal.unsubscribe=()=>this.unsubscribe(r),t.signal}static source(){let t;return{token:new Zp(function(i){t=i}),cancel:t}}}var Pk=Zp;function jk(e){return function(r){return e.apply(null,r)}}function kk(e){return fe.isObject(e)&&e.isAxiosError===!0}const Jd={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Jd).forEach(([e,t])=>{Jd[t]=e});var Rk=Jd;function c4(e){const t=new uu(e),r=Lx(uu.prototype.request,t);return fe.extend(r,uu.prototype,t,{allOwnKeys:!0}),fe.extend(r,t,null,{allOwnKeys:!0}),r.create=function(i){return c4(Ks(e,i))},r}const ur=c4(Yp);ur.Axios=uu;ur.CanceledError=Zo;ur.CancelToken=Pk;ur.isCancel=e4;ur.VERSION=a4;ur.toFormData=bl;ur.AxiosError=pt;ur.Cancel=ur.CanceledError;ur.all=function(t){return Promise.all(t)};ur.spread=jk;ur.isAxiosError=kk;ur.mergeConfig=Ks;ur.AxiosHeaders=On;ur.formToJSON=e=>Qx(fe.isHTMLForm(e)?new FormData(e):e);ur.getAdapter=o4.getAdapter;ur.HttpStatusCode=Rk;ur.default=ur;var u4=ur,Qp={exports:{}},Zr={},l4={exports:{}};(function(e){function t(r){return r&&r.__esModule?r:{default:r}}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports})(l4);var Nk=l4.exports,$f={exports:{}},Bf={exports:{}},eg;function Sl(){return eg||(eg=1,function(e){function t(r){"@babel/helpers - typeof";return e.exports=t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(n){return typeof n}:function(n){return n&&typeof Symbol=="function"&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(Bf)),Bf.exports}var tg;function Dk(){return tg||(tg=1,function(e){var t=Sl().default;function r(){e.exports=r=function(){return i},e.exports.__esModule=!0,e.exports.default=e.exports;var n,i={},s=Object.prototype,o=s.hasOwnProperty,a=Object.defineProperty||function(E,O,C){E[O]=C.value},c=typeof Symbol=="function"?Symbol:{},u=c.iterator||"@@iterator",l=c.asyncIterator||"@@asyncIterator",f=c.toStringTag||"@@toStringTag";function h(E,O,C){return Object.defineProperty(E,O,{value:C,enumerable:!0,configurable:!0,writable:!0}),E[O]}try{h({},"")}catch{h=function(C,g,v){return C[g]=v}}function y(E,O,C,g){var v=O&&O.prototype instanceof F?O:F,j=Object.create(v.prototype),ee=new x(g||[]);return a(j,"_invoke",{value:D(E,C,ee)}),j}function b(E,O,C){try{return{type:"normal",arg:E.call(O,C)}}catch(g){return{type:"throw",arg:g}}}i.wrap=y;var w="suspendedStart",T="suspendedYield",P="executing",k="completed",N={};function F(){}function L(){}function G(){}var q={};h(q,u,function(){return this});var X=Object.getPrototypeOf,ne=X&&X(X(M([])));ne&&ne!==s&&o.call(ne,u)&&(q=ne);var ae=G.prototype=F.prototype=Object.create(q);function ce(E){["next","throw","return"].forEach(function(O){h(E,O,function(C){return this._invoke(O,C)})})}function V(E,O){function C(v,j,ee,ie){var de=b(E[v],E,j);if(de.type!=="throw"){var ye=de.arg,Ee=ye.value;return Ee&&t(Ee)=="object"&&o.call(Ee,"__await")?O.resolve(Ee.__await).then(function(Se){C("next",Se,ee,ie)},function(Se){C("throw",Se,ee,ie)}):O.resolve(Ee).then(function(Se){ye.value=Se,ee(ye)},function(Se){return C("throw",Se,ee,ie)})}ie(de.arg)}var g;a(this,"_invoke",{value:function(j,ee){function ie(){return new O(function(de,ye){C(j,ee,de,ye)})}return g=g?g.then(ie,ie):ie()}})}function D(E,O,C){var g=w;return function(v,j){if(g===P)throw Error("Generator is already running");if(g===k){if(v==="throw")throw j;return{value:n,done:!0}}for(C.method=v,C.arg=j;;){var ee=C.delegate;if(ee){var ie=p(ee,C);if(ie){if(ie===N)continue;return ie}}if(C.method==="next")C.sent=C._sent=C.arg;else if(C.method==="throw"){if(g===w)throw g=k,C.arg;C.dispatchException(C.arg)}else C.method==="return"&&C.abrupt("return",C.arg);g=P;var de=b(E,O,C);if(de.type==="normal"){if(g=C.done?k:T,de.arg===N)continue;return{value:de.arg,done:C.done}}de.type==="throw"&&(g=k,C.method="throw",C.arg=de.arg)}}}function p(E,O){var C=O.method,g=E.iterator[C];if(g===n)return O.delegate=null,C==="throw"&&E.iterator.return&&(O.method="return",O.arg=n,p(E,O),O.method==="throw")||C!=="return"&&(O.method="throw",O.arg=new TypeError("The iterator does not provide a '"+C+"' method")),N;var v=b(g,E.iterator,O.arg);if(v.type==="throw")return O.method="throw",O.arg=v.arg,O.delegate=null,N;var j=v.arg;return j?j.done?(O[E.resultName]=j.value,O.next=E.nextLoc,O.method!=="return"&&(O.method="next",O.arg=n),O.delegate=null,N):j:(O.method="throw",O.arg=new TypeError("iterator result is not an object"),O.delegate=null,N)}function d(E){var O={tryLoc:E[0]};1 in E&&(O.catchLoc=E[1]),2 in E&&(O.finallyLoc=E[2],O.afterLoc=E[3]),this.tryEntries.push(O)}function m(E){var O=E.completion||{};O.type="normal",delete O.arg,E.completion=O}function x(E){this.tryEntries=[{tryLoc:"root"}],E.forEach(d,this),this.reset(!0)}function M(E){if(E||E===""){var O=E[u];if(O)return O.call(E);if(typeof E.next=="function")return E;if(!isNaN(E.length)){var C=-1,g=function v(){for(;++C<E.length;)if(o.call(E,C))return v.value=E[C],v.done=!1,v;return v.value=n,v.done=!0,v};return g.next=g}}throw new TypeError(t(E)+" is not iterable")}return L.prototype=G,a(ae,"constructor",{value:G,configurable:!0}),a(G,"constructor",{value:L,configurable:!0}),L.displayName=h(G,f,"GeneratorFunction"),i.isGeneratorFunction=function(E){var O=typeof E=="function"&&E.constructor;return!!O&&(O===L||(O.displayName||O.name)==="GeneratorFunction")},i.mark=function(E){return Object.setPrototypeOf?Object.setPrototypeOf(E,G):(E.__proto__=G,h(E,f,"GeneratorFunction")),E.prototype=Object.create(ae),E},i.awrap=function(E){return{__await:E}},ce(V.prototype),h(V.prototype,l,function(){return this}),i.AsyncIterator=V,i.async=function(E,O,C,g,v){v===void 0&&(v=Promise);var j=new V(y(E,O,C,g),v);return i.isGeneratorFunction(O)?j:j.next().then(function(ee){return ee.done?ee.value:j.next()})},ce(ae),h(ae,f,"Generator"),h(ae,u,function(){return this}),h(ae,"toString",function(){return"[object Generator]"}),i.keys=function(E){var O=Object(E),C=[];for(var g in O)C.push(g);return C.reverse(),function v(){for(;C.length;){var j=C.pop();if(j in O)return v.value=j,v.done=!1,v}return v.done=!0,v}},i.values=M,x.prototype={constructor:x,reset:function(O){if(this.prev=0,this.next=0,this.sent=this._sent=n,this.done=!1,this.delegate=null,this.method="next",this.arg=n,this.tryEntries.forEach(m),!O)for(var C in this)C.charAt(0)==="t"&&o.call(this,C)&&!isNaN(+C.slice(1))&&(this[C]=n)},stop:function(){this.done=!0;var O=this.tryEntries[0].completion;if(O.type==="throw")throw O.arg;return this.rval},dispatchException:function(O){if(this.done)throw O;var C=this;function g(ye,Ee){return ee.type="throw",ee.arg=O,C.next=ye,Ee&&(C.method="next",C.arg=n),!!Ee}for(var v=this.tryEntries.length-1;v>=0;--v){var j=this.tryEntries[v],ee=j.completion;if(j.tryLoc==="root")return g("end");if(j.tryLoc<=this.prev){var ie=o.call(j,"catchLoc"),de=o.call(j,"finallyLoc");if(ie&&de){if(this.prev<j.catchLoc)return g(j.catchLoc,!0);if(this.prev<j.finallyLoc)return g(j.finallyLoc)}else if(ie){if(this.prev<j.catchLoc)return g(j.catchLoc,!0)}else{if(!de)throw Error("try statement without catch or finally");if(this.prev<j.finallyLoc)return g(j.finallyLoc)}}}},abrupt:function(O,C){for(var g=this.tryEntries.length-1;g>=0;--g){var v=this.tryEntries[g];if(v.tryLoc<=this.prev&&o.call(v,"finallyLoc")&&this.prev<v.finallyLoc){var j=v;break}}j&&(O==="break"||O==="continue")&&j.tryLoc<=C&&C<=j.finallyLoc&&(j=null);var ee=j?j.completion:{};return ee.type=O,ee.arg=C,j?(this.method="next",this.next=j.finallyLoc,N):this.complete(ee)},complete:function(O,C){if(O.type==="throw")throw O.arg;return O.type==="break"||O.type==="continue"?this.next=O.arg:O.type==="return"?(this.rval=this.arg=O.arg,this.method="return",this.next="end"):O.type==="normal"&&C&&(this.next=C),N},finish:function(O){for(var C=this.tryEntries.length-1;C>=0;--C){var g=this.tryEntries[C];if(g.finallyLoc===O)return this.complete(g.completion,g.afterLoc),m(g),N}},catch:function(O){for(var C=this.tryEntries.length-1;C>=0;--C){var g=this.tryEntries[C];if(g.tryLoc===O){var v=g.completion;if(v.type==="throw"){var j=v.arg;m(g)}return j}}throw Error("illegal catch attempt")},delegateYield:function(O,C,g){return this.delegate={iterator:M(O),resultName:C,nextLoc:g},this.method==="next"&&(this.arg=n),N}},i}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}($f)),$f.exports}var Lf,rg;function $k(){if(rg)return Lf;rg=1;var e=Dk()();Lf=e;try{regeneratorRuntime=e}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}return Lf}var Ff={exports:{}},ng;function Bk(){return ng||(ng=1,function(e){function t(n,i,s,o,a,c,u){try{var l=n[c](u),f=l.value}catch(h){return void s(h)}l.done?i(f):Promise.resolve(f).then(o,a)}function r(n){return function(){var i=this,s=arguments;return new Promise(function(o,a){var c=n.apply(i,s);function u(f){t(c,o,a,u,l,"next",f)}function l(f){t(c,o,a,u,l,"throw",f)}u(void 0)})}}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(Ff)),Ff.exports}var Uf={exports:{}},zf={exports:{}},Vf={exports:{}},ig;function Lk(){return ig||(ig=1,function(e){var t=Sl().default;function r(n,i){if(t(n)!="object"||!n)return n;var s=n[Symbol.toPrimitive];if(s!==void 0){var o=s.call(n,i||"default");if(t(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(i==="string"?String:Number)(n)}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(Vf)),Vf.exports}var sg;function Fk(){return sg||(sg=1,function(e){var t=Sl().default,r=Lk();function n(i){var s=r(i,"string");return t(s)=="symbol"?s:s+""}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}(zf)),zf.exports}var og;function Uk(){return og||(og=1,function(e){var t=Fk();function r(n,i,s){return(i=t(i))in n?Object.defineProperty(n,i,{value:s,enumerable:!0,configurable:!0,writable:!0}):n[i]=s,n}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(Uf)),Uf.exports}var qf,ag;function zk(){if(ag)return qf;ag=1;const e=new Set(["ENOTFOUND","ENETUNREACH","UNABLE_TO_GET_ISSUER_CERT","UNABLE_TO_GET_CRL","UNABLE_TO_DECRYPT_CERT_SIGNATURE","UNABLE_TO_DECRYPT_CRL_SIGNATURE","UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY","CERT_SIGNATURE_FAILURE","CRL_SIGNATURE_FAILURE","CERT_NOT_YET_VALID","CERT_HAS_EXPIRED","CRL_NOT_YET_VALID","CRL_HAS_EXPIRED","ERROR_IN_CERT_NOT_BEFORE_FIELD","ERROR_IN_CERT_NOT_AFTER_FIELD","ERROR_IN_CRL_LAST_UPDATE_FIELD","ERROR_IN_CRL_NEXT_UPDATE_FIELD","OUT_OF_MEM","DEPTH_ZERO_SELF_SIGNED_CERT","SELF_SIGNED_CERT_IN_CHAIN","UNABLE_TO_GET_ISSUER_CERT_LOCALLY","UNABLE_TO_VERIFY_LEAF_SIGNATURE","CERT_CHAIN_TOO_LONG","CERT_REVOKED","INVALID_CA","PATH_LENGTH_EXCEEDED","INVALID_PURPOSE","CERT_UNTRUSTED","CERT_REJECTED","HOSTNAME_MISMATCH"]);return qf=t=>!e.has(t&&t.code),qf}var xc=Nk;Object.defineProperty(Zr,"__esModule",{value:!0});Zr.isNetworkError=t0;Zr.isRetryableError=El;Zr.isSafeRequestError=h4;Zr.isIdempotentRequestError=r0;Zr.isNetworkOrIdempotentRequestError=n0;Zr.exponentialDelay=p4;Zr.default=Qs;Zr.DEFAULT_OPTIONS=Zr.namespace=void 0;var $u=xc($k()),Vk=xc(Sl()),f4=xc(Bk()),qk=xc(Uk()),Wk=xc(zk());function cg(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function Wf(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?cg(Object(r),!0).forEach(function(n){(0,qk.default)(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):cg(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}var e0="axios-retry";Zr.namespace=e0;function t0(e){var t=["ERR_CANCELED","ECONNABORTED"];return!e.response&&!!e.code&&!t.includes(e.code)&&(0,Wk.default)(e)}var d4=["get","head","options"],Gk=d4.concat(["put","delete"]);function El(e){return e.code!=="ECONNABORTED"&&(!e.response||e.response.status>=500&&e.response.status<=599)}function h4(e){return e.config?El(e)&&d4.indexOf(e.config.method)!==-1:!1}function r0(e){return e.config?El(e)&&Gk.indexOf(e.config.method)!==-1:!1}function n0(e){return t0(e)||r0(e)}function Hk(){return 0}function p4(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,t=arguments.length>2&&arguments[2]!==void 0?arguments[2]:100,r=Math.pow(2,e)*t,n=r*.2*Math.random();return r+n}var m4={retries:3,retryCondition:n0,retryDelay:Hk,shouldResetTimeout:!1,onRetry:function(){}};Zr.DEFAULT_OPTIONS=m4;function Kk(e,t){return Wf(Wf(Wf({},m4),t),e[e0])}function ug(e,t){var r=Kk(e,t);return r.retryCount=r.retryCount||0,e[e0]=r,r}function Xk(e,t){e.defaults.agent===t.agent&&delete t.agent,e.defaults.httpAgent===t.httpAgent&&delete t.httpAgent,e.defaults.httpsAgent===t.httpsAgent&&delete t.httpsAgent}function Jk(e,t){return Yd.apply(this,arguments)}function Yd(){return Yd=(0,f4.default)($u.default.mark(function e(t,r){var n,i,s,o;return $u.default.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:if(n=t.retries,i=t.retryCondition,s=t.retryCount<n&&i(r),(0,Vk.default)(s)!=="object"){c.next=13;break}return c.prev=3,c.next=6,s;case 6:return o=c.sent,c.abrupt("return",o!==!1);case 10:return c.prev=10,c.t0=c.catch(3),c.abrupt("return",!1);case 13:return c.abrupt("return",s);case 14:case"end":return c.stop()}},e,null,[[3,10]])})),Yd.apply(this,arguments)}function Qs(e,t){var r=e.interceptors.request.use(function(i){var s=ug(i,t);return s.lastRequestTime=Date.now(),i}),n=e.interceptors.response.use(null,function(){var i=(0,f4.default)($u.default.mark(function s(o){var a,c,u,l,f,h,y,b;return $u.default.wrap(function(T){for(;;)switch(T.prev=T.next){case 0:if(a=o.config,a){T.next=3;break}return T.abrupt("return",Promise.reject(o));case 3:return c=ug(a,t),T.next=6,Jk(c,o);case 6:if(!T.sent){T.next=21;break}if(c.retryCount+=1,u=c.retryDelay,l=c.shouldResetTimeout,f=c.onRetry,h=u(c.retryCount,o),Xk(e,a),!(!l&&a.timeout&&c.lastRequestTime)){T.next=17;break}if(y=Date.now()-c.lastRequestTime,b=a.timeout-y-h,!(b<=0)){T.next=16;break}return T.abrupt("return",Promise.reject(o));case 16:a.timeout=b;case 17:return a.transformRequest=[function(P){return P}],T.next=20,f(c.retryCount,o,a);case 20:return T.abrupt("return",new Promise(function(P){return setTimeout(function(){return P(e(a))},h)}));case 21:return T.abrupt("return",Promise.reject(o));case 22:case"end":return T.stop()}},s)}));return function(s){return i.apply(this,arguments)}}());return{requestInterceptorId:r,responseInterceptorId:n}}Qs.isNetworkError=t0;Qs.isSafeRequestError=h4;Qs.isIdempotentRequestError=r0;Qs.isNetworkOrIdempotentRequestError=n0;Qs.exponentialDelay=p4;Qs.isRetryableError=El;const g4=Zr.default;Qp.exports=g4;Qp.exports.default=g4;var Yk=Qp.exports,Cl={},wo=null;typeof WebSocket<"u"?wo=WebSocket:typeof MozWebSocket<"u"?wo=MozWebSocket:typeof Dr<"u"?wo=Dr.WebSocket||Dr.MozWebSocket:typeof window<"u"?wo=window.WebSocket||window.MozWebSocket:typeof self<"u"&&(wo=self.WebSocket||self.MozWebSocket);var Zk=wo,Qk=Dr&&Dr.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Cl,"__esModule",{value:!0});Cl.ResilientWebSocket=void 0;const e9=Qk(Zk),t9=3e4+3e3;class r9{constructor(t,r){vt(this,"endpoint");vt(this,"wsClient");vt(this,"wsUserClosed");vt(this,"wsFailedAttempts");vt(this,"pingTimeout");vt(this,"logger");vt(this,"onError");vt(this,"onMessage");vt(this,"onReconnect");this.endpoint=t,this.logger=r,this.wsFailedAttempts=0,this.onError=n=>{var i;(i=this.logger)==null||i.error(n)},this.wsUserClosed=!0,this.onMessage=()=>{},this.onReconnect=()=>{}}async send(t){var r,n,i;(r=this.logger)==null||r.info(`Sending ${t}`),await this.waitForMaybeReadyWebSocket(),this.wsClient===void 0?(n=this.logger)==null||n.error("Couldn't connect to the websocket server. Error callback is called."):(i=this.wsClient)==null||i.send(t)}async startWebSocket(){var t;this.wsClient===void 0&&((t=this.logger)==null||t.info("Creating Web Socket client"),this.wsClient=new e9.default(this.endpoint),this.wsUserClosed=!1,this.wsClient.onopen=()=>{this.wsFailedAttempts=0,this.wsClient.on!==void 0&&this.heartbeat()},this.wsClient.onerror=r=>{this.onError(r.error)},this.wsClient.onmessage=r=>{this.onMessage(r.data)},this.wsClient.onclose=async()=>{var r,n;if(this.pingTimeout!==void 0&&clearInterval(this.pingTimeout),this.wsUserClosed===!1){this.wsFailedAttempts+=1,this.wsClient=void 0;const i=n9(this.wsFailedAttempts);(r=this.logger)==null||r.error(`Connection closed unexpectedly or because of timeout. Reconnecting after ${i}ms.`),await lg(i),this.restartUnexpectedClosedWebsocket()}else(n=this.logger)==null||n.info("The connection has been closed successfully.")},this.wsClient.on!==void 0&&this.wsClient.on("ping",this.heartbeat.bind(this)))}heartbeat(){var t;(t=this.logger)==null||t.info("Heartbeat"),this.pingTimeout!==void 0&&clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{var r,n;(r=this.logger)==null||r.warn("Connection timed out. Reconnecting..."),(n=this.wsClient)==null||n.terminate(),this.restartUnexpectedClosedWebsocket()},t9)}async waitForMaybeReadyWebSocket(){let t=0;for(;this.wsClient!==void 0&&this.wsClient.readyState!==this.wsClient.OPEN;)if(t>5e3){this.wsClient.close();return}else t+=10,await lg(10)}async restartUnexpectedClosedWebsocket(){var t;if(this.wsUserClosed!==!0){if(await this.startWebSocket(),await this.waitForMaybeReadyWebSocket(),this.wsClient===void 0){(t=this.logger)==null||t.error("Couldn't reconnect to websocket. Error callback is called.");return}this.onReconnect()}}closeWebSocket(){if(this.wsClient!==void 0){const t=this.wsClient;this.wsClient=void 0,t.close()}this.wsUserClosed=!0}}Cl.ResilientWebSocket=r9;async function lg(e){return new Promise(t=>setTimeout(t,e))}function n9(e){return 2**e*100}var Bo={};Object.defineProperty(Bo,"__esModule",{value:!0});Bo.removeLeading0xIfExists=Bo.makeWebsocketUrl=void 0;function i9(e){const t=new URL("ws",e),r=t.protocol==="https:";return t.protocol=r?"wss:":"ws:",t.toString()}Bo.makeWebsocketUrl=i9;function s9(e){return e.startsWith("0x")?e.substring(2):e}Bo.removeLeading0xIfExists=s9;var v4=Dr&&Dr.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(hl,"__esModule",{value:!0});hl.PriceServiceConnection=void 0;const Gf=qp,o9=v4(u4),fg=v4(Yk),a9=Cl,Hf=Bo;class c9{constructor(t,r){vt(this,"httpClient");vt(this,"priceFeedCallbacks");vt(this,"wsClient");vt(this,"wsEndpoint");vt(this,"logger");vt(this,"priceFeedRequestConfig");vt(this,"onWsError");var n,i,s;this.httpClient=o9.default.create({baseURL:t,timeout:(r==null?void 0:r.timeout)||5e3}),(0,fg.default)(this.httpClient,{retries:(r==null?void 0:r.httpRetries)||3,retryDelay:fg.default.exponentialDelay}),this.priceFeedRequestConfig={binary:(n=r==null?void 0:r.priceFeedRequestConfig)==null?void 0:n.binary,verbose:((i=r==null?void 0:r.priceFeedRequestConfig)==null?void 0:i.verbose)??(r==null?void 0:r.verbose),allowOutOfOrder:(s=r==null?void 0:r.priceFeedRequestConfig)==null?void 0:s.allowOutOfOrder},this.priceFeedCallbacks=new Map,this.logger=(r==null?void 0:r.logger)||{trace:()=>{},debug:()=>{},info:()=>{},warn:console.warn,error:console.error},this.onWsError=o=>{this.logger.error(o),typeof Tn<"u"&&typeof Tn.exit=="function"?(this.logger.error("Halting the process due to the websocket error"),Tn.exit(1)):this.logger.error("Cannot halt process. Please handle the websocket error.")},this.wsEndpoint=(0,Hf.makeWebsocketUrl)(t)}async getLatestPriceFeeds(t){return t.length===0?[]:(await this.httpClient.get("/api/latest_price_feeds",{params:{ids:t,verbose:this.priceFeedRequestConfig.verbose,binary:this.priceFeedRequestConfig.binary}})).data.map(i=>Gf.PriceFeed.fromJson(i))}async getLatestVaas(t){return(await this.httpClient.get("/api/latest_vaas",{params:{ids:t}})).data}async getVaa(t,r){const n=await this.httpClient.get("/api/get_vaa",{params:{id:t,publish_time:r}});return[n.data.vaa,n.data.publishTime]}async getPriceFeed(t,r){const n=await this.httpClient.get("/api/get_price_feed",{params:{id:t,publish_time:r,verbose:this.priceFeedRequestConfig.verbose,binary:this.priceFeedRequestConfig.binary}});return Gf.PriceFeed.fromJson(n.data)}async getPriceFeedIds(){return(await this.httpClient.get("/api/price_feed_ids")).data}async subscribePriceFeedUpdates(t,r){var s;this.wsClient===void 0&&await this.startWebSocket(),t=t.map(o=>(0,Hf.removeLeading0xIfExists)(o));const n=[];for(const o of t)this.priceFeedCallbacks.has(o)||(this.priceFeedCallbacks.set(o,new Set),n.push(o)),this.priceFeedCallbacks.get(o).add(r);const i={ids:n,type:"subscribe",verbose:this.priceFeedRequestConfig.verbose,binary:this.priceFeedRequestConfig.binary,allow_out_of_order:this.priceFeedRequestConfig.allowOutOfOrder};await((s=this.wsClient)==null?void 0:s.send(JSON.stringify(i)))}async unsubscribePriceFeedUpdates(t,r){var s;this.wsClient===void 0&&await this.startWebSocket(),t=t.map(o=>(0,Hf.removeLeading0xIfExists)(o));const n=[];for(const o of t)if(this.priceFeedCallbacks.has(o)){let a=!1;r===void 0?(this.priceFeedCallbacks.delete(o),a=!0):(this.priceFeedCallbacks.get(o).delete(r),this.priceFeedCallbacks.get(o).size===0&&(this.priceFeedCallbacks.delete(o),a=!0)),a&&n.push(o)}const i={ids:n,type:"unsubscribe"};await((s=this.wsClient)==null?void 0:s.send(JSON.stringify(i))),this.priceFeedCallbacks.size===0&&this.closeWebSocket()}async startWebSocket(){if(this.wsEndpoint===void 0)throw new Error("Websocket endpoint is undefined.");this.wsClient=new a9.ResilientWebSocket(this.wsEndpoint,this.logger),this.wsClient.onError=this.onWsError,this.wsClient.onReconnect=()=>{var t;if(this.priceFeedCallbacks.size>0){const r={ids:Array.from(this.priceFeedCallbacks.keys()),type:"subscribe",verbose:this.priceFeedRequestConfig.verbose,binary:this.priceFeedRequestConfig.binary,allow_out_of_order:this.priceFeedRequestConfig.allowOutOfOrder};this.logger.info("Resubscribing to existing price feeds."),(t=this.wsClient)==null||t.send(JSON.stringify(r))}},this.wsClient.onMessage=t=>{this.logger.info(`Received message ${t.toString()}`);let r;try{r=JSON.parse(t.toString())}catch(n){this.logger.error(`Error parsing message ${t.toString()} as JSON.`),this.logger.error(n),this.onWsError(n);return}if(r.type==="response")r.status==="error"&&(this.logger.error(`Error response from the websocket server ${r.error}.`),this.onWsError(new Error(r.error)));else if(r.type==="price_update"){let n;try{n=Gf.PriceFeed.fromJson(r.price_feed)}catch(i){this.logger.error(`Error parsing price feeds from message ${t.toString()}.`),this.logger.error(i),this.onWsError(i);return}if(this.priceFeedCallbacks.has(n.id))for(const i of this.priceFeedCallbacks.get(n.id))i(n)}else this.logger.warn(`Ignoring unsupported server response ${t.toString()}.`)},await this.wsClient.startWebSocket()}closeWebSocket(){var t;(t=this.wsClient)==null||t.closeWebSocket(),this.wsClient=void 0,this.priceFeedCallbacks.clear()}}hl.PriceServiceConnection=c9;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.parseAccumulatorUpdateData=e.isAccumulatorUpdateData=e.Price=e.PriceFeed=e.PriceFeedMetadata=e.PriceServiceConnection=void 0;var t=hl;Object.defineProperty(e,"PriceServiceConnection",{enumerable:!0,get:function(){return t.PriceServiceConnection}});var r=qp;Object.defineProperty(e,"PriceFeedMetadata",{enumerable:!0,get:function(){return r.PriceFeedMetadata}}),Object.defineProperty(e,"PriceFeed",{enumerable:!0,get:function(){return r.PriceFeed}}),Object.defineProperty(e,"Price",{enumerable:!0,get:function(){return r.Price}}),Object.defineProperty(e,"isAccumulatorUpdateData",{enumerable:!0,get:function(){return r.isAccumulatorUpdateData}}),Object.defineProperty(e,"parseAccumulatorUpdateData",{enumerable:!0,get:function(){return r.parseAccumulatorUpdateData}})})(Vp);Object.defineProperty(dl,"__esModule",{value:!0});dl.SuiPriceServiceConnection=void 0;const u9=Vp,l9=ml();class f9 extends u9.PriceServiceConnection{async getPriceFeedsUpdateData(t){return(await this.getLatestVaas(t)).map(n=>l9.Buffer.from(n,"base64"))}}dl.SuiPriceServiceConnection=f9;var Ml={};Object.defineProperty(Ml,"__esModule",{value:!0});Ml.SuiPythClient=void 0;const $c=S2,oo=ai,d9=ml(),Kf=16*1024;class h9{constructor(t,r,n){vt(this,"provider");vt(this,"pythStateId");vt(this,"wormholeStateId");vt(this,"pythPackageId");vt(this,"wormholePackageId");vt(this,"priceTableInfo");vt(this,"priceFeedObjectIdCache",new Map);vt(this,"baseUpdateFee");this.provider=t,this.pythStateId=r,this.wormholeStateId=n,this.pythPackageId=void 0,this.wormholePackageId=void 0}async getBaseUpdateFee(){if(this.baseUpdateFee===void 0){const t=await this.provider.getObject({id:this.pythStateId,options:{showContent:!0}});if(!t.data||!t.data.content||t.data.content.dataType!=="moveObject")throw new Error("Unable to fetch pyth state object");this.baseUpdateFee=t.data.content.fields.base_update_fee}return this.baseUpdateFee}async getPackageId(t){const r=await this.provider.getObject({id:t,options:{showContent:!0}}).then(n=>{var i,s,o;if(((s=(i=n.data)==null?void 0:i.content)==null?void 0:s.dataType)=="moveObject")return n.data.content.fields;throw console.log((o=n.data)==null?void 0:o.content),new Error(`Cannot fetch package id for object ${t}`)});if("upgrade_cap"in r)return r.upgrade_cap.fields.package;throw new Error("upgrade_cap not found")}async verifyVaas(t,r){const n=await this.getWormholePackageId(),i=[];for(const s of t){const[o]=r.moveCall({target:`${n}::vaa::parse_and_verify`,arguments:[r.object(this.wormholeStateId),r.pure(oo.bcs.vector(oo.bcs.U8).serialize(Array.from(s),{maxSize:Kf}).toBytes()),r.object($c.SUI_CLOCK_OBJECT_ID)]});i.push(o)}return i}async updatePriceFeeds(t,r,n){const i=await this.getPythPackageId();let s;if(r.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");const o=this.extractVaaBytesFromAccumulatorMessage(r[0]),a=await this.verifyVaas([o],t);[s]=t.moveCall({target:`${i}::pyth::create_authenticated_price_infos_using_accumulator`,arguments:[t.object(this.pythStateId),t.pure(oo.bcs.vector(oo.bcs.U8).serialize(Array.from(r[0]),{maxSize:Kf}).toBytes()),a[0],t.object($c.SUI_CLOCK_OBJECT_ID)]});const c=[],u=await this.getBaseUpdateFee(),l=t.splitCoins(t.gas,n.map(()=>t.pure.u64(u)));let f=0;for(const h of n){const y=await this.getPriceFeedObjectId(h);if(!y)throw new Error(`Price feed ${h} not found, please create it first`);c.push(y),[s]=t.moveCall({target:`${i}::pyth::update_single_price_feed`,arguments:[t.object(this.pythStateId),s,t.object(y),l[f],t.object($c.SUI_CLOCK_OBJECT_ID)]}),f++}return t.moveCall({target:`${i}::hot_potato_vector::destroy`,arguments:[s],typeArguments:[`${i}::price_info::PriceInfo`]}),c}async createPriceFeed(t,r){const n=await this.getPythPackageId();if(r.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");const i=this.extractVaaBytesFromAccumulatorMessage(r[0]),s=await this.verifyVaas([i],t);t.moveCall({target:`${n}::pyth::create_price_feeds_using_accumulator`,arguments:[t.object(this.pythStateId),t.pure(oo.bcs.vector(oo.bcs.U8).serialize(Array.from(r[0]),{maxSize:Kf}).toBytes()),s[0],t.object($c.SUI_CLOCK_OBJECT_ID)]})}async getWormholePackageId(){return this.wormholePackageId||(this.wormholePackageId=await this.getPackageId(this.wormholeStateId)),this.wormholePackageId}async getPythPackageId(){return this.pythPackageId||(this.pythPackageId=await this.getPackageId(this.pythStateId)),this.pythPackageId}async getPriceFeedObjectId(t){const r=t.replace("0x","");if(!this.priceFeedObjectIdCache.has(r)){const{id:n,fieldType:i}=await this.getPriceTableInfo(),s=await this.provider.getDynamicFieldObject({parentId:n,name:{type:`${i}::price_identifier::PriceIdentifier`,value:{bytes:Array.from(d9.Buffer.from(r,"hex"))}}});if(!s.data||!s.data.content)return;if(s.data.content.dataType!=="moveObject")throw new Error("Price feed type mismatch");this.priceFeedObjectIdCache.set(r,s.data.content.fields.value)}return this.priceFeedObjectIdCache.get(r)}async getPriceTableInfo(){if(this.priceTableInfo===void 0){const t=await this.provider.getDynamicFieldObject({parentId:this.pythStateId,name:{type:"vector<u8>",value:"price_info"}});if(!t.data||!t.data.type)throw new Error("Price Table not found, contract may not be initialized");let r=t.data.type.replace("0x2::table::Table<","");r=r.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>",""),this.priceTableInfo={id:t.data.objectId,fieldType:r}}return this.priceTableInfo}extractVaaBytesFromAccumulatorMessage(t){const n=7+t.readUint8(6)+1,i=t.readUint16BE(n),s=n+2;return t.subarray(s,s+i)}}Ml.SuiPythClient=h9;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.PriceFeed=e.Price=e.SuiPythClient=e.SuiPriceServiceConnection=void 0;var t=dl;Object.defineProperty(e,"SuiPriceServiceConnection",{enumerable:!0,get:function(){return t.SuiPriceServiceConnection}});var r=Ml;Object.defineProperty(e,"SuiPythClient",{enumerable:!0,get:function(){return r.SuiPythClient}});var n=Vp;Object.defineProperty(e,"Price",{enumerable:!0,get:function(){return n.Price}}),Object.defineProperty(e,"PriceFeed",{enumerable:!0,get:function(){return n.PriceFeed}})})(Dx);var dg=PM,Zd=S2,p9=Co,Bc=Dx,m9=Object.create,i0=Object.defineProperty,g9=Object.defineProperties,v9=Object.getOwnPropertyDescriptor,y9=Object.getOwnPropertyDescriptors,y4=Object.getOwnPropertyNames,hg=Object.getOwnPropertySymbols,b9=Object.getPrototypeOf,b4=Object.prototype.hasOwnProperty,w9=Object.prototype.propertyIsEnumerable,pg=(e,t,r)=>t in e?i0(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,_9=(e,t)=>{for(var r in t||(t={}))b4.call(t,r)&&pg(e,r,t[r]);if(hg)for(var r of hg(t))w9.call(t,r)&&pg(e,r,t[r]);return e},x9=(e,t)=>g9(e,y9(t)),S9=(e=>typeof Kn<"u"?Kn:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof Kn<"u"?Kn:t)[r]}):e)(function(e){if(typeof Kn<"u")return Kn.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')}),E9=(e,t)=>function(){return t||(0,e[y4(e)[0]])((t={exports:{}}).exports,t),t.exports},C9=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of y4(t))!b4.call(e,i)&&i!==r&&i0(e,i,{get:()=>t[i],enumerable:!(n=v9(t,i))||n.enumerable});return e},Qo=(e,t,r)=>(r=e!=null?m9(b9(e)):{},C9(!e||!e.__esModule?i0(r,"default",{value:e,enumerable:!0}):r,e)),_t=(e,t,r)=>new Promise((n,i)=>{var s=c=>{try{a(r.next(c))}catch(u){i(u)}},o=c=>{try{a(r.throw(c))}catch(u){i(u)}},a=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,o);a((r=r.apply(e,t)).next())}),ea=E9({"node_modules/bn.js/lib/bn.js"(e,t){(function(r,n){function i(p,d){if(!p)throw new Error(d||"Assertion failed")}function s(p,d){p.super_=d;var m=function(){};m.prototype=d.prototype,p.prototype=new m,p.prototype.constructor=p}function o(p,d,m){if(o.isBN(p))return p;this.negative=0,this.words=null,this.length=0,this.red=null,p!==null&&((d==="le"||d==="be")&&(m=d,d=10),this._init(p||0,d||10,m||"be"))}typeof r=="object"?r.exports=o:n.BN=o,o.BN=o,o.wordSize=26;var a;try{typeof window<"u"&&typeof window.Buffer<"u"?a=window.Buffer:a=S9("buffer").Buffer}catch{}o.isBN=function(d){return d instanceof o?!0:d!==null&&typeof d=="object"&&d.constructor.wordSize===o.wordSize&&Array.isArray(d.words)},o.max=function(d,m){return d.cmp(m)>0?d:m},o.min=function(d,m){return d.cmp(m)<0?d:m},o.prototype._init=function(d,m,x){if(typeof d=="number")return this._initNumber(d,m,x);if(typeof d=="object")return this._initArray(d,m,x);m==="hex"&&(m=16),i(m===(m|0)&&m>=2&&m<=36),d=d.toString().replace(/\s+/g,"");var M=0;d[0]==="-"&&(M++,this.negative=1),M<d.length&&(m===16?this._parseHex(d,M,x):(this._parseBase(d,m,M),x==="le"&&this._initArray(this.toArray(),m,x)))},o.prototype._initNumber=function(d,m,x){d<0&&(this.negative=1,d=-d),d<67108864?(this.words=[d&67108863],this.length=1):d<4503599627370496?(this.words=[d&67108863,d/67108864&67108863],this.length=2):(i(d<9007199254740992),this.words=[d&67108863,d/67108864&67108863,1],this.length=3),x==="le"&&this._initArray(this.toArray(),m,x)},o.prototype._initArray=function(d,m,x){if(i(typeof d.length=="number"),d.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(d.length/3),this.words=new Array(this.length);for(var M=0;M<this.length;M++)this.words[M]=0;var E,O,C=0;if(x==="be")for(M=d.length-1,E=0;M>=0;M-=3)O=d[M]|d[M-1]<<8|d[M-2]<<16,this.words[E]|=O<<C&67108863,this.words[E+1]=O>>>26-C&67108863,C+=24,C>=26&&(C-=26,E++);else if(x==="le")for(M=0,E=0;M<d.length;M+=3)O=d[M]|d[M+1]<<8|d[M+2]<<16,this.words[E]|=O<<C&67108863,this.words[E+1]=O>>>26-C&67108863,C+=24,C>=26&&(C-=26,E++);return this._strip()};function c(p,d){var m=p.charCodeAt(d);if(m>=48&&m<=57)return m-48;if(m>=65&&m<=70)return m-55;if(m>=97&&m<=102)return m-87;i(!1,"Invalid character in "+p)}function u(p,d,m){var x=c(p,m);return m-1>=d&&(x|=c(p,m-1)<<4),x}o.prototype._parseHex=function(d,m,x){this.length=Math.ceil((d.length-m)/6),this.words=new Array(this.length);for(var M=0;M<this.length;M++)this.words[M]=0;var E=0,O=0,C;if(x==="be")for(M=d.length-1;M>=m;M-=2)C=u(d,m,M)<<E,this.words[O]|=C&67108863,E>=18?(E-=18,O+=1,this.words[O]|=C>>>26):E+=8;else{var g=d.length-m;for(M=g%2===0?m+1:m;M<d.length;M+=2)C=u(d,m,M)<<E,this.words[O]|=C&67108863,E>=18?(E-=18,O+=1,this.words[O]|=C>>>26):E+=8}this._strip()};function l(p,d,m,x){for(var M=0,E=0,O=Math.min(p.length,m),C=d;C<O;C++){var g=p.charCodeAt(C)-48;M*=x,g>=49?E=g-49+10:g>=17?E=g-17+10:E=g,i(g>=0&&E<x,"Invalid character"),M+=E}return M}o.prototype._parseBase=function(d,m,x){this.words=[0],this.length=1;for(var M=0,E=1;E<=67108863;E*=m)M++;M--,E=E/m|0;for(var O=d.length-x,C=O%M,g=Math.min(O,O-C)+x,v=0,j=x;j<g;j+=M)v=l(d,j,j+M,m),this.imuln(E),this.words[0]+v<67108864?this.words[0]+=v:this._iaddn(v);if(C!==0){var ee=1;for(v=l(d,j,d.length,m),j=0;j<C;j++)ee*=m;this.imuln(ee),this.words[0]+v<67108864?this.words[0]+=v:this._iaddn(v)}this._strip()},o.prototype.copy=function(d){d.words=new Array(this.length);for(var m=0;m<this.length;m++)d.words[m]=this.words[m];d.length=this.length,d.negative=this.negative,d.red=this.red};function f(p,d){p.words=d.words,p.length=d.length,p.negative=d.negative,p.red=d.red}if(o.prototype._move=function(d){f(d,this)},o.prototype.clone=function(){var d=new o(null);return this.copy(d),d},o.prototype._expand=function(d){for(;this.length<d;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=h}catch{o.prototype.inspect=h}else o.prototype.inspect=h;function h(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var y=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],b=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],w=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(d,m){d=d||10,m=m|0||1;var x;if(d===16||d==="hex"){x="";for(var M=0,E=0,O=0;O<this.length;O++){var C=this.words[O],g=((C<<M|E)&16777215).toString(16);E=C>>>24-M&16777215,M+=2,M>=26&&(M-=26,O--),E!==0||O!==this.length-1?x=y[6-g.length]+g+x:x=g+x}for(E!==0&&(x=E.toString(16)+x);x.length%m!==0;)x="0"+x;return this.negative!==0&&(x="-"+x),x}if(d===(d|0)&&d>=2&&d<=36){var v=b[d],j=w[d];x="";var ee=this.clone();for(ee.negative=0;!ee.isZero();){var ie=ee.modrn(j).toString(d);ee=ee.idivn(j),ee.isZero()?x=ie+x:x=y[v-ie.length]+ie+x}for(this.isZero()&&(x="0"+x);x.length%m!==0;)x="0"+x;return this.negative!==0&&(x="-"+x),x}i(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var d=this.words[0];return this.length===2?d+=this.words[1]*67108864:this.length===3&&this.words[2]===1?d+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-d:d},o.prototype.toJSON=function(){return this.toString(16,2)},a&&(o.prototype.toBuffer=function(d,m){return this.toArrayLike(a,d,m)}),o.prototype.toArray=function(d,m){return this.toArrayLike(Array,d,m)};var T=function(d,m){return d.allocUnsafe?d.allocUnsafe(m):new d(m)};o.prototype.toArrayLike=function(d,m,x){this._strip();var M=this.byteLength(),E=x||Math.max(1,M);i(M<=E,"byte array longer than desired length"),i(E>0,"Requested array length <= 0");var O=T(d,E),C=m==="le"?"LE":"BE";return this["_toArrayLike"+C](O,M),O},o.prototype._toArrayLikeLE=function(d,m){for(var x=0,M=0,E=0,O=0;E<this.length;E++){var C=this.words[E]<<O|M;d[x++]=C&255,x<d.length&&(d[x++]=C>>8&255),x<d.length&&(d[x++]=C>>16&255),O===6?(x<d.length&&(d[x++]=C>>24&255),M=0,O=0):(M=C>>>24,O+=2)}if(x<d.length)for(d[x++]=M;x<d.length;)d[x++]=0},o.prototype._toArrayLikeBE=function(d,m){for(var x=d.length-1,M=0,E=0,O=0;E<this.length;E++){var C=this.words[E]<<O|M;d[x--]=C&255,x>=0&&(d[x--]=C>>8&255),x>=0&&(d[x--]=C>>16&255),O===6?(x>=0&&(d[x--]=C>>24&255),M=0,O=0):(M=C>>>24,O+=2)}if(x>=0)for(d[x--]=M;x>=0;)d[x--]=0},Math.clz32?o.prototype._countBits=function(d){return 32-Math.clz32(d)}:o.prototype._countBits=function(d){var m=d,x=0;return m>=4096&&(x+=13,m>>>=13),m>=64&&(x+=7,m>>>=7),m>=8&&(x+=4,m>>>=4),m>=2&&(x+=2,m>>>=2),x+m},o.prototype._zeroBits=function(d){if(d===0)return 26;var m=d,x=0;return m&8191||(x+=13,m>>>=13),m&127||(x+=7,m>>>=7),m&15||(x+=4,m>>>=4),m&3||(x+=2,m>>>=2),m&1||x++,x},o.prototype.bitLength=function(){var d=this.words[this.length-1],m=this._countBits(d);return(this.length-1)*26+m};function P(p){for(var d=new Array(p.bitLength()),m=0;m<d.length;m++){var x=m/26|0,M=m%26;d[m]=p.words[x]>>>M&1}return d}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var d=0,m=0;m<this.length;m++){var x=this._zeroBits(this.words[m]);if(d+=x,x!==26)break}return d},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(d){return this.negative!==0?this.abs().inotn(d).iaddn(1):this.clone()},o.prototype.fromTwos=function(d){return this.testn(d-1)?this.notn(d).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(d){for(;this.length<d.length;)this.words[this.length++]=0;for(var m=0;m<d.length;m++)this.words[m]=this.words[m]|d.words[m];return this._strip()},o.prototype.ior=function(d){return i((this.negative|d.negative)===0),this.iuor(d)},o.prototype.or=function(d){return this.length>d.length?this.clone().ior(d):d.clone().ior(this)},o.prototype.uor=function(d){return this.length>d.length?this.clone().iuor(d):d.clone().iuor(this)},o.prototype.iuand=function(d){var m;this.length>d.length?m=d:m=this;for(var x=0;x<m.length;x++)this.words[x]=this.words[x]&d.words[x];return this.length=m.length,this._strip()},o.prototype.iand=function(d){return i((this.negative|d.negative)===0),this.iuand(d)},o.prototype.and=function(d){return this.length>d.length?this.clone().iand(d):d.clone().iand(this)},o.prototype.uand=function(d){return this.length>d.length?this.clone().iuand(d):d.clone().iuand(this)},o.prototype.iuxor=function(d){var m,x;this.length>d.length?(m=this,x=d):(m=d,x=this);for(var M=0;M<x.length;M++)this.words[M]=m.words[M]^x.words[M];if(this!==m)for(;M<m.length;M++)this.words[M]=m.words[M];return this.length=m.length,this._strip()},o.prototype.ixor=function(d){return i((this.negative|d.negative)===0),this.iuxor(d)},o.prototype.xor=function(d){return this.length>d.length?this.clone().ixor(d):d.clone().ixor(this)},o.prototype.uxor=function(d){return this.length>d.length?this.clone().iuxor(d):d.clone().iuxor(this)},o.prototype.inotn=function(d){i(typeof d=="number"&&d>=0);var m=Math.ceil(d/26)|0,x=d%26;this._expand(m),x>0&&m--;for(var M=0;M<m;M++)this.words[M]=~this.words[M]&67108863;return x>0&&(this.words[M]=~this.words[M]&67108863>>26-x),this._strip()},o.prototype.notn=function(d){return this.clone().inotn(d)},o.prototype.setn=function(d,m){i(typeof d=="number"&&d>=0);var x=d/26|0,M=d%26;return this._expand(x+1),m?this.words[x]=this.words[x]|1<<M:this.words[x]=this.words[x]&~(1<<M),this._strip()},o.prototype.iadd=function(d){var m;if(this.negative!==0&&d.negative===0)return this.negative=0,m=this.isub(d),this.negative^=1,this._normSign();if(this.negative===0&&d.negative!==0)return d.negative=0,m=this.isub(d),d.negative=1,m._normSign();var x,M;this.length>d.length?(x=this,M=d):(x=d,M=this);for(var E=0,O=0;O<M.length;O++)m=(x.words[O]|0)+(M.words[O]|0)+E,this.words[O]=m&67108863,E=m>>>26;for(;E!==0&&O<x.length;O++)m=(x.words[O]|0)+E,this.words[O]=m&67108863,E=m>>>26;if(this.length=x.length,E!==0)this.words[this.length]=E,this.length++;else if(x!==this)for(;O<x.length;O++)this.words[O]=x.words[O];return this},o.prototype.add=function(d){var m;return d.negative!==0&&this.negative===0?(d.negative=0,m=this.sub(d),d.negative^=1,m):d.negative===0&&this.negative!==0?(this.negative=0,m=d.sub(this),this.negative=1,m):this.length>d.length?this.clone().iadd(d):d.clone().iadd(this)},o.prototype.isub=function(d){if(d.negative!==0){d.negative=0;var m=this.iadd(d);return d.negative=1,m._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(d),this.negative=1,this._normSign();var x=this.cmp(d);if(x===0)return this.negative=0,this.length=1,this.words[0]=0,this;var M,E;x>0?(M=this,E=d):(M=d,E=this);for(var O=0,C=0;C<E.length;C++)m=(M.words[C]|0)-(E.words[C]|0)+O,O=m>>26,this.words[C]=m&67108863;for(;O!==0&&C<M.length;C++)m=(M.words[C]|0)+O,O=m>>26,this.words[C]=m&67108863;if(O===0&&C<M.length&&M!==this)for(;C<M.length;C++)this.words[C]=M.words[C];return this.length=Math.max(this.length,C),M!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(d){return this.clone().isub(d)};function k(p,d,m){m.negative=d.negative^p.negative;var x=p.length+d.length|0;m.length=x,x=x-1|0;var M=p.words[0]|0,E=d.words[0]|0,O=M*E,C=O&67108863,g=O/67108864|0;m.words[0]=C;for(var v=1;v<x;v++){for(var j=g>>>26,ee=g&67108863,ie=Math.min(v,d.length-1),de=Math.max(0,v-p.length+1);de<=ie;de++){var ye=v-de|0;M=p.words[ye]|0,E=d.words[de]|0,O=M*E+ee,j+=O/67108864|0,ee=O&67108863}m.words[v]=ee|0,g=j|0}return g!==0?m.words[v]=g|0:m.length--,m._strip()}var N=function(d,m,x){var M=d.words,E=m.words,O=x.words,C=0,g,v,j,ee=M[0]|0,ie=ee&8191,de=ee>>>13,ye=M[1]|0,Ee=ye&8191,Se=ye>>>13,Ge=M[2]|0,Ue=Ge&8191,dt=Ge>>>13,ht=M[3]|0,$e=ht&8191,mt=ht>>>13,xe=M[4]|0,ge=xe&8191,Te=xe>>>13,qe=M[5]|0,De=qe&8191,Oe=qe>>>13,Ie=M[6]|0,Fe=Ie&8191,lt=Ie>>>13,ft=M[7]|0,He=ft&8191,jt=ft>>>13,St=M[8]|0,Ze=St&8191,At=St>>>13,Nt=M[9]|0,nt=Nt&8191,Et=Nt>>>13,Tt=E[0]|0,st=Tt&8191,kt=Tt>>>13,It=E[1]|0,it=It&8191,bt=It>>>13,Ct=E[2]|0,Ye=Ct&8191,gt=Ct>>>13,Pt=E[3]|0,ot=Pt&8191,wt=Pt>>>13,Ut=E[4]|0,R=Ut&8191,S=Ut>>>13,A=E[5]|0,B=A&8191,K=A>>>13,Z=E[6]|0,te=Z&8191,Be=Z>>>13,tt=E[7]|0,Ne=tt&8191,z=tt>>>13,oe=E[8]|0,pe=oe&8191,ke=oe>>>13,Ke=E[9]|0,Re=Ke&8191,ze=Ke>>>13;x.negative=d.negative^m.negative,x.length=19,g=Math.imul(ie,st),v=Math.imul(ie,kt),v=v+Math.imul(de,st)|0,j=Math.imul(de,kt);var at=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(at>>>26)|0,at&=67108863,g=Math.imul(Ee,st),v=Math.imul(Ee,kt),v=v+Math.imul(Se,st)|0,j=Math.imul(Se,kt),g=g+Math.imul(ie,it)|0,v=v+Math.imul(ie,bt)|0,v=v+Math.imul(de,it)|0,j=j+Math.imul(de,bt)|0;var Ht=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,g=Math.imul(Ue,st),v=Math.imul(Ue,kt),v=v+Math.imul(dt,st)|0,j=Math.imul(dt,kt),g=g+Math.imul(Ee,it)|0,v=v+Math.imul(Ee,bt)|0,v=v+Math.imul(Se,it)|0,j=j+Math.imul(Se,bt)|0,g=g+Math.imul(ie,Ye)|0,v=v+Math.imul(ie,gt)|0,v=v+Math.imul(de,Ye)|0,j=j+Math.imul(de,gt)|0;var Rt=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,g=Math.imul($e,st),v=Math.imul($e,kt),v=v+Math.imul(mt,st)|0,j=Math.imul(mt,kt),g=g+Math.imul(Ue,it)|0,v=v+Math.imul(Ue,bt)|0,v=v+Math.imul(dt,it)|0,j=j+Math.imul(dt,bt)|0,g=g+Math.imul(Ee,Ye)|0,v=v+Math.imul(Ee,gt)|0,v=v+Math.imul(Se,Ye)|0,j=j+Math.imul(Se,gt)|0,g=g+Math.imul(ie,ot)|0,v=v+Math.imul(ie,wt)|0,v=v+Math.imul(de,ot)|0,j=j+Math.imul(de,wt)|0;var Dt=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,g=Math.imul(ge,st),v=Math.imul(ge,kt),v=v+Math.imul(Te,st)|0,j=Math.imul(Te,kt),g=g+Math.imul($e,it)|0,v=v+Math.imul($e,bt)|0,v=v+Math.imul(mt,it)|0,j=j+Math.imul(mt,bt)|0,g=g+Math.imul(Ue,Ye)|0,v=v+Math.imul(Ue,gt)|0,v=v+Math.imul(dt,Ye)|0,j=j+Math.imul(dt,gt)|0,g=g+Math.imul(Ee,ot)|0,v=v+Math.imul(Ee,wt)|0,v=v+Math.imul(Se,ot)|0,j=j+Math.imul(Se,wt)|0,g=g+Math.imul(ie,R)|0,v=v+Math.imul(ie,S)|0,v=v+Math.imul(de,R)|0,j=j+Math.imul(de,S)|0;var er=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(er>>>26)|0,er&=67108863,g=Math.imul(De,st),v=Math.imul(De,kt),v=v+Math.imul(Oe,st)|0,j=Math.imul(Oe,kt),g=g+Math.imul(ge,it)|0,v=v+Math.imul(ge,bt)|0,v=v+Math.imul(Te,it)|0,j=j+Math.imul(Te,bt)|0,g=g+Math.imul($e,Ye)|0,v=v+Math.imul($e,gt)|0,v=v+Math.imul(mt,Ye)|0,j=j+Math.imul(mt,gt)|0,g=g+Math.imul(Ue,ot)|0,v=v+Math.imul(Ue,wt)|0,v=v+Math.imul(dt,ot)|0,j=j+Math.imul(dt,wt)|0,g=g+Math.imul(Ee,R)|0,v=v+Math.imul(Ee,S)|0,v=v+Math.imul(Se,R)|0,j=j+Math.imul(Se,S)|0,g=g+Math.imul(ie,B)|0,v=v+Math.imul(ie,K)|0,v=v+Math.imul(de,B)|0,j=j+Math.imul(de,K)|0;var br=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(br>>>26)|0,br&=67108863,g=Math.imul(Fe,st),v=Math.imul(Fe,kt),v=v+Math.imul(lt,st)|0,j=Math.imul(lt,kt),g=g+Math.imul(De,it)|0,v=v+Math.imul(De,bt)|0,v=v+Math.imul(Oe,it)|0,j=j+Math.imul(Oe,bt)|0,g=g+Math.imul(ge,Ye)|0,v=v+Math.imul(ge,gt)|0,v=v+Math.imul(Te,Ye)|0,j=j+Math.imul(Te,gt)|0,g=g+Math.imul($e,ot)|0,v=v+Math.imul($e,wt)|0,v=v+Math.imul(mt,ot)|0,j=j+Math.imul(mt,wt)|0,g=g+Math.imul(Ue,R)|0,v=v+Math.imul(Ue,S)|0,v=v+Math.imul(dt,R)|0,j=j+Math.imul(dt,S)|0,g=g+Math.imul(Ee,B)|0,v=v+Math.imul(Ee,K)|0,v=v+Math.imul(Se,B)|0,j=j+Math.imul(Se,K)|0,g=g+Math.imul(ie,te)|0,v=v+Math.imul(ie,Be)|0,v=v+Math.imul(de,te)|0,j=j+Math.imul(de,Be)|0;var ir=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(ir>>>26)|0,ir&=67108863,g=Math.imul(He,st),v=Math.imul(He,kt),v=v+Math.imul(jt,st)|0,j=Math.imul(jt,kt),g=g+Math.imul(Fe,it)|0,v=v+Math.imul(Fe,bt)|0,v=v+Math.imul(lt,it)|0,j=j+Math.imul(lt,bt)|0,g=g+Math.imul(De,Ye)|0,v=v+Math.imul(De,gt)|0,v=v+Math.imul(Oe,Ye)|0,j=j+Math.imul(Oe,gt)|0,g=g+Math.imul(ge,ot)|0,v=v+Math.imul(ge,wt)|0,v=v+Math.imul(Te,ot)|0,j=j+Math.imul(Te,wt)|0,g=g+Math.imul($e,R)|0,v=v+Math.imul($e,S)|0,v=v+Math.imul(mt,R)|0,j=j+Math.imul(mt,S)|0,g=g+Math.imul(Ue,B)|0,v=v+Math.imul(Ue,K)|0,v=v+Math.imul(dt,B)|0,j=j+Math.imul(dt,K)|0,g=g+Math.imul(Ee,te)|0,v=v+Math.imul(Ee,Be)|0,v=v+Math.imul(Se,te)|0,j=j+Math.imul(Se,Be)|0,g=g+Math.imul(ie,Ne)|0,v=v+Math.imul(ie,z)|0,v=v+Math.imul(de,Ne)|0,j=j+Math.imul(de,z)|0;var Kt=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Kt>>>26)|0,Kt&=67108863,g=Math.imul(Ze,st),v=Math.imul(Ze,kt),v=v+Math.imul(At,st)|0,j=Math.imul(At,kt),g=g+Math.imul(He,it)|0,v=v+Math.imul(He,bt)|0,v=v+Math.imul(jt,it)|0,j=j+Math.imul(jt,bt)|0,g=g+Math.imul(Fe,Ye)|0,v=v+Math.imul(Fe,gt)|0,v=v+Math.imul(lt,Ye)|0,j=j+Math.imul(lt,gt)|0,g=g+Math.imul(De,ot)|0,v=v+Math.imul(De,wt)|0,v=v+Math.imul(Oe,ot)|0,j=j+Math.imul(Oe,wt)|0,g=g+Math.imul(ge,R)|0,v=v+Math.imul(ge,S)|0,v=v+Math.imul(Te,R)|0,j=j+Math.imul(Te,S)|0,g=g+Math.imul($e,B)|0,v=v+Math.imul($e,K)|0,v=v+Math.imul(mt,B)|0,j=j+Math.imul(mt,K)|0,g=g+Math.imul(Ue,te)|0,v=v+Math.imul(Ue,Be)|0,v=v+Math.imul(dt,te)|0,j=j+Math.imul(dt,Be)|0,g=g+Math.imul(Ee,Ne)|0,v=v+Math.imul(Ee,z)|0,v=v+Math.imul(Se,Ne)|0,j=j+Math.imul(Se,z)|0,g=g+Math.imul(ie,pe)|0,v=v+Math.imul(ie,ke)|0,v=v+Math.imul(de,pe)|0,j=j+Math.imul(de,ke)|0;var vr=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(vr>>>26)|0,vr&=67108863,g=Math.imul(nt,st),v=Math.imul(nt,kt),v=v+Math.imul(Et,st)|0,j=Math.imul(Et,kt),g=g+Math.imul(Ze,it)|0,v=v+Math.imul(Ze,bt)|0,v=v+Math.imul(At,it)|0,j=j+Math.imul(At,bt)|0,g=g+Math.imul(He,Ye)|0,v=v+Math.imul(He,gt)|0,v=v+Math.imul(jt,Ye)|0,j=j+Math.imul(jt,gt)|0,g=g+Math.imul(Fe,ot)|0,v=v+Math.imul(Fe,wt)|0,v=v+Math.imul(lt,ot)|0,j=j+Math.imul(lt,wt)|0,g=g+Math.imul(De,R)|0,v=v+Math.imul(De,S)|0,v=v+Math.imul(Oe,R)|0,j=j+Math.imul(Oe,S)|0,g=g+Math.imul(ge,B)|0,v=v+Math.imul(ge,K)|0,v=v+Math.imul(Te,B)|0,j=j+Math.imul(Te,K)|0,g=g+Math.imul($e,te)|0,v=v+Math.imul($e,Be)|0,v=v+Math.imul(mt,te)|0,j=j+Math.imul(mt,Be)|0,g=g+Math.imul(Ue,Ne)|0,v=v+Math.imul(Ue,z)|0,v=v+Math.imul(dt,Ne)|0,j=j+Math.imul(dt,z)|0,g=g+Math.imul(Ee,pe)|0,v=v+Math.imul(Ee,ke)|0,v=v+Math.imul(Se,pe)|0,j=j+Math.imul(Se,ke)|0,g=g+Math.imul(ie,Re)|0,v=v+Math.imul(ie,ze)|0,v=v+Math.imul(de,Re)|0,j=j+Math.imul(de,ze)|0;var mn=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(mn>>>26)|0,mn&=67108863,g=Math.imul(nt,it),v=Math.imul(nt,bt),v=v+Math.imul(Et,it)|0,j=Math.imul(Et,bt),g=g+Math.imul(Ze,Ye)|0,v=v+Math.imul(Ze,gt)|0,v=v+Math.imul(At,Ye)|0,j=j+Math.imul(At,gt)|0,g=g+Math.imul(He,ot)|0,v=v+Math.imul(He,wt)|0,v=v+Math.imul(jt,ot)|0,j=j+Math.imul(jt,wt)|0,g=g+Math.imul(Fe,R)|0,v=v+Math.imul(Fe,S)|0,v=v+Math.imul(lt,R)|0,j=j+Math.imul(lt,S)|0,g=g+Math.imul(De,B)|0,v=v+Math.imul(De,K)|0,v=v+Math.imul(Oe,B)|0,j=j+Math.imul(Oe,K)|0,g=g+Math.imul(ge,te)|0,v=v+Math.imul(ge,Be)|0,v=v+Math.imul(Te,te)|0,j=j+Math.imul(Te,Be)|0,g=g+Math.imul($e,Ne)|0,v=v+Math.imul($e,z)|0,v=v+Math.imul(mt,Ne)|0,j=j+Math.imul(mt,z)|0,g=g+Math.imul(Ue,pe)|0,v=v+Math.imul(Ue,ke)|0,v=v+Math.imul(dt,pe)|0,j=j+Math.imul(dt,ke)|0,g=g+Math.imul(Ee,Re)|0,v=v+Math.imul(Ee,ze)|0,v=v+Math.imul(Se,Re)|0,j=j+Math.imul(Se,ze)|0;var Fr=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,g=Math.imul(nt,Ye),v=Math.imul(nt,gt),v=v+Math.imul(Et,Ye)|0,j=Math.imul(Et,gt),g=g+Math.imul(Ze,ot)|0,v=v+Math.imul(Ze,wt)|0,v=v+Math.imul(At,ot)|0,j=j+Math.imul(At,wt)|0,g=g+Math.imul(He,R)|0,v=v+Math.imul(He,S)|0,v=v+Math.imul(jt,R)|0,j=j+Math.imul(jt,S)|0,g=g+Math.imul(Fe,B)|0,v=v+Math.imul(Fe,K)|0,v=v+Math.imul(lt,B)|0,j=j+Math.imul(lt,K)|0,g=g+Math.imul(De,te)|0,v=v+Math.imul(De,Be)|0,v=v+Math.imul(Oe,te)|0,j=j+Math.imul(Oe,Be)|0,g=g+Math.imul(ge,Ne)|0,v=v+Math.imul(ge,z)|0,v=v+Math.imul(Te,Ne)|0,j=j+Math.imul(Te,z)|0,g=g+Math.imul($e,pe)|0,v=v+Math.imul($e,ke)|0,v=v+Math.imul(mt,pe)|0,j=j+Math.imul(mt,ke)|0,g=g+Math.imul(Ue,Re)|0,v=v+Math.imul(Ue,ze)|0,v=v+Math.imul(dt,Re)|0,j=j+Math.imul(dt,ze)|0;var gn=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(gn>>>26)|0,gn&=67108863,g=Math.imul(nt,ot),v=Math.imul(nt,wt),v=v+Math.imul(Et,ot)|0,j=Math.imul(Et,wt),g=g+Math.imul(Ze,R)|0,v=v+Math.imul(Ze,S)|0,v=v+Math.imul(At,R)|0,j=j+Math.imul(At,S)|0,g=g+Math.imul(He,B)|0,v=v+Math.imul(He,K)|0,v=v+Math.imul(jt,B)|0,j=j+Math.imul(jt,K)|0,g=g+Math.imul(Fe,te)|0,v=v+Math.imul(Fe,Be)|0,v=v+Math.imul(lt,te)|0,j=j+Math.imul(lt,Be)|0,g=g+Math.imul(De,Ne)|0,v=v+Math.imul(De,z)|0,v=v+Math.imul(Oe,Ne)|0,j=j+Math.imul(Oe,z)|0,g=g+Math.imul(ge,pe)|0,v=v+Math.imul(ge,ke)|0,v=v+Math.imul(Te,pe)|0,j=j+Math.imul(Te,ke)|0,g=g+Math.imul($e,Re)|0,v=v+Math.imul($e,ze)|0,v=v+Math.imul(mt,Re)|0,j=j+Math.imul(mt,ze)|0;var fi=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(fi>>>26)|0,fi&=67108863,g=Math.imul(nt,R),v=Math.imul(nt,S),v=v+Math.imul(Et,R)|0,j=Math.imul(Et,S),g=g+Math.imul(Ze,B)|0,v=v+Math.imul(Ze,K)|0,v=v+Math.imul(At,B)|0,j=j+Math.imul(At,K)|0,g=g+Math.imul(He,te)|0,v=v+Math.imul(He,Be)|0,v=v+Math.imul(jt,te)|0,j=j+Math.imul(jt,Be)|0,g=g+Math.imul(Fe,Ne)|0,v=v+Math.imul(Fe,z)|0,v=v+Math.imul(lt,Ne)|0,j=j+Math.imul(lt,z)|0,g=g+Math.imul(De,pe)|0,v=v+Math.imul(De,ke)|0,v=v+Math.imul(Oe,pe)|0,j=j+Math.imul(Oe,ke)|0,g=g+Math.imul(ge,Re)|0,v=v+Math.imul(ge,ze)|0,v=v+Math.imul(Te,Re)|0,j=j+Math.imul(Te,ze)|0;var di=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(di>>>26)|0,di&=67108863,g=Math.imul(nt,B),v=Math.imul(nt,K),v=v+Math.imul(Et,B)|0,j=Math.imul(Et,K),g=g+Math.imul(Ze,te)|0,v=v+Math.imul(Ze,Be)|0,v=v+Math.imul(At,te)|0,j=j+Math.imul(At,Be)|0,g=g+Math.imul(He,Ne)|0,v=v+Math.imul(He,z)|0,v=v+Math.imul(jt,Ne)|0,j=j+Math.imul(jt,z)|0,g=g+Math.imul(Fe,pe)|0,v=v+Math.imul(Fe,ke)|0,v=v+Math.imul(lt,pe)|0,j=j+Math.imul(lt,ke)|0,g=g+Math.imul(De,Re)|0,v=v+Math.imul(De,ze)|0,v=v+Math.imul(Oe,Re)|0,j=j+Math.imul(Oe,ze)|0;var vn=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(vn>>>26)|0,vn&=67108863,g=Math.imul(nt,te),v=Math.imul(nt,Be),v=v+Math.imul(Et,te)|0,j=Math.imul(Et,Be),g=g+Math.imul(Ze,Ne)|0,v=v+Math.imul(Ze,z)|0,v=v+Math.imul(At,Ne)|0,j=j+Math.imul(At,z)|0,g=g+Math.imul(He,pe)|0,v=v+Math.imul(He,ke)|0,v=v+Math.imul(jt,pe)|0,j=j+Math.imul(jt,ke)|0,g=g+Math.imul(Fe,Re)|0,v=v+Math.imul(Fe,ze)|0,v=v+Math.imul(lt,Re)|0,j=j+Math.imul(lt,ze)|0;var hi=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(hi>>>26)|0,hi&=67108863,g=Math.imul(nt,Ne),v=Math.imul(nt,z),v=v+Math.imul(Et,Ne)|0,j=Math.imul(Et,z),g=g+Math.imul(Ze,pe)|0,v=v+Math.imul(Ze,ke)|0,v=v+Math.imul(At,pe)|0,j=j+Math.imul(At,ke)|0,g=g+Math.imul(He,Re)|0,v=v+Math.imul(He,ze)|0,v=v+Math.imul(jt,Re)|0,j=j+Math.imul(jt,ze)|0;var pi=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+(pi>>>26)|0,pi&=67108863,g=Math.imul(nt,pe),v=Math.imul(nt,ke),v=v+Math.imul(Et,pe)|0,j=Math.imul(Et,ke),g=g+Math.imul(Ze,Re)|0,v=v+Math.imul(Ze,ze)|0,v=v+Math.imul(At,Re)|0,j=j+Math.imul(At,ze)|0;var $=(C+g|0)+((v&8191)<<13)|0;C=(j+(v>>>13)|0)+($>>>26)|0,$&=67108863,g=Math.imul(nt,Re),v=Math.imul(nt,ze),v=v+Math.imul(Et,Re)|0,j=Math.imul(Et,ze);var H=(C+g|0)+((v&8191)<<13)|0;return C=(j+(v>>>13)|0)+(H>>>26)|0,H&=67108863,O[0]=at,O[1]=Ht,O[2]=Rt,O[3]=Dt,O[4]=er,O[5]=br,O[6]=ir,O[7]=Kt,O[8]=vr,O[9]=mn,O[10]=Fr,O[11]=gn,O[12]=fi,O[13]=di,O[14]=vn,O[15]=hi,O[16]=pi,O[17]=$,O[18]=H,C!==0&&(O[19]=C,x.length++),x};Math.imul||(N=k);function F(p,d,m){m.negative=d.negative^p.negative,m.length=p.length+d.length;for(var x=0,M=0,E=0;E<m.length-1;E++){var O=M;M=0;for(var C=x&67108863,g=Math.min(E,d.length-1),v=Math.max(0,E-p.length+1);v<=g;v++){var j=E-v,ee=p.words[j]|0,ie=d.words[v]|0,de=ee*ie,ye=de&67108863;O=O+(de/67108864|0)|0,ye=ye+C|0,C=ye&67108863,O=O+(ye>>>26)|0,M+=O>>>26,O&=67108863}m.words[E]=C,x=O,O=M}return x!==0?m.words[E]=x:m.length--,m._strip()}function L(p,d,m){return F(p,d,m)}o.prototype.mulTo=function(d,m){var x,M=this.length+d.length;return this.length===10&&d.length===10?x=N(this,d,m):M<63?x=k(this,d,m):M<1024?x=F(this,d,m):x=L(this,d,m),x},o.prototype.mul=function(d){var m=new o(null);return m.words=new Array(this.length+d.length),this.mulTo(d,m)},o.prototype.mulf=function(d){var m=new o(null);return m.words=new Array(this.length+d.length),L(this,d,m)},o.prototype.imul=function(d){return this.clone().mulTo(d,this)},o.prototype.imuln=function(d){var m=d<0;m&&(d=-d),i(typeof d=="number"),i(d<67108864);for(var x=0,M=0;M<this.length;M++){var E=(this.words[M]|0)*d,O=(E&67108863)+(x&67108863);x>>=26,x+=E/67108864|0,x+=O>>>26,this.words[M]=O&67108863}return x!==0&&(this.words[M]=x,this.length++),m?this.ineg():this},o.prototype.muln=function(d){return this.clone().imuln(d)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(d){var m=P(d);if(m.length===0)return new o(1);for(var x=this,M=0;M<m.length&&m[M]===0;M++,x=x.sqr());if(++M<m.length)for(var E=x.sqr();M<m.length;M++,E=E.sqr())m[M]!==0&&(x=x.mul(E));return x},o.prototype.iushln=function(d){i(typeof d=="number"&&d>=0);var m=d%26,x=(d-m)/26,M=67108863>>>26-m<<26-m,E;if(m!==0){var O=0;for(E=0;E<this.length;E++){var C=this.words[E]&M,g=(this.words[E]|0)-C<<m;this.words[E]=g|O,O=C>>>26-m}O&&(this.words[E]=O,this.length++)}if(x!==0){for(E=this.length-1;E>=0;E--)this.words[E+x]=this.words[E];for(E=0;E<x;E++)this.words[E]=0;this.length+=x}return this._strip()},o.prototype.ishln=function(d){return i(this.negative===0),this.iushln(d)},o.prototype.iushrn=function(d,m,x){i(typeof d=="number"&&d>=0);var M;m?M=(m-m%26)/26:M=0;var E=d%26,O=Math.min((d-E)/26,this.length),C=67108863^67108863>>>E<<E,g=x;if(M-=O,M=Math.max(0,M),g){for(var v=0;v<O;v++)g.words[v]=this.words[v];g.length=O}if(O!==0)if(this.length>O)for(this.length-=O,v=0;v<this.length;v++)this.words[v]=this.words[v+O];else this.words[0]=0,this.length=1;var j=0;for(v=this.length-1;v>=0&&(j!==0||v>=M);v--){var ee=this.words[v]|0;this.words[v]=j<<26-E|ee>>>E,j=ee&C}return g&&j!==0&&(g.words[g.length++]=j),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(d,m,x){return i(this.negative===0),this.iushrn(d,m,x)},o.prototype.shln=function(d){return this.clone().ishln(d)},o.prototype.ushln=function(d){return this.clone().iushln(d)},o.prototype.shrn=function(d){return this.clone().ishrn(d)},o.prototype.ushrn=function(d){return this.clone().iushrn(d)},o.prototype.testn=function(d){i(typeof d=="number"&&d>=0);var m=d%26,x=(d-m)/26,M=1<<m;if(this.length<=x)return!1;var E=this.words[x];return!!(E&M)},o.prototype.imaskn=function(d){i(typeof d=="number"&&d>=0);var m=d%26,x=(d-m)/26;if(i(this.negative===0,"imaskn works only with positive numbers"),this.length<=x)return this;if(m!==0&&x++,this.length=Math.min(x,this.length),m!==0){var M=67108863^67108863>>>m<<m;this.words[this.length-1]&=M}return this._strip()},o.prototype.maskn=function(d){return this.clone().imaskn(d)},o.prototype.iaddn=function(d){return i(typeof d=="number"),i(d<67108864),d<0?this.isubn(-d):this.negative!==0?this.length===1&&(this.words[0]|0)<=d?(this.words[0]=d-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(d),this.negative=1,this):this._iaddn(d)},o.prototype._iaddn=function(d){this.words[0]+=d;for(var m=0;m<this.length&&this.words[m]>=67108864;m++)this.words[m]-=67108864,m===this.length-1?this.words[m+1]=1:this.words[m+1]++;return this.length=Math.max(this.length,m+1),this},o.prototype.isubn=function(d){if(i(typeof d=="number"),i(d<67108864),d<0)return this.iaddn(-d);if(this.negative!==0)return this.negative=0,this.iaddn(d),this.negative=1,this;if(this.words[0]-=d,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var m=0;m<this.length&&this.words[m]<0;m++)this.words[m]+=67108864,this.words[m+1]-=1;return this._strip()},o.prototype.addn=function(d){return this.clone().iaddn(d)},o.prototype.subn=function(d){return this.clone().isubn(d)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(d,m,x){var M=d.length+x,E;this._expand(M);var O,C=0;for(E=0;E<d.length;E++){O=(this.words[E+x]|0)+C;var g=(d.words[E]|0)*m;O-=g&67108863,C=(O>>26)-(g/67108864|0),this.words[E+x]=O&67108863}for(;E<this.length-x;E++)O=(this.words[E+x]|0)+C,C=O>>26,this.words[E+x]=O&67108863;if(C===0)return this._strip();for(i(C===-1),C=0,E=0;E<this.length;E++)O=-(this.words[E]|0)+C,C=O>>26,this.words[E]=O&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(d,m){var x=this.length-d.length,M=this.clone(),E=d,O=E.words[E.length-1]|0,C=this._countBits(O);x=26-C,x!==0&&(E=E.ushln(x),M.iushln(x),O=E.words[E.length-1]|0);var g=M.length-E.length,v;if(m!=="mod"){v=new o(null),v.length=g+1,v.words=new Array(v.length);for(var j=0;j<v.length;j++)v.words[j]=0}var ee=M.clone()._ishlnsubmul(E,1,g);ee.negative===0&&(M=ee,v&&(v.words[g]=1));for(var ie=g-1;ie>=0;ie--){var de=(M.words[E.length+ie]|0)*67108864+(M.words[E.length+ie-1]|0);for(de=Math.min(de/O|0,67108863),M._ishlnsubmul(E,de,ie);M.negative!==0;)de--,M.negative=0,M._ishlnsubmul(E,1,ie),M.isZero()||(M.negative^=1);v&&(v.words[ie]=de)}return v&&v._strip(),M._strip(),m!=="div"&&x!==0&&M.iushrn(x),{div:v||null,mod:M}},o.prototype.divmod=function(d,m,x){if(i(!d.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var M,E,O;return this.negative!==0&&d.negative===0?(O=this.neg().divmod(d,m),m!=="mod"&&(M=O.div.neg()),m!=="div"&&(E=O.mod.neg(),x&&E.negative!==0&&E.iadd(d)),{div:M,mod:E}):this.negative===0&&d.negative!==0?(O=this.divmod(d.neg(),m),m!=="mod"&&(M=O.div.neg()),{div:M,mod:O.mod}):this.negative&d.negative?(O=this.neg().divmod(d.neg(),m),m!=="div"&&(E=O.mod.neg(),x&&E.negative!==0&&E.isub(d)),{div:O.div,mod:E}):d.length>this.length||this.cmp(d)<0?{div:new o(0),mod:this}:d.length===1?m==="div"?{div:this.divn(d.words[0]),mod:null}:m==="mod"?{div:null,mod:new o(this.modrn(d.words[0]))}:{div:this.divn(d.words[0]),mod:new o(this.modrn(d.words[0]))}:this._wordDiv(d,m)},o.prototype.div=function(d){return this.divmod(d,"div",!1).div},o.prototype.mod=function(d){return this.divmod(d,"mod",!1).mod},o.prototype.umod=function(d){return this.divmod(d,"mod",!0).mod},o.prototype.divRound=function(d){var m=this.divmod(d);if(m.mod.isZero())return m.div;var x=m.div.negative!==0?m.mod.isub(d):m.mod,M=d.ushrn(1),E=d.andln(1),O=x.cmp(M);return O<0||E===1&&O===0?m.div:m.div.negative!==0?m.div.isubn(1):m.div.iaddn(1)},o.prototype.modrn=function(d){var m=d<0;m&&(d=-d),i(d<=67108863);for(var x=(1<<26)%d,M=0,E=this.length-1;E>=0;E--)M=(x*M+(this.words[E]|0))%d;return m?-M:M},o.prototype.modn=function(d){return this.modrn(d)},o.prototype.idivn=function(d){var m=d<0;m&&(d=-d),i(d<=67108863);for(var x=0,M=this.length-1;M>=0;M--){var E=(this.words[M]|0)+x*67108864;this.words[M]=E/d|0,x=E%d}return this._strip(),m?this.ineg():this},o.prototype.divn=function(d){return this.clone().idivn(d)},o.prototype.egcd=function(d){i(d.negative===0),i(!d.isZero());var m=this,x=d.clone();m.negative!==0?m=m.umod(d):m=m.clone();for(var M=new o(1),E=new o(0),O=new o(0),C=new o(1),g=0;m.isEven()&&x.isEven();)m.iushrn(1),x.iushrn(1),++g;for(var v=x.clone(),j=m.clone();!m.isZero();){for(var ee=0,ie=1;!(m.words[0]&ie)&&ee<26;++ee,ie<<=1);if(ee>0)for(m.iushrn(ee);ee-- >0;)(M.isOdd()||E.isOdd())&&(M.iadd(v),E.isub(j)),M.iushrn(1),E.iushrn(1);for(var de=0,ye=1;!(x.words[0]&ye)&&de<26;++de,ye<<=1);if(de>0)for(x.iushrn(de);de-- >0;)(O.isOdd()||C.isOdd())&&(O.iadd(v),C.isub(j)),O.iushrn(1),C.iushrn(1);m.cmp(x)>=0?(m.isub(x),M.isub(O),E.isub(C)):(x.isub(m),O.isub(M),C.isub(E))}return{a:O,b:C,gcd:x.iushln(g)}},o.prototype._invmp=function(d){i(d.negative===0),i(!d.isZero());var m=this,x=d.clone();m.negative!==0?m=m.umod(d):m=m.clone();for(var M=new o(1),E=new o(0),O=x.clone();m.cmpn(1)>0&&x.cmpn(1)>0;){for(var C=0,g=1;!(m.words[0]&g)&&C<26;++C,g<<=1);if(C>0)for(m.iushrn(C);C-- >0;)M.isOdd()&&M.iadd(O),M.iushrn(1);for(var v=0,j=1;!(x.words[0]&j)&&v<26;++v,j<<=1);if(v>0)for(x.iushrn(v);v-- >0;)E.isOdd()&&E.iadd(O),E.iushrn(1);m.cmp(x)>=0?(m.isub(x),M.isub(E)):(x.isub(m),E.isub(M))}var ee;return m.cmpn(1)===0?ee=M:ee=E,ee.cmpn(0)<0&&ee.iadd(d),ee},o.prototype.gcd=function(d){if(this.isZero())return d.abs();if(d.isZero())return this.abs();var m=this.clone(),x=d.clone();m.negative=0,x.negative=0;for(var M=0;m.isEven()&&x.isEven();M++)m.iushrn(1),x.iushrn(1);do{for(;m.isEven();)m.iushrn(1);for(;x.isEven();)x.iushrn(1);var E=m.cmp(x);if(E<0){var O=m;m=x,x=O}else if(E===0||x.cmpn(1)===0)break;m.isub(x)}while(!0);return x.iushln(M)},o.prototype.invm=function(d){return this.egcd(d).a.umod(d)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(d){return this.words[0]&d},o.prototype.bincn=function(d){i(typeof d=="number");var m=d%26,x=(d-m)/26,M=1<<m;if(this.length<=x)return this._expand(x+1),this.words[x]|=M,this;for(var E=M,O=x;E!==0&&O<this.length;O++){var C=this.words[O]|0;C+=E,E=C>>>26,C&=67108863,this.words[O]=C}return E!==0&&(this.words[O]=E,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(d){var m=d<0;if(this.negative!==0&&!m)return-1;if(this.negative===0&&m)return 1;this._strip();var x;if(this.length>1)x=1;else{m&&(d=-d),i(d<=67108863,"Number is too big");var M=this.words[0]|0;x=M===d?0:M<d?-1:1}return this.negative!==0?-x|0:x},o.prototype.cmp=function(d){if(this.negative!==0&&d.negative===0)return-1;if(this.negative===0&&d.negative!==0)return 1;var m=this.ucmp(d);return this.negative!==0?-m|0:m},o.prototype.ucmp=function(d){if(this.length>d.length)return 1;if(this.length<d.length)return-1;for(var m=0,x=this.length-1;x>=0;x--){var M=this.words[x]|0,E=d.words[x]|0;if(M!==E){M<E?m=-1:M>E&&(m=1);break}}return m},o.prototype.gtn=function(d){return this.cmpn(d)===1},o.prototype.gt=function(d){return this.cmp(d)===1},o.prototype.gten=function(d){return this.cmpn(d)>=0},o.prototype.gte=function(d){return this.cmp(d)>=0},o.prototype.ltn=function(d){return this.cmpn(d)===-1},o.prototype.lt=function(d){return this.cmp(d)===-1},o.prototype.lten=function(d){return this.cmpn(d)<=0},o.prototype.lte=function(d){return this.cmp(d)<=0},o.prototype.eqn=function(d){return this.cmpn(d)===0},o.prototype.eq=function(d){return this.cmp(d)===0},o.red=function(d){return new V(d)},o.prototype.toRed=function(d){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),d.convertTo(this)._forceRed(d)},o.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(d){return this.red=d,this},o.prototype.forceRed=function(d){return i(!this.red,"Already a number in reduction context"),this._forceRed(d)},o.prototype.redAdd=function(d){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,d)},o.prototype.redIAdd=function(d){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,d)},o.prototype.redSub=function(d){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,d)},o.prototype.redISub=function(d){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,d)},o.prototype.redShl=function(d){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,d)},o.prototype.redMul=function(d){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,d),this.red.mul(this,d)},o.prototype.redIMul=function(d){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,d),this.red.imul(this,d)},o.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(d){return i(this.red&&!d.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,d)};var G={k256:null,p224:null,p192:null,p25519:null};function q(p,d){this.name=p,this.p=new o(d,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}q.prototype._tmp=function(){var d=new o(null);return d.words=new Array(Math.ceil(this.n/13)),d},q.prototype.ireduce=function(d){var m=d,x;do this.split(m,this.tmp),m=this.imulK(m),m=m.iadd(this.tmp),x=m.bitLength();while(x>this.n);var M=x<this.n?-1:m.ucmp(this.p);return M===0?(m.words[0]=0,m.length=1):M>0?m.isub(this.p):m.strip!==void 0?m.strip():m._strip(),m},q.prototype.split=function(d,m){d.iushrn(this.n,0,m)},q.prototype.imulK=function(d){return d.imul(this.k)};function X(){q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}s(X,q),X.prototype.split=function(d,m){for(var x=4194303,M=Math.min(d.length,9),E=0;E<M;E++)m.words[E]=d.words[E];if(m.length=M,d.length<=9){d.words[0]=0,d.length=1;return}var O=d.words[9];for(m.words[m.length++]=O&x,E=10;E<d.length;E++){var C=d.words[E]|0;d.words[E-10]=(C&x)<<4|O>>>22,O=C}O>>>=22,d.words[E-10]=O,O===0&&d.length>10?d.length-=10:d.length-=9},X.prototype.imulK=function(d){d.words[d.length]=0,d.words[d.length+1]=0,d.length+=2;for(var m=0,x=0;x<d.length;x++){var M=d.words[x]|0;m+=M*977,d.words[x]=m&67108863,m=M*64+(m/67108864|0)}return d.words[d.length-1]===0&&(d.length--,d.words[d.length-1]===0&&d.length--),d};function ne(){q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}s(ne,q);function ae(){q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}s(ae,q);function ce(){q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}s(ce,q),ce.prototype.imulK=function(d){for(var m=0,x=0;x<d.length;x++){var M=(d.words[x]|0)*19+m,E=M&67108863;M>>>=26,d.words[x]=E,m=M}return m!==0&&(d.words[d.length++]=m),d},o._prime=function(d){if(G[d])return G[d];var m;if(d==="k256")m=new X;else if(d==="p224")m=new ne;else if(d==="p192")m=new ae;else if(d==="p25519")m=new ce;else throw new Error("Unknown prime "+d);return G[d]=m,m};function V(p){if(typeof p=="string"){var d=o._prime(p);this.m=d.p,this.prime=d}else i(p.gtn(1),"modulus must be greater than 1"),this.m=p,this.prime=null}V.prototype._verify1=function(d){i(d.negative===0,"red works only with positives"),i(d.red,"red works only with red numbers")},V.prototype._verify2=function(d,m){i((d.negative|m.negative)===0,"red works only with positives"),i(d.red&&d.red===m.red,"red works only with red numbers")},V.prototype.imod=function(d){return this.prime?this.prime.ireduce(d)._forceRed(this):(f(d,d.umod(this.m)._forceRed(this)),d)},V.prototype.neg=function(d){return d.isZero()?d.clone():this.m.sub(d)._forceRed(this)},V.prototype.add=function(d,m){this._verify2(d,m);var x=d.add(m);return x.cmp(this.m)>=0&&x.isub(this.m),x._forceRed(this)},V.prototype.iadd=function(d,m){this._verify2(d,m);var x=d.iadd(m);return x.cmp(this.m)>=0&&x.isub(this.m),x},V.prototype.sub=function(d,m){this._verify2(d,m);var x=d.sub(m);return x.cmpn(0)<0&&x.iadd(this.m),x._forceRed(this)},V.prototype.isub=function(d,m){this._verify2(d,m);var x=d.isub(m);return x.cmpn(0)<0&&x.iadd(this.m),x},V.prototype.shl=function(d,m){return this._verify1(d),this.imod(d.ushln(m))},V.prototype.imul=function(d,m){return this._verify2(d,m),this.imod(d.imul(m))},V.prototype.mul=function(d,m){return this._verify2(d,m),this.imod(d.mul(m))},V.prototype.isqr=function(d){return this.imul(d,d.clone())},V.prototype.sqr=function(d){return this.mul(d,d)},V.prototype.sqrt=function(d){if(d.isZero())return d.clone();var m=this.m.andln(3);if(i(m%2===1),m===3){var x=this.m.add(new o(1)).iushrn(2);return this.pow(d,x)}for(var M=this.m.subn(1),E=0;!M.isZero()&&M.andln(1)===0;)E++,M.iushrn(1);i(!M.isZero());var O=new o(1).toRed(this),C=O.redNeg(),g=this.m.subn(1).iushrn(1),v=this.m.bitLength();for(v=new o(2*v*v).toRed(this);this.pow(v,g).cmp(C)!==0;)v.redIAdd(C);for(var j=this.pow(v,M),ee=this.pow(d,M.addn(1).iushrn(1)),ie=this.pow(d,M),de=E;ie.cmp(O)!==0;){for(var ye=ie,Ee=0;ye.cmp(O)!==0;Ee++)ye=ye.redSqr();i(Ee<de);var Se=this.pow(j,new o(1).iushln(de-Ee-1));ee=ee.redMul(Se),j=Se.redSqr(),ie=ie.redMul(j),de=Ee}return ee},V.prototype.invm=function(d){var m=d._invmp(this.m);return m.negative!==0?(m.negative=0,this.imod(m).redNeg()):this.imod(m)},V.prototype.pow=function(d,m){if(m.isZero())return new o(1).toRed(this);if(m.cmpn(1)===0)return d.clone();var x=4,M=new Array(1<<x);M[0]=new o(1).toRed(this),M[1]=d;for(var E=2;E<M.length;E++)M[E]=this.mul(M[E-1],d);var O=M[0],C=0,g=0,v=m.bitLength()%26;for(v===0&&(v=26),E=m.length-1;E>=0;E--){for(var j=m.words[E],ee=v-1;ee>=0;ee--){var ie=j>>ee&1;if(O!==M[0]&&(O=this.sqr(O)),ie===0&&C===0){g=0;continue}C<<=1,C|=ie,g++,!(g!==x&&(E!==0||ee!==0))&&(O=this.mul(O,M[C]),g=0,C=0)}v=26}return O},V.prototype.convertTo=function(d){var m=d.umod(this.m);return m===d?m.clone():m},V.prototype.convertFrom=function(d){var m=d.clone();return m.red=null,m},o.mont=function(d){return new D(d)};function D(p){V.call(this,p),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}s(D,V),D.prototype.convertTo=function(d){return this.imod(d.ushln(this.shift))},D.prototype.convertFrom=function(d){var m=this.imod(d.mul(this.rinv));return m.red=null,m},D.prototype.imul=function(d,m){if(d.isZero()||m.isZero())return d.words[0]=0,d.length=1,d;var x=d.imul(m),M=x.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),E=x.isub(M).iushrn(this.shift),O=E;return E.cmp(this.m)>=0?O=E.isub(this.m):E.cmpn(0)<0&&(O=E.iadd(this.m)),O._forceRed(this)},D.prototype.mul=function(d,m){if(d.isZero()||m.isZero())return new o(0)._forceRed(this);var x=d.mul(m),M=x.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),E=x.isub(M).iushrn(this.shift),O=E;return E.cmp(this.m)>=0?O=E.isub(this.m):E.cmpn(0)<0&&(O=E.iadd(this.m)),O._forceRed(this)},D.prototype.invm=function(d){var m=this.imod(d._invmp(this.m).mul(this.r2));return m._forceRed(this)}})(typeof t>"u"||t,e)}}),Ao=9e15,ys=1e9,Qd="0123456789abcdef",Bu="2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058",Lu="3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989380952572010654858632789",eh={precision:20,rounding:4,modulo:1,toExpNeg:-7,toExpPos:21,minE:-Ao,maxE:Ao,crypto:!1},w4,Ti,ct=!0,Al="[DecimalError] ",us=Al+"Invalid argument: ",_4=Al+"Precision limit exceeded",x4=Al+"crypto unavailable",S4="[object Decimal]",Or=Math.floor,pr=Math.pow,M9=/^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i,A9=/^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i,T9=/^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i,E4=/^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,In=1e7,Qe=7,O9=9007199254740991,I9=Bu.length-1,th=Lu.length-1,be={toStringTag:S4};be.absoluteValue=be.abs=function(){var e=new this.constructor(this);return e.s<0&&(e.s=1),Xe(e)};be.ceil=function(){return Xe(new this.constructor(this),this.e+1,2)};be.clampedTo=be.clamp=function(e,t){var r,n=this,i=n.constructor;if(e=new i(e),t=new i(t),!e.s||!t.s)return new i(NaN);if(e.gt(t))throw Error(us+t);return r=n.cmp(e),r<0?e:n.cmp(t)>0?t:new i(n)};be.comparedTo=be.cmp=function(e){var t,r,n,i,s=this,o=s.d,a=(e=new s.constructor(e)).d,c=s.s,u=e.s;if(!o||!a)return!c||!u?NaN:c!==u?c:o===a?0:!o^c<0?1:-1;if(!o[0]||!a[0])return o[0]?c:a[0]?-u:0;if(c!==u)return c;if(s.e!==e.e)return s.e>e.e^c<0?1:-1;for(n=o.length,i=a.length,t=0,r=n<i?n:i;t<r;++t)if(o[t]!==a[t])return o[t]>a[t]^c<0?1:-1;return n===i?0:n>i^c<0?1:-1};be.cosine=be.cos=function(){var e,t,r=this,n=r.constructor;return r.d?r.d[0]?(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+Qe,n.rounding=1,r=P9(n,O4(n,r)),n.precision=e,n.rounding=t,Xe(Ti==2||Ti==3?r.neg():r,e,t,!0)):new n(1):new n(NaN)};be.cubeRoot=be.cbrt=function(){var e,t,r,n,i,s,o,a,c,u,l=this,f=l.constructor;if(!l.isFinite()||l.isZero())return new f(l);for(ct=!1,s=l.s*pr(l.s*l,1/3),!s||Math.abs(s)==1/0?(r=xr(l.d),e=l.e,(s=(e-r.length+1)%3)&&(r+=s==1||s==-2?"0":"00"),s=pr(r,1/3),e=Or((e+1)/3)-(e%3==(e<0?-1:2)),s==1/0?r="5e"+e:(r=s.toExponential(),r=r.slice(0,r.indexOf("e")+1)+e),n=new f(r),n.s=l.s):n=new f(s.toString()),o=(e=f.precision)+3;;)if(a=n,c=a.times(a).times(a),u=c.plus(l),n=Vt(u.plus(l).times(a),u.plus(c),o+2,1),xr(a.d).slice(0,o)===(r=xr(n.d)).slice(0,o))if(r=r.slice(o-3,o+1),r=="9999"||!i&&r=="4999"){if(!i&&(Xe(a,e+1,0),a.times(a).times(a).eq(l))){n=a;break}o+=4,i=1}else{(!+r||!+r.slice(1)&&r.charAt(0)=="5")&&(Xe(n,e+1,1),t=!n.times(n).times(n).eq(l));break}return ct=!0,Xe(n,e,f.rounding,t)};be.decimalPlaces=be.dp=function(){var e,t=this.d,r=NaN;if(t){if(e=t.length-1,r=(e-Or(this.e/Qe))*Qe,e=t[e],e)for(;e%10==0;e/=10)r--;r<0&&(r=0)}return r};be.dividedBy=be.div=function(e){return Vt(this,new this.constructor(e))};be.dividedToIntegerBy=be.divToInt=function(e){var t=this,r=t.constructor;return Xe(Vt(t,new r(e),0,1,1),r.precision,r.rounding)};be.equals=be.eq=function(e){return this.cmp(e)===0};be.floor=function(){return Xe(new this.constructor(this),this.e+1,3)};be.greaterThan=be.gt=function(e){return this.cmp(e)>0};be.greaterThanOrEqualTo=be.gte=function(e){var t=this.cmp(e);return t==1||t===0};be.hyperbolicCosine=be.cosh=function(){var e,t,r,n,i,s=this,o=s.constructor,a=new o(1);if(!s.isFinite())return new o(s.s?1/0:NaN);if(s.isZero())return a;r=o.precision,n=o.rounding,o.precision=r+Math.max(s.e,s.sd())+4,o.rounding=1,i=s.d.length,i<32?(e=Math.ceil(i/3),t=(1/Ol(4,e)).toString()):(e=16,t="2.3283064365386962890625e-10"),s=Lo(o,1,s.times(t),new o(1),!0);for(var c,u=e,l=new o(8);u--;)c=s.times(s),s=a.minus(c.times(l.minus(c.times(l))));return Xe(s,o.precision=r,o.rounding=n,!0)};be.hyperbolicSine=be.sinh=function(){var e,t,r,n,i=this,s=i.constructor;if(!i.isFinite()||i.isZero())return new s(i);if(t=s.precision,r=s.rounding,s.precision=t+Math.max(i.e,i.sd())+4,s.rounding=1,n=i.d.length,n<3)i=Lo(s,2,i,i,!0);else{e=1.4*Math.sqrt(n),e=e>16?16:e|0,i=i.times(1/Ol(5,e)),i=Lo(s,2,i,i,!0);for(var o,a=new s(5),c=new s(16),u=new s(20);e--;)o=i.times(i),i=i.times(a.plus(o.times(c.times(o).plus(u))))}return s.precision=t,s.rounding=r,Xe(i,t,r,!0)};be.hyperbolicTangent=be.tanh=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+7,n.rounding=1,Vt(r.sinh(),r.cosh(),n.precision=e,n.rounding=t)):new n(r.s)};be.inverseCosine=be.acos=function(){var e,t=this,r=t.constructor,n=t.abs().cmp(1),i=r.precision,s=r.rounding;return n!==-1?n===0?t.isNeg()?Mn(r,i,s):new r(0):new r(NaN):t.isZero()?Mn(r,i+4,s).times(.5):(r.precision=i+6,r.rounding=1,t=t.asin(),e=Mn(r,i+4,s).times(.5),r.precision=i,r.rounding=s,e.minus(t))};be.inverseHyperbolicCosine=be.acosh=function(){var e,t,r=this,n=r.constructor;return r.lte(1)?new n(r.eq(1)?0:NaN):r.isFinite()?(e=n.precision,t=n.rounding,n.precision=e+Math.max(Math.abs(r.e),r.sd())+4,n.rounding=1,ct=!1,r=r.times(r).minus(1).sqrt().plus(r),ct=!0,n.precision=e,n.rounding=t,r.ln()):new n(r)};be.inverseHyperbolicSine=be.asinh=function(){var e,t,r=this,n=r.constructor;return!r.isFinite()||r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+2*Math.max(Math.abs(r.e),r.sd())+6,n.rounding=1,ct=!1,r=r.times(r).plus(1).sqrt().plus(r),ct=!0,n.precision=e,n.rounding=t,r.ln())};be.inverseHyperbolicTangent=be.atanh=function(){var e,t,r,n,i=this,s=i.constructor;return i.isFinite()?i.e>=0?new s(i.abs().eq(1)?i.s/0:i.isZero()?i:NaN):(e=s.precision,t=s.rounding,n=i.sd(),Math.max(n,e)<2*-i.e-1?Xe(new s(i),e,t,!0):(s.precision=r=n-i.e,i=Vt(i.plus(1),new s(1).minus(i),r+e,1),s.precision=e+4,s.rounding=1,i=i.ln(),s.precision=e,s.rounding=t,i.times(.5))):new s(NaN)};be.inverseSine=be.asin=function(){var e,t,r,n,i=this,s=i.constructor;return i.isZero()?new s(i):(t=i.abs().cmp(1),r=s.precision,n=s.rounding,t!==-1?t===0?(e=Mn(s,r+4,n).times(.5),e.s=i.s,e):new s(NaN):(s.precision=r+6,s.rounding=1,i=i.div(new s(1).minus(i.times(i)).sqrt().plus(1)).atan(),s.precision=r,s.rounding=n,i.times(2)))};be.inverseTangent=be.atan=function(){var e,t,r,n,i,s,o,a,c,u=this,l=u.constructor,f=l.precision,h=l.rounding;if(u.isFinite()){if(u.isZero())return new l(u);if(u.abs().eq(1)&&f+4<=th)return o=Mn(l,f+4,h).times(.25),o.s=u.s,o}else{if(!u.s)return new l(NaN);if(f+4<=th)return o=Mn(l,f+4,h).times(.5),o.s=u.s,o}for(l.precision=a=f+10,l.rounding=1,r=Math.min(28,a/Qe+2|0),e=r;e;--e)u=u.div(u.times(u).plus(1).sqrt().plus(1));for(ct=!1,t=Math.ceil(a/Qe),n=1,c=u.times(u),o=new l(u),i=u;e!==-1;)if(i=i.times(c),s=o.minus(i.div(n+=2)),i=i.times(c),o=s.plus(i.div(n+=2)),o.d[t]!==void 0)for(e=t;o.d[e]===s.d[e]&&e--;);return r&&(o=o.times(2<<r-1)),ct=!0,Xe(o,l.precision=f,l.rounding=h,!0)};be.isFinite=function(){return!!this.d};be.isInteger=be.isInt=function(){return!!this.d&&Or(this.e/Qe)>this.d.length-2};be.isNaN=function(){return!this.s};be.isNegative=be.isNeg=function(){return this.s<0};be.isPositive=be.isPos=function(){return this.s>0};be.isZero=function(){return!!this.d&&this.d[0]===0};be.lessThan=be.lt=function(e){return this.cmp(e)<0};be.lessThanOrEqualTo=be.lte=function(e){return this.cmp(e)<1};be.logarithm=be.log=function(e){var t,r,n,i,s,o,a,c,u=this,l=u.constructor,f=l.precision,h=l.rounding,y=5;if(e==null)e=new l(10),t=!0;else{if(e=new l(e),r=e.d,e.s<0||!r||!r[0]||e.eq(1))return new l(NaN);t=e.eq(10)}if(r=u.d,u.s<0||!r||!r[0]||u.eq(1))return new l(r&&!r[0]?-1/0:u.s!=1?NaN:r?0:1/0);if(t)if(r.length>1)s=!0;else{for(i=r[0];i%10===0;)i/=10;s=i!==1}if(ct=!1,a=f+y,o=ts(u,a),n=t?Fu(l,a+10):ts(e,a),c=Vt(o,n,a,1),nc(c.d,i=f,h))do if(a+=10,o=ts(u,a),n=t?Fu(l,a+10):ts(e,a),c=Vt(o,n,a,1),!s){+xr(c.d).slice(i+1,i+15)+1==1e14&&(c=Xe(c,f+1,0));break}while(nc(c.d,i+=10,h));return ct=!0,Xe(c,f,h)};be.minus=be.sub=function(e){var t,r,n,i,s,o,a,c,u,l,f,h,y=this,b=y.constructor;if(e=new b(e),!y.d||!e.d)return!y.s||!e.s?e=new b(NaN):y.d?e.s=-e.s:e=new b(e.d||y.s!==e.s?y:NaN),e;if(y.s!=e.s)return e.s=-e.s,y.plus(e);if(u=y.d,h=e.d,a=b.precision,c=b.rounding,!u[0]||!h[0]){if(h[0])e.s=-e.s;else if(u[0])e=new b(y);else return new b(c===3?-0:0);return ct?Xe(e,a,c):e}if(r=Or(e.e/Qe),l=Or(y.e/Qe),u=u.slice(),s=l-r,s){for(f=s<0,f?(t=u,s=-s,o=h.length):(t=h,r=l,o=u.length),n=Math.max(Math.ceil(a/Qe),o)+2,s>n&&(s=n,t.length=1),t.reverse(),n=s;n--;)t.push(0);t.reverse()}else{for(n=u.length,o=h.length,f=n<o,f&&(o=n),n=0;n<o;n++)if(u[n]!=h[n]){f=u[n]<h[n];break}s=0}for(f&&(t=u,u=h,h=t,e.s=-e.s),o=u.length,n=h.length-o;n>0;--n)u[o++]=0;for(n=h.length;n>s;){if(u[--n]<h[n]){for(i=n;i&&u[--i]===0;)u[i]=In-1;--u[i],u[n]+=In}u[n]-=h[n]}for(;u[--o]===0;)u.pop();for(;u[0]===0;u.shift())--r;return u[0]?(e.d=u,e.e=Tl(u,r),ct?Xe(e,a,c):e):new b(c===3?-0:0)};be.modulo=be.mod=function(e){var t,r=this,n=r.constructor;return e=new n(e),!r.d||!e.s||e.d&&!e.d[0]?new n(NaN):!e.d||r.d&&!r.d[0]?Xe(new n(r),n.precision,n.rounding):(ct=!1,n.modulo==9?(t=Vt(r,e.abs(),0,3,1),t.s*=e.s):t=Vt(r,e,0,n.modulo,1),t=t.times(e),ct=!0,r.minus(t))};be.naturalExponential=be.exp=function(){return rh(this)};be.naturalLogarithm=be.ln=function(){return ts(this)};be.negated=be.neg=function(){var e=new this.constructor(this);return e.s=-e.s,Xe(e)};be.plus=be.add=function(e){var t,r,n,i,s,o,a,c,u,l,f=this,h=f.constructor;if(e=new h(e),!f.d||!e.d)return!f.s||!e.s?e=new h(NaN):f.d||(e=new h(e.d||f.s===e.s?f:NaN)),e;if(f.s!=e.s)return e.s=-e.s,f.minus(e);if(u=f.d,l=e.d,a=h.precision,c=h.rounding,!u[0]||!l[0])return l[0]||(e=new h(f)),ct?Xe(e,a,c):e;if(s=Or(f.e/Qe),n=Or(e.e/Qe),u=u.slice(),i=s-n,i){for(i<0?(r=u,i=-i,o=l.length):(r=l,n=s,o=u.length),s=Math.ceil(a/Qe),o=s>o?s+1:o+1,i>o&&(i=o,r.length=1),r.reverse();i--;)r.push(0);r.reverse()}for(o=u.length,i=l.length,o-i<0&&(i=o,r=l,l=u,u=r),t=0;i;)t=(u[--i]=u[i]+l[i]+t)/In|0,u[i]%=In;for(t&&(u.unshift(t),++n),o=u.length;u[--o]==0;)u.pop();return e.d=u,e.e=Tl(u,n),ct?Xe(e,a,c):e};be.precision=be.sd=function(e){var t,r=this;if(e!==void 0&&e!==!!e&&e!==1&&e!==0)throw Error(us+e);return r.d?(t=C4(r.d),e&&r.e+1>t&&(t=r.e+1)):t=NaN,t};be.round=function(){var e=this,t=e.constructor;return Xe(new t(e),e.e+1,t.rounding)};be.sine=be.sin=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+Math.max(r.e,r.sd())+Qe,n.rounding=1,r=k9(n,O4(n,r)),n.precision=e,n.rounding=t,Xe(Ti>2?r.neg():r,e,t,!0)):new n(NaN)};be.squareRoot=be.sqrt=function(){var e,t,r,n,i,s,o=this,a=o.d,c=o.e,u=o.s,l=o.constructor;if(u!==1||!a||!a[0])return new l(!u||u<0&&(!a||a[0])?NaN:a?o:1/0);for(ct=!1,u=Math.sqrt(+o),u==0||u==1/0?(t=xr(a),(t.length+c)%2==0&&(t+="0"),u=Math.sqrt(t),c=Or((c+1)/2)-(c<0||c%2),u==1/0?t="5e"+c:(t=u.toExponential(),t=t.slice(0,t.indexOf("e")+1)+c),n=new l(t)):n=new l(u.toString()),r=(c=l.precision)+3;;)if(s=n,n=s.plus(Vt(o,s,r+2,1)).times(.5),xr(s.d).slice(0,r)===(t=xr(n.d)).slice(0,r))if(t=t.slice(r-3,r+1),t=="9999"||!i&&t=="4999"){if(!i&&(Xe(s,c+1,0),s.times(s).eq(o))){n=s;break}r+=4,i=1}else{(!+t||!+t.slice(1)&&t.charAt(0)=="5")&&(Xe(n,c+1,1),e=!n.times(n).eq(o));break}return ct=!0,Xe(n,c,l.rounding,e)};be.tangent=be.tan=function(){var e,t,r=this,n=r.constructor;return r.isFinite()?r.isZero()?new n(r):(e=n.precision,t=n.rounding,n.precision=e+10,n.rounding=1,r=r.sin(),r.s=1,r=Vt(r,new n(1).minus(r.times(r)).sqrt(),e+10,0),n.precision=e,n.rounding=t,Xe(Ti==2||Ti==4?r.neg():r,e,t,!0)):new n(NaN)};be.times=be.mul=function(e){var t,r,n,i,s,o,a,c,u,l=this,f=l.constructor,h=l.d,y=(e=new f(e)).d;if(e.s*=l.s,!h||!h[0]||!y||!y[0])return new f(!e.s||h&&!h[0]&&!y||y&&!y[0]&&!h?NaN:!h||!y?e.s/0:e.s*0);for(r=Or(l.e/Qe)+Or(e.e/Qe),c=h.length,u=y.length,c<u&&(s=h,h=y,y=s,o=c,c=u,u=o),s=[],o=c+u,n=o;n--;)s.push(0);for(n=u;--n>=0;){for(t=0,i=c+n;i>n;)a=s[i]+y[n]*h[i-n-1]+t,s[i--]=a%In|0,t=a/In|0;s[i]=(s[i]+t)%In|0}for(;!s[--o];)s.pop();return t?++r:s.shift(),e.d=s,e.e=Tl(s,r),ct?Xe(e,f.precision,f.rounding):e};be.toBinary=function(e,t){return s0(this,2,e,t)};be.toDecimalPlaces=be.toDP=function(e,t){var r=this,n=r.constructor;return r=new n(r),e===void 0?r:(qr(e,0,ys),t===void 0?t=n.rounding:qr(t,0,8),Xe(r,e+r.e+1,t))};be.toExponential=function(e,t){var r,n=this,i=n.constructor;return e===void 0?r=ri(n,!0):(qr(e,0,ys),t===void 0?t=i.rounding:qr(t,0,8),n=Xe(new i(n),e+1,t),r=ri(n,!0,e+1)),n.isNeg()&&!n.isZero()?"-"+r:r};be.toFixed=function(e,t){var r,n,i=this,s=i.constructor;return e===void 0?r=ri(i):(qr(e,0,ys),t===void 0?t=s.rounding:qr(t,0,8),n=Xe(new s(i),e+i.e+1,t),r=ri(n,!1,e+n.e+1)),i.isNeg()&&!i.isZero()?"-"+r:r};be.toFraction=function(e){var t,r,n,i,s,o,a,c,u,l,f,h,y=this,b=y.d,w=y.constructor;if(!b)return new w(y);if(u=r=new w(1),n=c=new w(0),t=new w(n),s=t.e=C4(b)-y.e-1,o=s%Qe,t.d[0]=pr(10,o<0?Qe+o:o),e==null)e=s>0?t:u;else{if(a=new w(e),!a.isInt()||a.lt(u))throw Error(us+a);e=a.gt(t)?s>0?t:u:a}for(ct=!1,a=new w(xr(b)),l=w.precision,w.precision=s=b.length*Qe*2;f=Vt(a,t,0,1,1),i=r.plus(f.times(n)),i.cmp(e)!=1;)r=n,n=i,i=u,u=c.plus(f.times(i)),c=i,i=t,t=a.minus(f.times(i)),a=i;return i=Vt(e.minus(r),n,0,1,1),c=c.plus(i.times(u)),r=r.plus(i.times(n)),c.s=u.s=y.s,h=Vt(u,n,s,1).minus(y).abs().cmp(Vt(c,r,s,1).minus(y).abs())<1?[u,n]:[c,r],w.precision=l,ct=!0,h};be.toHexadecimal=be.toHex=function(e,t){return s0(this,16,e,t)};be.toNearest=function(e,t){var r=this,n=r.constructor;if(r=new n(r),e==null){if(!r.d)return r;e=new n(1),t=n.rounding}else{if(e=new n(e),t===void 0?t=n.rounding:qr(t,0,8),!r.d)return e.s?r:e;if(!e.d)return e.s&&(e.s=r.s),e}return e.d[0]?(ct=!1,r=Vt(r,e,0,t,1).times(e),ct=!0,Xe(r)):(e.s=r.s,r=e),r};be.toNumber=function(){return+this};be.toOctal=function(e,t){return s0(this,8,e,t)};be.toPower=be.pow=function(e){var t,r,n,i,s,o,a=this,c=a.constructor,u=+(e=new c(e));if(!a.d||!e.d||!a.d[0]||!e.d[0])return new c(pr(+a,u));if(a=new c(a),a.eq(1))return a;if(n=c.precision,s=c.rounding,e.eq(1))return Xe(a,n,s);if(t=Or(e.e/Qe),t>=e.d.length-1&&(r=u<0?-u:u)<=O9)return i=M4(c,a,r,n),e.s<0?new c(1).div(i):Xe(i,n,s);if(o=a.s,o<0){if(t<e.d.length-1)return new c(NaN);if(e.d[t]&1||(o=1),a.e==0&&a.d[0]==1&&a.d.length==1)return a.s=o,a}return r=pr(+a,u),t=r==0||!isFinite(r)?Or(u*(Math.log("0."+xr(a.d))/Math.LN10+a.e+1)):new c(r+"").e,t>c.maxE+1||t<c.minE-1?new c(t>0?o/0:0):(ct=!1,c.rounding=a.s=1,r=Math.min(12,(t+"").length),i=rh(e.times(ts(a,n+r)),n),i.d&&(i=Xe(i,n+5,1),nc(i.d,n,s)&&(t=n+10,i=Xe(rh(e.times(ts(a,t+r)),t),t+5,1),+xr(i.d).slice(n+1,n+15)+1==1e14&&(i=Xe(i,n+1,0)))),i.s=o,ct=!0,c.rounding=s,Xe(i,n,s))};be.toPrecision=function(e,t){var r,n=this,i=n.constructor;return e===void 0?r=ri(n,n.e<=i.toExpNeg||n.e>=i.toExpPos):(qr(e,1,ys),t===void 0?t=i.rounding:qr(t,0,8),n=Xe(new i(n),e,t),r=ri(n,e<=n.e||n.e<=i.toExpNeg,e)),n.isNeg()&&!n.isZero()?"-"+r:r};be.toSignificantDigits=be.toSD=function(e,t){var r=this,n=r.constructor;return e===void 0?(e=n.precision,t=n.rounding):(qr(e,1,ys),t===void 0?t=n.rounding:qr(t,0,8)),Xe(new n(r),e,t)};be.toString=function(){var e=this,t=e.constructor,r=ri(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()&&!e.isZero()?"-"+r:r};be.truncated=be.trunc=function(){return Xe(new this.constructor(this),this.e+1,1)};be.valueOf=be.toJSON=function(){var e=this,t=e.constructor,r=ri(e,e.e<=t.toExpNeg||e.e>=t.toExpPos);return e.isNeg()?"-"+r:r};function xr(e){var t,r,n,i=e.length-1,s="",o=e[0];if(i>0){for(s+=o,t=1;t<i;t++)n=e[t]+"",r=Qe-n.length,r&&(s+=Zi(r)),s+=n;o=e[t],n=o+"",r=Qe-n.length,r&&(s+=Zi(r))}else if(o===0)return"0";for(;o%10===0;)o/=10;return s+o}function qr(e,t,r){if(e!==~~e||e<t||e>r)throw Error(us+e)}function nc(e,t,r,n){var i,s,o,a;for(s=e[0];s>=10;s/=10)--t;return--t<0?(t+=Qe,i=0):(i=Math.ceil((t+1)/Qe),t%=Qe),s=pr(10,Qe-t),a=e[i]%s|0,n==null?t<3?(t==0?a=a/100|0:t==1&&(a=a/10|0),o=r<4&&a==99999||r>3&&a==49999||a==5e4||a==0):o=(r<4&&a+1==s||r>3&&a+1==s/2)&&(e[i+1]/s/100|0)==pr(10,t-2)-1||(a==s/2||a==0)&&(e[i+1]/s/100|0)==0:t<4?(t==0?a=a/1e3|0:t==1?a=a/100|0:t==2&&(a=a/10|0),o=(n||r<4)&&a==9999||!n&&r>3&&a==4999):o=((n||r<4)&&a+1==s||!n&&r>3&&a+1==s/2)&&(e[i+1]/s/1e3|0)==pr(10,t-3)-1,o}function lu(e,t,r){for(var n,i=[0],s,o=0,a=e.length;o<a;){for(s=i.length;s--;)i[s]*=t;for(i[0]+=Qd.indexOf(e.charAt(o++)),n=0;n<i.length;n++)i[n]>r-1&&(i[n+1]===void 0&&(i[n+1]=0),i[n+1]+=i[n]/r|0,i[n]%=r)}return i.reverse()}function P9(e,t){var r,n,i;if(t.isZero())return t;n=t.d.length,n<32?(r=Math.ceil(n/3),i=(1/Ol(4,r)).toString()):(r=16,i="2.3283064365386962890625e-10"),e.precision+=r,t=Lo(e,1,t.times(i),new e(1));for(var s=r;s--;){var o=t.times(t);t=o.times(o).minus(o).times(8).plus(1)}return e.precision-=r,t}var Vt=function(){function e(n,i,s){var o,a=0,c=n.length;for(n=n.slice();c--;)o=n[c]*i+a,n[c]=o%s|0,a=o/s|0;return a&&n.unshift(a),n}function t(n,i,s,o){var a,c;if(s!=o)c=s>o?1:-1;else for(a=c=0;a<s;a++)if(n[a]!=i[a]){c=n[a]>i[a]?1:-1;break}return c}function r(n,i,s,o){for(var a=0;s--;)n[s]-=a,a=n[s]<i[s]?1:0,n[s]=a*o+n[s]-i[s];for(;!n[0]&&n.length>1;)n.shift()}return function(n,i,s,o,a,c){var u,l,f,h,y,b,w,T,P,k,N,F,L,G,q,X,ne,ae,ce,V,D=n.constructor,p=n.s==i.s?1:-1,d=n.d,m=i.d;if(!d||!d[0]||!m||!m[0])return new D(!n.s||!i.s||(d?m&&d[0]==m[0]:!m)?NaN:d&&d[0]==0||!m?p*0:p/0);for(c?(y=1,l=n.e-i.e):(c=In,y=Qe,l=Or(n.e/y)-Or(i.e/y)),ce=m.length,ne=d.length,P=new D(p),k=P.d=[],f=0;m[f]==(d[f]||0);f++);if(m[f]>(d[f]||0)&&l--,s==null?(G=s=D.precision,o=D.rounding):a?G=s+(n.e-i.e)+1:G=s,G<0)k.push(1),b=!0;else{if(G=G/y+2|0,f=0,ce==1){for(h=0,m=m[0],G++;(f<ne||h)&&G--;f++)q=h*c+(d[f]||0),k[f]=q/m|0,h=q%m|0;b=h||f<ne}else{for(h=c/(m[0]+1)|0,h>1&&(m=e(m,h,c),d=e(d,h,c),ce=m.length,ne=d.length),X=ce,N=d.slice(0,ce),F=N.length;F<ce;)N[F++]=0;V=m.slice(),V.unshift(0),ae=m[0],m[1]>=c/2&&++ae;do h=0,u=t(m,N,ce,F),u<0?(L=N[0],ce!=F&&(L=L*c+(N[1]||0)),h=L/ae|0,h>1?(h>=c&&(h=c-1),w=e(m,h,c),T=w.length,F=N.length,u=t(w,N,T,F),u==1&&(h--,r(w,ce<T?V:m,T,c))):(h==0&&(u=h=1),w=m.slice()),T=w.length,T<F&&w.unshift(0),r(N,w,F,c),u==-1&&(F=N.length,u=t(m,N,ce,F),u<1&&(h++,r(N,ce<F?V:m,F,c))),F=N.length):u===0&&(h++,N=[0]),k[f++]=h,u&&N[0]?N[F++]=d[X]||0:(N=[d[X]],F=1);while((X++<ne||N[0]!==void 0)&&G--);b=N[0]!==void 0}k[0]||k.shift()}if(y==1)P.e=l,w4=b;else{for(f=1,h=k[0];h>=10;h/=10)f++;P.e=f+l*y-1,Xe(P,a?s+P.e+1:s,o,b)}return P}}();function Xe(e,t,r,n){var i,s,o,a,c,u,l,f,h,y=e.constructor;e:if(t!=null){if(f=e.d,!f)return e;for(i=1,a=f[0];a>=10;a/=10)i++;if(s=t-i,s<0)s+=Qe,o=t,l=f[h=0],c=l/pr(10,i-o-1)%10|0;else if(h=Math.ceil((s+1)/Qe),a=f.length,h>=a)if(n){for(;a++<=h;)f.push(0);l=c=0,i=1,s%=Qe,o=s-Qe+1}else break e;else{for(l=a=f[h],i=1;a>=10;a/=10)i++;s%=Qe,o=s-Qe+i,c=o<0?0:l/pr(10,i-o-1)%10|0}if(n=n||t<0||f[h+1]!==void 0||(o<0?l:l%pr(10,i-o-1)),u=r<4?(c||n)&&(r==0||r==(e.s<0?3:2)):c>5||c==5&&(r==4||n||r==6&&(s>0?o>0?l/pr(10,i-o):0:f[h-1])%10&1||r==(e.s<0?8:7)),t<1||!f[0])return f.length=0,u?(t-=e.e+1,f[0]=pr(10,(Qe-t%Qe)%Qe),e.e=-t||0):f[0]=e.e=0,e;if(s==0?(f.length=h,a=1,h--):(f.length=h+1,a=pr(10,Qe-s),f[h]=o>0?(l/pr(10,i-o)%pr(10,o)|0)*a:0),u)for(;;)if(h==0){for(s=1,o=f[0];o>=10;o/=10)s++;for(o=f[0]+=a,a=1;o>=10;o/=10)a++;s!=a&&(e.e++,f[0]==In&&(f[0]=1));break}else{if(f[h]+=a,f[h]!=In)break;f[h--]=0,a=1}for(s=f.length;f[--s]===0;)f.pop()}return ct&&(e.e>y.maxE?(e.d=null,e.e=NaN):e.e<y.minE&&(e.e=0,e.d=[0])),e}function ri(e,t,r){if(!e.isFinite())return T4(e);var n,i=e.e,s=xr(e.d),o=s.length;return t?(r&&(n=r-o)>0?s=s.charAt(0)+"."+s.slice(1)+Zi(n):o>1&&(s=s.charAt(0)+"."+s.slice(1)),s=s+(e.e<0?"e":"e+")+e.e):i<0?(s="0."+Zi(-i-1)+s,r&&(n=r-o)>0&&(s+=Zi(n))):i>=o?(s+=Zi(i+1-o),r&&(n=r-i-1)>0&&(s=s+"."+Zi(n))):((n=i+1)<o&&(s=s.slice(0,n)+"."+s.slice(n)),r&&(n=r-o)>0&&(i+1===o&&(s+="."),s+=Zi(n))),s}function Tl(e,t){var r=e[0];for(t*=Qe;r>=10;r/=10)t++;return t}function Fu(e,t,r){if(t>I9)throw ct=!0,r&&(e.precision=r),Error(_4);return Xe(new e(Bu),t,1,!0)}function Mn(e,t,r){if(t>th)throw Error(_4);return Xe(new e(Lu),t,r,!0)}function C4(e){var t=e.length-1,r=t*Qe+1;if(t=e[t],t){for(;t%10==0;t/=10)r--;for(t=e[0];t>=10;t/=10)r++}return r}function Zi(e){for(var t="";e--;)t+="0";return t}function M4(e,t,r,n){var i,s=new e(1),o=Math.ceil(n/Qe+4);for(ct=!1;;){if(r%2&&(s=s.times(t),gg(s.d,o)&&(i=!0)),r=Or(r/2),r===0){r=s.d.length-1,i&&s.d[r]===0&&++s.d[r];break}t=t.times(t),gg(t.d,o)}return ct=!0,s}function mg(e){return e.d[e.d.length-1]&1}function A4(e,t,r){for(var n,i=new e(t[0]),s=0;++s<t.length;)if(n=new e(t[s]),n.s)i[r](n)&&(i=n);else{i=n;break}return i}function rh(e,t){var r,n,i,s,o,a,c,u=0,l=0,f=0,h=e.constructor,y=h.rounding,b=h.precision;if(!e.d||!e.d[0]||e.e>17)return new h(e.d?e.d[0]?e.s<0?0:1/0:1:e.s?e.s<0?0:e:0/0);for(t==null?(ct=!1,c=b):c=t,a=new h(.03125);e.e>-2;)e=e.times(a),f+=5;for(n=Math.log(pr(2,f))/Math.LN10*2+5|0,c+=n,r=s=o=new h(1),h.precision=c;;){if(s=Xe(s.times(e),c,1),r=r.times(++l),a=o.plus(Vt(s,r,c,1)),xr(a.d).slice(0,c)===xr(o.d).slice(0,c)){for(i=f;i--;)o=Xe(o.times(o),c,1);if(t==null)if(u<3&&nc(o.d,c-n,y,u))h.precision=c+=10,r=s=a=new h(1),l=0,u++;else return Xe(o,h.precision=b,y,ct=!0);else return h.precision=b,o}o=a}}function ts(e,t){var r,n,i,s,o,a,c,u,l,f,h,y=1,b=10,w=e,T=w.d,P=w.constructor,k=P.rounding,N=P.precision;if(w.s<0||!T||!T[0]||!w.e&&T[0]==1&&T.length==1)return new P(T&&!T[0]?-1/0:w.s!=1?NaN:T?0:w);if(t==null?(ct=!1,l=N):l=t,P.precision=l+=b,r=xr(T),n=r.charAt(0),Math.abs(s=w.e)<15e14){for(;n<7&&n!=1||n==1&&r.charAt(1)>3;)w=w.times(e),r=xr(w.d),n=r.charAt(0),y++;s=w.e,n>1?(w=new P("0."+r),s++):w=new P(n+"."+r.slice(1))}else return u=Fu(P,l+2,N).times(s+""),w=ts(new P(n+"."+r.slice(1)),l-b).plus(u),P.precision=N,t==null?Xe(w,N,k,ct=!0):w;for(f=w,c=o=w=Vt(w.minus(1),w.plus(1),l,1),h=Xe(w.times(w),l,1),i=3;;){if(o=Xe(o.times(h),l,1),u=c.plus(Vt(o,new P(i),l,1)),xr(u.d).slice(0,l)===xr(c.d).slice(0,l))if(c=c.times(2),s!==0&&(c=c.plus(Fu(P,l+2,N).times(s+""))),c=Vt(c,new P(y),l,1),t==null)if(nc(c.d,l-b,k,a))P.precision=l+=b,u=o=w=Vt(f.minus(1),f.plus(1),l,1),h=Xe(w.times(w),l,1),i=a=1;else return Xe(c,P.precision=N,k,ct=!0);else return P.precision=N,c;c=u,i+=2}}function T4(e){return String(e.s*e.s/0)}function nh(e,t){var r,n,i;for((r=t.indexOf("."))>-1&&(t=t.replace(".","")),(n=t.search(/e/i))>0?(r<0&&(r=n),r+=+t.slice(n+1),t=t.substring(0,n)):r<0&&(r=t.length),n=0;t.charCodeAt(n)===48;n++);for(i=t.length;t.charCodeAt(i-1)===48;--i);if(t=t.slice(n,i),t){if(i-=n,e.e=r=r-n-1,e.d=[],n=(r+1)%Qe,r<0&&(n+=Qe),n<i){for(n&&e.d.push(+t.slice(0,n)),i-=Qe;n<i;)e.d.push(+t.slice(n,n+=Qe));t=t.slice(n),n=Qe-t.length}else n-=i;for(;n--;)t+="0";e.d.push(+t),ct&&(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 j9(e,t){var r,n,i,s,o,a,c,u,l;if(t.indexOf("_")>-1){if(t=t.replace(/(\d)_(?=\d)/g,"$1"),E4.test(t))return nh(e,t)}else if(t==="Infinity"||t==="NaN")return+t||(e.s=NaN),e.e=NaN,e.d=null,e;if(A9.test(t))r=16,t=t.toLowerCase();else if(M9.test(t))r=2;else if(T9.test(t))r=8;else throw Error(us+t);for(s=t.search(/p/i),s>0?(c=+t.slice(s+1),t=t.substring(2,s)):t=t.slice(2),s=t.indexOf("."),o=s>=0,n=e.constructor,o&&(t=t.replace(".",""),a=t.length,s=a-s,i=M4(n,new n(r),s,s*2)),u=lu(t,r,In),l=u.length-1,s=l;u[s]===0;--s)u.pop();return s<0?new n(e.s*0):(e.e=Tl(u,l),e.d=u,ct=!1,o&&(e=Vt(e,i,a*4)),c&&(e=e.times(Math.abs(c)<54?pr(2,c):Sc.pow(2,c))),ct=!0,e)}function k9(e,t){var r,n=t.d.length;if(n<3)return t.isZero()?t:Lo(e,2,t,t);r=1.4*Math.sqrt(n),r=r>16?16:r|0,t=t.times(1/Ol(5,r)),t=Lo(e,2,t,t);for(var i,s=new e(5),o=new e(16),a=new e(20);r--;)i=t.times(t),t=t.times(s.plus(i.times(o.times(i).minus(a))));return t}function Lo(e,t,r,n,i){var s,o,a,c,u=e.precision,l=Math.ceil(u/Qe);for(ct=!1,c=r.times(r),a=new e(n);;){if(o=Vt(a.times(c),new e(t++*t++),u,1),a=i?n.plus(o):n.minus(o),n=Vt(o.times(c),new e(t++*t++),u,1),o=a.plus(n),o.d[l]!==void 0){for(s=l;o.d[s]===a.d[s]&&s--;);if(s==-1)break}s=a,a=n,n=o,o=s}return ct=!0,o.d.length=l+1,o}function Ol(e,t){for(var r=e;--t;)r*=e;return r}function O4(e,t){var r,n=t.s<0,i=Mn(e,e.precision,1),s=i.times(.5);if(t=t.abs(),t.lte(s))return Ti=n?4:1,t;if(r=t.divToInt(i),r.isZero())Ti=n?3:2;else{if(t=t.minus(r.times(i)),t.lte(s))return Ti=mg(r)?n?2:3:n?4:1,t;Ti=mg(r)?n?1:4:n?3:2}return t.minus(i).abs()}function s0(e,t,r,n){var i,s,o,a,c,u,l,f,h,y=e.constructor,b=r!==void 0;if(b?(qr(r,1,ys),n===void 0?n=y.rounding:qr(n,0,8)):(r=y.precision,n=y.rounding),!e.isFinite())l=T4(e);else{for(l=ri(e),o=l.indexOf("."),b?(i=2,t==16?r=r*4-3:t==8&&(r=r*3-2)):i=t,o>=0&&(l=l.replace(".",""),h=new y(1),h.e=l.length-o,h.d=lu(ri(h),10,i),h.e=h.d.length),f=lu(l,10,i),s=c=f.length;f[--c]==0;)f.pop();if(!f[0])l=b?"0p+0":"0";else{if(o<0?s--:(e=new y(e),e.d=f,e.e=s,e=Vt(e,h,r,n,0,i),f=e.d,s=e.e,u=w4),o=f[r],a=i/2,u=u||f[r+1]!==void 0,u=n<4?(o!==void 0||u)&&(n===0||n===(e.s<0?3:2)):o>a||o===a&&(n===4||u||n===6&&f[r-1]&1||n===(e.s<0?8:7)),f.length=r,u)for(;++f[--r]>i-1;)f[r]=0,r||(++s,f.unshift(1));for(c=f.length;!f[c-1];--c);for(o=0,l="";o<c;o++)l+=Qd.charAt(f[o]);if(b){if(c>1)if(t==16||t==8){for(o=t==16?4:3,--c;c%o;c++)l+="0";for(f=lu(l,i,t),c=f.length;!f[c-1];--c);for(o=1,l="1.";o<c;o++)l+=Qd.charAt(f[o])}else l=l.charAt(0)+"."+l.slice(1);l=l+(s<0?"p":"p+")+s}else if(s<0){for(;++s;)l="0"+l;l="0."+l}else if(++s>c)for(s-=c;s--;)l+="0";else s<c&&(l=l.slice(0,s)+"."+l.slice(s))}l=(t==16?"0x":t==2?"0b":t==8?"0o":"")+l}return e.s<0?"-"+l:l}function gg(e,t){if(e.length>t)return e.length=t,!0}function R9(e){return new this(e).abs()}function N9(e){return new this(e).acos()}function D9(e){return new this(e).acosh()}function $9(e,t){return new this(e).plus(t)}function B9(e){return new this(e).asin()}function L9(e){return new this(e).asinh()}function F9(e){return new this(e).atan()}function U9(e){return new this(e).atanh()}function z9(e,t){e=new this(e),t=new this(t);var r,n=this.precision,i=this.rounding,s=n+4;return!e.s||!t.s?r=new this(NaN):!e.d&&!t.d?(r=Mn(this,s,1).times(t.s>0?.25:.75),r.s=e.s):!t.d||e.isZero()?(r=t.s<0?Mn(this,n,i):new this(0),r.s=e.s):!e.d||t.isZero()?(r=Mn(this,s,1).times(.5),r.s=e.s):t.s<0?(this.precision=s,this.rounding=1,r=this.atan(Vt(e,t,s,1)),t=Mn(this,s,1),this.precision=n,this.rounding=i,r=e.s<0?r.minus(t):r.plus(t)):r=this.atan(Vt(e,t,s,1)),r}function V9(e){return new this(e).cbrt()}function q9(e){return Xe(e=new this(e),e.e+1,2)}function W9(e,t,r){return new this(e).clamp(t,r)}function G9(e){if(!e||typeof e!="object")throw Error(Al+"Object expected");var t,r,n,i=e.defaults===!0,s=["precision",1,ys,"rounding",0,8,"toExpNeg",-Ao,0,"toExpPos",0,Ao,"maxE",0,Ao,"minE",-Ao,0,"modulo",0,9];for(t=0;t<s.length;t+=3)if(r=s[t],i&&(this[r]=eh[r]),(n=e[r])!==void 0)if(Or(n)===n&&n>=s[t+1]&&n<=s[t+2])this[r]=n;else throw Error(us+r+": "+n);if(r="crypto",i&&(this[r]=eh[r]),(n=e[r])!==void 0)if(n===!0||n===!1||n===0||n===1)if(n)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))this[r]=!0;else throw Error(x4);else this[r]=!1;else throw Error(us+r+": "+n);return this}function H9(e){return new this(e).cos()}function K9(e){return new this(e).cosh()}function I4(e){var t,r,n;function i(s){var o,a,c,u=this;if(!(u instanceof i))return new i(s);if(u.constructor=i,vg(s)){u.s=s.s,ct?!s.d||s.e>i.maxE?(u.e=NaN,u.d=null):s.e<i.minE?(u.e=0,u.d=[0]):(u.e=s.e,u.d=s.d.slice()):(u.e=s.e,u.d=s.d?s.d.slice():s.d);return}if(c=typeof s,c==="number"){if(s===0){u.s=1/s<0?-1:1,u.e=0,u.d=[0];return}if(s<0?(s=-s,u.s=-1):u.s=1,s===~~s&&s<1e7){for(o=0,a=s;a>=10;a/=10)o++;ct?o>i.maxE?(u.e=NaN,u.d=null):o<i.minE?(u.e=0,u.d=[0]):(u.e=o,u.d=[s]):(u.e=o,u.d=[s]);return}else if(s*0!==0){s||(u.s=NaN),u.e=NaN,u.d=null;return}return nh(u,s.toString())}else if(c!=="string")throw Error(us+s);return(a=s.charCodeAt(0))===45?(s=s.slice(1),u.s=-1):(a===43&&(s=s.slice(1)),u.s=1),E4.test(s)?nh(u,s):j9(u,s)}if(i.prototype=be,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=G9,i.clone=I4,i.isDecimal=vg,i.abs=R9,i.acos=N9,i.acosh=D9,i.add=$9,i.asin=B9,i.asinh=L9,i.atan=F9,i.atanh=U9,i.atan2=z9,i.cbrt=V9,i.ceil=q9,i.clamp=W9,i.cos=H9,i.cosh=K9,i.div=X9,i.exp=J9,i.floor=Y9,i.hypot=Z9,i.ln=Q9,i.log=eR,i.log10=rR,i.log2=tR,i.max=nR,i.min=iR,i.mod=sR,i.mul=oR,i.pow=aR,i.random=cR,i.round=uR,i.sign=lR,i.sin=fR,i.sinh=dR,i.sqrt=hR,i.sub=pR,i.sum=mR,i.tan=gR,i.tanh=vR,i.trunc=yR,e===void 0&&(e={}),e&&e.defaults!==!0)for(n=["precision","rounding","toExpNeg","toExpPos","maxE","minE","modulo","crypto"],t=0;t<n.length;)e.hasOwnProperty(r=n[t++])||(e[r]=this[r]);return i.config(e),i}function X9(e,t){return new this(e).div(t)}function J9(e){return new this(e).exp()}function Y9(e){return Xe(e=new this(e),e.e+1,3)}function Z9(){var e,t,r=new this(0);for(ct=!1,e=0;e<arguments.length;)if(t=new this(arguments[e++]),t.d)r.d&&(r=r.plus(t.times(t)));else{if(t.s)return ct=!0,new this(1/0);r=t}return ct=!0,r.sqrt()}function vg(e){return e instanceof Sc||e&&e.toStringTag===S4||!1}function Q9(e){return new this(e).ln()}function eR(e,t){return new this(e).log(t)}function tR(e){return new this(e).log(2)}function rR(e){return new this(e).log(10)}function nR(){return A4(this,arguments,"lt")}function iR(){return A4(this,arguments,"gt")}function sR(e,t){return new this(e).mod(t)}function oR(e,t){return new this(e).mul(t)}function aR(e,t){return new this(e).pow(t)}function cR(e){var t,r,n,i,s=0,o=new this(1),a=[];if(e===void 0?e=this.precision:qr(e,1,ys),n=Math.ceil(e/Qe),this.crypto)if(crypto.getRandomValues)for(t=crypto.getRandomValues(new Uint32Array(n));s<n;)i=t[s],i>=429e7?t[s]=crypto.getRandomValues(new Uint32Array(1))[0]:a[s++]=i%1e7;else if(crypto.randomBytes){for(t=crypto.randomBytes(n*=4);s<n;)i=t[s]+(t[s+1]<<8)+(t[s+2]<<16)+((t[s+3]&127)<<24),i>=214e7?crypto.randomBytes(4).copy(t,s):(a.push(i%1e7),s+=4);s=n/4}else throw Error(x4);else for(;s<n;)a[s++]=Math.random()*1e7|0;for(n=a[--s],e%=Qe,n&&e&&(i=pr(10,Qe-e),a[s]=(n/i|0)*i);a[s]===0;s--)a.pop();if(s<0)r=0,a=[0];else{for(r=-1;a[0]===0;r-=Qe)a.shift();for(n=1,i=a[0];i>=10;i/=10)n++;n<Qe&&(r-=Qe-n)}return o.e=r,o.d=a,o}function uR(e){return Xe(e=new this(e),e.e+1,this.rounding)}function lR(e){return e=new this(e),e.d?e.d[0]?e.s:0*e.s:e.s||NaN}function fR(e){return new this(e).sin()}function dR(e){return new this(e).sinh()}function hR(e){return new this(e).sqrt()}function pR(e,t){return new this(e).sub(t)}function mR(){var e=0,t=arguments,r=new this(t[e]);for(ct=!1;r.s&&++e<t.length;)r=r.plus(t[e]);return ct=!0,Xe(r,this.precision,this.rounding)}function gR(e){return new this(e).tan()}function vR(e){return new this(e).tanh()}function yR(e){return Xe(e=new this(e),e.e+1,1)}be[Symbol.for("nodejs.util.inspect.custom")]=be.toString;be[Symbol.toStringTag]="Decimal";var Sc=be.constructor=I4(eh);Bu=new Sc(Bu);Lu=new Sc(Lu);var fu=Sc,rs=Qo(ea()),Xf=Qo(ea()),bR=class{constructor(e){if(e!==0)throw new Error("Aftermath only supported on mainnet");this.slippage="900000000000000000",this.poolRegistry="0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae",this.protocolFeeVault="0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4",this.treasury="0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce",this.insuranceFund="0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b",this.referrealVault="0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278"}amountLimit(e){return new Xf.default(e).mul(new Xf.default(this.slippage)).div(new Xf.default("1000000000000000000")).toString()}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o];if(r.extendedDetails==null)throw new Error("Extended details not supported");if(r.extendedDetails.aftermathLpSupplyType==null)throw new Error("LP supply type not supported");const f=[t.object(r.id),t.object(this.poolRegistry),t.object(this.protocolFeeVault),t.object(this.treasury),t.object(this.insuranceFund),t.object(this.referrealVault),t.pure.u64(this.amountLimit(r.amountOut)),t.pure.u64(this.slippage),n],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::aftermath::${c}`,typeArguments:[u,l,r.extendedDetails.aftermathLpSupplyType],arguments:f})})}},yg="0x000000000000000000000000000000000000000000000000000000000000dee9",wR=class{constructor(e){if(e!==0)throw new Error("Aftermath only supported on mainnet")}getAccountCap(e,t){return _t(this,null,function*(){let r=50,n=null;for(;;){const i=e.getOwnedObjects({owner:t,cursor:n,limit:r,filter:{MoveModule:{package:yg,module:"custodian_v2"}}});if(i!=null&&i.data!=null){if(i.data.length!==0)return i.data[0].data.objectId;if(i.data.length<50)break}else break}return null})}getOrCreateAccountCap(e,t,r){return _t(this,null,function*(){let n=yield this.getAccountCap(t,r);return n!==null?{accountCap:e.object(n),isCreate:!1}:{accountCap:e.moveCall({target:`${yg}::clob_v2::create_account`,typeArguments:[],arguments:[]}),isCreate:!0}})}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=yield this.getOrCreateAccountCap(t,e.client,e.signer),h=[t.object(r.id),n,f.accountCap,t.object(ni)],y=yr(e.publishedAtV2(),i),b=t.moveCall({target:`${y}::deepbook::${c}`,typeArguments:[u,l],arguments:h});return f.isCreate&&t.transferObjects([f.accountCap],e.signer),b})}},_R=class{constructor(e){if(e!==0)throw new Error("Kriya amm only supported on mainnet")}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(r.id),n],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::kriya_amm::${c}`,typeArguments:[u,l],arguments:f})})}},xR=class{constructor(e){if(e!==0)throw new Error("Kriya clmm only supported on mainnet");this.version="0xf5145a7ac345ca8736cf8c76047d00d6d378f30e81be6f6eb557184d9de93c78"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(r.id),n,t.object(this.version),t.object(ni)],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::kriya_clmm::${c}`,typeArguments:[u,l],arguments:f})})}},SR=class{constructor(e){if(e!==0)throw new Error("Flowx only supported on mainnet");this.container="0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.container),n],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::flowx_amm::${c}`,typeArguments:[u,l],arguments:f})})}},ER=class{constructor(e){if(e!==0)throw new Error("Flowx clmm only supported on mainnet");this.versioned="0x67624a1533b5aff5d0dfcf5e598684350efd38134d2d245f475524c03a64e656",this.poolRegistry="0x27565d24a4cd51127ac90e4074a841bbe356cca7bf5759ddc14a975be1632abc"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.poolRegistry),t.pure.u64(r.feeRate*1e6),n,t.object(this.versioned),t.object(ni)],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::flowx_clmm::${c}`,typeArguments:[u,l],arguments:f})})}},CR=class{constructor(e){if(e!==0)throw new Error("Turbos only supported on mainnet");this.versioned="0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o];if(r.extendedDetails==null)throw new Error("Extended details not supported");if(r.extendedDetails.turbosFeeType==null)throw new Error("Turbos fee type not supported");const f=[t.object(r.id),n,t.object(ni),t.object(this.versioned)],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::turbos::${c}`,typeArguments:[u,l,r.extendedDetails.turbosFeeType],arguments:f})})}},bg=class{constructor(e,t){this.globalConfig=e===0?"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f":"0x9774e359588ead122af1c7e7f64e14ade261cfeecdb5d0eb4a5b3b4c8ab8bd3e",this.partner=t??(e===0?"0x639b5e433da31739e800cd085f356e64cae222966d0f1b11bd9dc76b322ff58b":"0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5")}flash_swap(e,t,r,n,i){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["flash_swap_a2b",o,a]:["flash_swap_b2a",a,o];let f=n?r.amountIn:r.amountOut;const h=[t.object(this.globalConfig),t.object(r.id),t.object(this.partner),t.pure.u64(f),t.pure.bool(n),t.object(ni)],y=yr(e.publishedAtV2(),i),b=t.moveCall({target:`${y}::cetus::${c}`,typeArguments:[u,l],arguments:h});return{targetCoin:b[0],flashReceipt:b[1],payAmount:b[2]}}repay_flash_swap(e,t,r,n,i,s){const{direction:o,from:a,target:c}=r,[u,l,f]=o?["repay_flash_swap_a2b",a,c]:["repay_flash_swap_b2a",c,a],h=[t.object(this.globalConfig),t.object(r.id),t.object(this.partner),n,i],y=yr(e.publishedAtV2(),s);return t.moveCall({target:`${y}::cetus::${u}`,typeArguments:[l,f],arguments:h})[0]}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.globalConfig),t.object(r.id),t.object(this.partner),n,t.object(ni)],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::cetus::${c}`,typeArguments:[u,l],arguments:f})})}};function wg(e,...t){const r=Array.isArray(t[t.length-1])?t.pop():[];let i=[e,...t].filter(Boolean).join("::");return r&&r.length&&(i+=`<${r.join(", ")}>`),i}function MR(e){return e.split("::")[0]}function Gs(e){var t;try{let r=e.replace(/\s/g,"");const n=r.match(/(<.+>)$/),i=(t=n==null?void 0:n[0])==null?void 0:t.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(i){r=r.slice(0,r.indexOf("<"));const c=Gs(r),u=x9(_9({},c),{type_arguments:i.map(l=>Gs(l).source_address)});return u.type_arguments=u.type_arguments.map(l=>Wn.isSuiCoin(l)?l:Gs(l).source_address),u.source_address=wg(u.full_address,u.type_arguments),u}const s=r.split("::"),a={full_address:r,address:r===P4||r===OR?"0x2":Zd.normalizeSuiObjectId(s[0]),module:s[1],name:s[2],type_arguments:[],source_address:""};return a.full_address=`${a.address}::${a.module}::${a.name}`,a.source_address=wg(a.full_address,a.type_arguments),a}catch{return{full_address:e,address:"",module:"",name:"",type_arguments:[],source_address:e}}}function _g(e){return Gs(e).source_address}var AR="0x2::coin::Coin",TR=/^0x2::coin::Coin<(.+)>$/,P4="0x2::sui::SUI",OR="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Wn=class Xi{static getCoinTypeArg(t){const r=t.type.match(TR);return r?r[1]:null}static isSUI(t){const r=Xi.getCoinTypeArg(t);return r?Xi.getCoinSymbol(r)==="SUI":!1}static getCoinSymbol(t){return t.substring(t.lastIndexOf(":")+1)}static getBalance(t){return BigInt(t.fields.balance)}static totalBalance(t,r){let n=BigInt(0);return t.forEach(i=>{r===i.coinAddress&&(n+=BigInt(i.balance))}),n}static getID(t){return t.fields.id.id}static getCoinTypeFromArg(t){return`${AR}<${t}>`}static getCoinAssets(t,r){const n=[];return r.forEach(i=>{_g(i.coinAddress)===_g(t)&&n.push(i)}),n}static isSuiCoin(t){return Gs(t).full_address===P4}static selectCoinObjectIdGreaterThanOrEqual(t,r,n=[]){const i=Xi.selectCoinAssetGreaterThanOrEqual(t,r,n),s=i.selectedCoins.map(c=>c.coinObjectId),o=i.remainingCoins,a=i.selectedCoins.map(c=>c.balance.toString());return{objectArray:s,remainCoins:o,amountArray:a}}static selectCoinAssetGreaterThanOrEqual(t,r,n=[]){const i=Xi.sortByBalance(t.filter(u=>!n.includes(u.coinObjectId))),s=Xi.calculateTotalBalance(i);if(s<r)return{selectedCoins:[],remainingCoins:i};if(s===r)return{selectedCoins:i,remainingCoins:[]};let o=BigInt(0);const a=[],c=[...i];for(;o<s;){const u=r-o,l=c.findIndex(h=>h.balance>=u);if(l!==-1){a.push(c[l]),c.splice(l,1);break}const f=c.pop();f.balance>0&&(a.push(f),o+=f.balance)}return{selectedCoins:Xi.sortByBalance(a),remainingCoins:Xi.sortByBalance(c)}}static sortByBalance(t){return t.sort((r,n)=>r.balance<n.balance?-1:r.balance>n.balance?1:0)}static sortByBalanceDes(t){return t.sort((r,n)=>r.balance>n.balance?-1:r.balance<n.balance?0:1)}static calculateTotalBalance(t){return t.reduce((r,n)=>r+n.balance,BigInt(0))}};function Jf(e){switch(e){case 1e4:return"Calculate error";case 10001:return"Input number too large can not fit in target type";case 10002:return"No router";case 10003:return"Insufficient Liquidity";case 10004:return"Target token is detected as a HoneyPot scam";default:return"Unknown error"}}function ls(e){const t=e.indexOf("::");if(t===-1)return e;const r=e.substring(0,t),n=e.substring(t);if(!r.startsWith("0x"))return e;const i=r.substring(2);return i.length>64?e:`0x${i.padStart(64,"0")}${n}`}function IR(e,t){e=ls(e),t=ls(t);const r=Math.min(e.length,t.length);for(let n=0;n<r;n++){if(e[n]>t[n])return!0;if(e[n]<t[n])return!1}return!0}function j4(e,t){return e.moveCall({target:"0x2::coin::zero",typeArguments:[t]})}function Yf(e,t,r,n){const i=Wn.getCoinAssets(n,t);if(r===BigInt(0))return Wn.isSuiCoin(n)||i.length===0&&!Wn.isSuiCoin(n)?{targetCoin:j4(e,n),isMintZeroCoin:!0,targetCoinAmount:0}:{targetCoin:e.object(i[0].coinObjectId),isMintZeroCoin:!1,targetCoinAmount:Number(i[0].balance.toString())};if(Wn.calculateTotalBalance(i)<r)throw new AggregateError("Insufficient balance when build merge coin, coinType: "+n,"InsufficientBalance"+n);if(Wn.isSuiCoin(n))return{targetCoin:e.splitCoins(e.gas,[e.pure.u64(r.toString())]),isMintZeroCoin:!0,targetCoinAmount:Number(r.toString())};let o=Wn.sortByBalance(i);o.slice(0,3).reduce((h,y)=>h+y.balance,BigInt(0))<BigInt(r)&&(o=Wn.sortByBalanceDes(i));let c=Wn.selectCoinObjectIdGreaterThanOrEqual(o,r);const[u,...l]=c.objectArray;return l.length>0&&e.mergeCoins(u,l.map(h=>e.object(h))),{targetCoin:e.splitCoins(e.object(u),[e.pure.u64(r.toString())]),isMintZeroCoin:!1,targetCoinAmount:Number(r.toString())}}function PR(e,t=!0){return _t(this,null,function*(){console.log("inputs",e.getData().inputs),e.getData().commands.forEach((r,n)=>{t&&console.log(`transaction ${n}: `,JSON.stringify(r,null,2))})})}function jR(e){return!(!e.startsWith("0x")||e.length!==66)}var ao=Qo(ea()),ns=Qo(ea()),Ec=Qo(ea()),Ci=new Ec.default(0);new Ec.default(1);var kR=new Ec.default(2);kR.pow(new Ec.default(128));var RR=new Ec.default("18446744073709551615"),an=1e9;function NR(e,t,r){let n=Ci;return t?n=e.mul(new ns.default(an-r*an)).div(new ns.default(an)):n=e.mul(new ns.default(an+r*an)).div(new ns.default(an)),Number(n.toString())}function DR(e,t,r){let n=Ci;return t?n=e.mul(new ns.default(an-r*an)).div(new ns.default(an)):n=e.mul(new ns.default(an+r*an)).div(new ns.default(an)),n}function $R(e,t,r){return new fu(e).mul(fu.pow(2,-64)).pow(2).mul(fu.pow(10,t-r))}function BR(e,t,r,n){return _t(this,null,function*(){var i,s,o,a,c;const{from:u,target:l,amount:f,byAmountIn:h,pools:y}=t,b=ls(u),w=ls(l),T=new p9.Transaction,P=IR(b,w),k=n===0?"0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10":"0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293",N=P?b:w,F=P?w:b,L=[N,F];console.log("typeArguments",L,k);for(let C=0;C<y.length;C++){const g=[T.object(y[C]),T.pure.bool(P),T.pure.bool(h),T.pure.u64(f.toString())];T.moveCall({target:`${k}::fetcher_script::calculate_swap_result`,arguments:g,typeArguments:L})}if(!jR(r))throw new AggregateError("Aggregator package not set","InvalidWallet");PR(T);const G=yield e.devInspectTransactionBlock({transactionBlock:T,sender:r});if(G.error!=null)throw console.log("simulateRes.error",G.error),new AggregateError("Aggregator package not set","SimulateError");const q=(i=G.events)==null?void 0:i.filter(C=>C.type.includes("CalculatedSwapResultEvent"));if(q.length===0||q.length!==y.length)throw new AggregateError("Simulate event result error","simulateEventError");let X=h?Ci:RR,ne=0;for(let C=0;C<q.length;C+=1)if(!q[C].parsedJson.data.is_exceed)if(t.byAmountIn){const g=new ao.BN(q[C].parsedJson.data.amount_out);g.gt(X)&&(ne=C,X=g)}else{const g=new ao.BN(q[C].parsedJson.data.amount_out);g.lt(X)&&(ne=C,X=g)}const ae=q[ne].parsedJson.data;console.log("event",JSON.stringify(ae,null,2));const ce=ae.step_results[0].current_sqrt_price,[V,D]=yield Promise.all([e.getCoinMetadata({coinType:N}).then(C=>C==null?void 0:C.decimals),e.getCoinMetadata({coinType:F}).then(C=>C==null?void 0:C.decimals)]);if(V==null||D==null)throw new AggregateError("Simulate event result error","CannotGetDecimals");const p=$R(ce,V,D),d=Number(ae.fee_rate)/1e6,m=new ao.BN((s=ae.amount_in)!=null?s:0),x=new ao.BN((o=ae.fee_amount)!=null?o:0),M=m.add(x),E={amountIn:M,amountOut:new ao.BN((a=ae.amount_out)!=null?a:0),routes:[{path:[{id:y[ne],direction:P,provider:"CETUS",from:b,target:w,feeRate:d,amountIn:ae.amount_in,amountOut:ae.amount_out,extendedDetails:{afterSqrtPrice:ae.after_sqrt_price}}],amountIn:M,amountOut:new ao.BN((c=ae.amount_out)!=null?c:0),initialPrice:p}],insufficientLiquidity:!1,byAmountIn:t.byAmountIn};return{isExceed:ae.is_exceed,routeData:E}})}var LR=class{constructor(e){if(e!==0)throw new Error("Haedal only supported on mainnet")}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s}=r,o=s?"swap_a2b":"swap_b2a",a=[t.object(r.id),t.object("0x5"),n],c=yr(e.publishedAtV2(),i);return t.moveCall({target:`${c}::haedal::${o}`,typeArguments:[],arguments:a})})}},FR=class{constructor(e){if(e!==0)throw new Error("Afsui only supported on mainnet");this.stakedSuiVault="0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",this.safe="0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",this.referVault="0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",this.validator="0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s}=r;if(!s)throw new Error("Afsui not support b2a swap");const o="swap_a2b",a=[t.object(this.stakedSuiVault),t.object(this.safe),t.object("0x5"),t.object(this.referVault),t.object(this.validator),n],c=yr(e.publishedAtV2(),i);return t.moveCall({target:`${c}::afsui::${o}`,typeArguments:[],arguments:a})})}},UR=class{constructor(e){if(e!==0)throw new Error("Volo only supported on mainnet");this.nativePool="0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",this.metadata="0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s}=r;if(!s)throw new Error("Volo not support b2a swap");const o="swap_a2b",a=[t.object(this.nativePool),t.object(this.metadata),t.object("0x5"),n],c=yr(e.publishedAtV2(),i);return t.moveCall({target:`${c}::volo::${o}`,typeArguments:[],arguments:a})})}},zR=class{constructor(e){if(e!==0)throw new Error("Bluemove only supported on mainnet");this.dexInfo="0x3f2d9f724f4a1ce5e71676448dc452be9a6243dac9c5b975a588c8c867066e92"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.dexInfo),n],h=yr(e.publishedAtV2(),i);return t.moveCall({target:`${h}::bluemove::${c}`,typeArguments:[u,l],arguments:f})})}},VR=class{constructor(e){this.deepbookV3Config=e===0?"0xe4099d0cda04f3aa80028fac91a9b3dbe50d08f2ff42aa2c29473926e34ca48c":"0xe19b5d072346cae83a037d4e3c8492068a74410a74e5830b3a68012db38296aa"}swap(e,t,r,n,i,s){return _t(this,null,function*(){const{direction:o,from:a,target:c}=r,[u,l,f]=o?["swap_a2b",a,c]:["swap_b2a",c,a];let h;s?h=s:h=j4(t,e.deepbookv3DeepFeeType());const y=[t.object(this.deepbookV3Config),t.object(r.id),n,h,t.object(ni)],b=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${b}::deepbookv3::${u}`,typeArguments:[l,f],arguments:y})})}},qR=class{constructor(e){if(e!==0)throw new Error("Scallop only supported on mainnet");this.version=e===0?"0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7":"0x0",this.market=e===0?"0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9":"0x0"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",o,a];if(r.extendedDetails==null)throw new Error("Extended details not supported");if(r.extendedDetails.scallopScoinTreasury==null)throw new Error("Scallop coin treasury not supported");const f=[t.object(this.version),t.object(this.market),t.object(r.extendedDetails.scallopScoinTreasury),n,t.object(ni)],h=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${h}::scallop::${c}`,typeArguments:[u,l],arguments:f})})}},xg=class{constructor(e){if(e!==0)throw new Error("Suilend only supported on mainnet");this.sui_system_state=e===0?"0x0000000000000000000000000000000000000000000000000000000000000005":"0x0"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u]=s?["swap_a2b",a]:["swap_b2a",o],l=[t.object(r.id),t.object(this.sui_system_state),n],f=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${f}::suilend::${c}`,typeArguments:[u],arguments:l})})}},WR=class{constructor(e){if(e!==0)throw new Error("Bluefin only supported on mainnet");this.globalConfig="0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o],f=[t.object(this.globalConfig),t.object(r.id),n,t.object(ni)],h=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${h}::bluefin::${c}`,typeArguments:[u,l],arguments:f})})}},GR=class{constructor(e,t){if(e===1){this.connection=new Bc.SuiPriceServiceConnection("https://hermes-beta.pyth.network");const r="0x31358d198147da50db32eda2562951d53973a0c0ad5ed738e9b17d88b213d790",n="0x243759059f4c3111179da5878c12f68d612c21a8d54d85edc86164bb18be1c7c";this.pythClient=new Bc.SuiPythClient(t,n,r)}else{this.connection=new Bc.SuiPriceServiceConnection("https://hermes.pyth.network");const r="0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c",n="0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";this.pythClient=new Bc.SuiPythClient(t,n,r)}}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u,l]=s?["swap_a2b",o,a]:["swap_b2a",a,o];let f,h;if(r.extendedDetails==null)throw new Error("Extended details not supported haedal pmm");if(!r.extendedDetails.haedalPmmBasePriceSeed||!r.extendedDetails.haedalPmmQuotePriceSeed)throw new Error("Base price seed or quote price seed not supported");f=r.extendedDetails.haedalPmmBasePriceSeed,h=r.extendedDetails.haedalPmmQuotePriceSeed;const y=[f,h],b=yield this.connection.getPriceFeedsUpdateData(y),w=yield this.pythClient.updatePriceFeeds(t,b,y),T=[t.object(r.id),t.object(w[0]),t.object(w[1]),n,t.object(ni)],P=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${P}::haedalpmm::${c}`,typeArguments:[u,l],arguments:T})})}},HR=class{constructor(e){if(e!==0)throw new Error("Alphafi only supported on mainnet");this.sui_system_state=e===0?"0x0000000000000000000000000000000000000000000000000000000000000005":"0x0"}swap(e,t,r,n,i){return _t(this,null,function*(){const{direction:s,from:o,target:a}=r,[c,u]=s?["swap_a2b",a]:["swap_b2a",o],l=[t.object(r.id),t.object(this.sui_system_state),n],f=ta(e.publishedAtV2Extend(),i);return t.moveCall({target:`${f}::alphafi::${c}`,typeArguments:[u],arguments:l})})}},k4="CETUS",KR="DEEPBOOK",XR="KRIYA",JR="FLOWX",YR="FLOWXV3",ZR="KRIYAV3",R4="TURBOS",ih="AFTERMATH",QR="HAEDAL",eN="VOLO",tN="AFSUI",rN="BLUEMOVE",N4="DEEPBOOKV3",D4="SCALLOP",nN="SUILEND",iN="BLUEFIN",$4="HAEDALPMM",sN="ALPHAFI",oN="SPRINGSUI",aN="https://api-sui.cetus.zone/router_v2";function Sg(e){return Array.isArray(e.routers)}function Zf(e){return Array.isArray(e.routers)}var cN=class{constructor(e,t,r,n){this.endpoint=e?dN(e):aN,this.client=r||new dg.SuiClient({url:dg.getFullnodeUrl("mainnet")}),this.signer=t||"",this.env=n||0,this.allCoins=new Map}getCoins(e,t=!0){return _t(this,null,function*(){if(this.signer==="")throw new Error("Signer is required, but not provided.");let r=null,n=50;if(!t){const s=this.allCoins.get(e);if(s)return s}const i=[];for(;;){const s=yield this.client.getCoins({owner:this.signer,coinType:e,cursor:r,limit:n});for(const o of s.data)i.push({coinAddress:Gs(o.coinType).source_address,coinObjectId:o.coinObjectId,balance:BigInt(o.balance)});if(s.data.length<n)break;r=s.data[n-1].coinObjectId}return this.allCoins.set(e,i),i})}findRouters(e){return _t(this,null,function*(){return hN(this.endpoint,e)})}expectInputSwap(e,t,r,n,i,s,o){return _t(this,null,function*(){if(r.length===0)throw new Error("No router found");const a=r.map(b=>b.amountIn.toString()),c=r[0].path[0].from,u=r[0].path[r[0].path.length-1].target,l=e.splitCoins(t,a),f=[];for(let b=0;b<r.length;b++){if(r[b].path.length===0)throw new Error("Empty path");let w=l[b];for(const T of r[b].path)w=yield this.newDex(T.provider,i).swap(this,e,T,w,o,s);f.push(w)}const h=yr(this.publishedAtV2(),o);return this.transferOrDestoryCoin(e,t,c,this.publishedAtV2()),this.checkCoinThresholdAndMergeCoin(e,f,u,n,h)})}expectOutputSwap(e,t,r,n,i){return _t(this,null,function*(){const s=[],o=[],a=[],c=new bg(this.env,n),u=yr(this.publishedAtV2(),i);for(let f=0;f<r.length;f++){const h=r[f];for(let b=h.path.length-1;b>=0;b--){const w=h.path[b],T=c.flash_swap(this,e,w,!1);s.unshift(T.targetCoin),o.unshift(T.flashReceipt)}let y=t;for(let b=0;b<h.path.length;b++){const w=h.path[b],T=c.repay_flash_swap(this,e,w,y,o[b]);y=s[b],b===0?t=T:this.transferOrDestoryCoin(e,T,w.from,u),b===h.path.length-1&&a.push(y)}}const l=r[0].path[0].from;if(this.transferOrDestoryCoin(e,t,l,u),a.length>1){const f=e.makeMoveVec({elements:a.slice(1)});e.moveCall({target:`${Zd.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,typeArguments:[r[0].path[r[0].path.length-1].target],arguments:[a[0],f]})}return a[0]})}swapInPools(e){return _t(this,null,function*(){let t;try{t=yield BR(this.client,e,this.signer,this.env)}catch(r){return console.error("swapInPools error:",r),null}return t})}routerSwap(e){return _t(this,null,function*(){const{routers:t,inputCoin:r,slippage:n,txb:i,partner:s,deepbookv3DeepFee:o}=e,a=Array.isArray(t)?t:t.routes,c=Sg(e)?e.byAmountIn:e.routers.byAmountIn,u=a.reduce((T,P)=>T.add(P.amountIn),new rs.default(0)),l=a.reduce((T,P)=>T.add(P.amountOut),new rs.default(0)),f=DR(c?l:u,c,n),h=Sg(e)?void 0:e.routers.packages;console.log("packages11",h);const y=yr(this.publishedAtV2(),h);if(c)return yield this.expectInputSwap(i,r,a,f,s,o,h);const b=i.splitCoins(r,[f.toString()]);return this.transferOrDestoryCoin(i,r,a[0].path[0].from,y),yield this.expectOutputSwap(i,b[0],a,s)})}fastRouterSwap(e){return _t(this,null,function*(){const{routers:t,slippage:r,txb:n,partner:i,refreshAllCoins:s,payDeepFeeAmount:o}=e,a=Array.isArray(t)?t:t.routes,c=a[0].path[0].from;let u=yield this.getCoins(c,s);const l=a[0].path[a[0].path.length-1].target,f=a.reduce((F,L)=>F.add(L.amountIn),new rs.default(0)),h=a.reduce((F,L)=>F.add(L.amountOut),new rs.default(0)),y=Zf(e)?e.byAmountIn:e.routers.byAmountIn,b=NR(y?h:f,y,r),T=Yf(n,u,BigInt((y?f:b).toString()),c);let P;if(o&&o>0){let F=yield this.getCoins(this.deepbookv3DeepFeeType());P=Yf(n,F,BigInt(o),this.deepbookv3DeepFeeType()).targetCoin}const k=Zf(e)?{routers:a,inputCoin:T.targetCoin,slippage:r,byAmountIn:y,txb:n,partner:i,deepbookv3DeepFee:P}:{routers:e.routers,inputCoin:T.targetCoin,slippage:r,byAmountIn:y,txb:n,partner:i,deepbookv3DeepFee:P},N=yield this.routerSwap(k);if(Wn.isSuiCoin(l))n.mergeCoins(n.gas,[N]);else{let F=yield this.getCoins(l,s);const L=Yf(n,F,BigInt(0),l),G=Zf(e)?void 0:e.routers.packages,q=yr(this.publishedAtV2(),G);n.mergeCoins(L.targetCoin,[N]),L.isMintZeroCoin&&this.transferOrDestoryCoin(n,L.targetCoin,l,q)}})}publishedAtV2(){return this.env===0?"0xf9c6f78322ed667909e05f6b42b2f5a67af6297503c905335e02a15148e9440d":"0x52eae33adeb44de55cfb3f281d4cc9e02d976181c0952f5323648b5717b33934"}publishedAtV2Extend(){return this.env===0?"0xf2fcea41dc217385019828375764fa06d9bd25e8e4726ba1962680849fb8d613":"0xabb6a81c8a216828e317719e06125de5bb2cb0fe8f9916ff8c023ca5be224c78"}deepbookv3DeepFeeType(){return this.env===0?"0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP":"0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP"}transferOrDestoryCoin(e,t,r,n){e.moveCall({target:`${n}::utils::transfer_or_destroy_coin`,typeArguments:[r],arguments:[t]})}checkCoinThresholdAndMergeCoin(e,t,r,n,i){let s=t[0];if(t.length>1){let o=e.makeMoveVec({elements:t.slice(1)});e.moveCall({target:`${Zd.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,typeArguments:[r],arguments:[t[0],o]}),s=t[0]}return e.moveCall({target:`${i}::utils::check_coin_threshold`,typeArguments:[r],arguments:[s,e.pure.u64(n.toString())]}),s}newDex(e,t){switch(e){case k4:return new bg(this.env,t);case KR:return new wR(this.env);case N4:return new VR(this.env);case XR:return new _R(this.env);case ZR:return new xR(this.env);case JR:return new SR(this.env);case YR:return new ER(this.env);case R4:return new CR(this.env);case ih:return new bR(this.env);case QR:return new LR(this.env);case tN:return new FR(this.env);case eN:return new UR(this.env);case rN:return new zR(this.env);case D4:return new qR(this.env);case nN:return new xg(this.env);case oN:return new xg(this.env);case iN:return new WR(this.env);case $4:return new GR(this.env,this.client);case sN:return new HR(this.env);default:throw new Error(`Unsupported dex ${e}`)}}signAndExecuteTransaction(e,t){return _t(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:e,signer:t,options:{showEffects:!0,showEvents:!0,showInput:!0,showBalanceChanges:!0}})})}devInspectTransactionBlock(e){return _t(this,null,function*(){return yield this.client.devInspectTransactionBlock({transactionBlock:e,sender:this.signer})})}sendTransaction(e,t){return _t(this,null,function*(){return yield this.client.signAndExecuteTransaction({transaction:e,signer:t})})}getDeepbookV3Config(){return _t(this,null,function*(){const e=yield gN(this.endpoint);return e?e.data:null})}};function uN(e,t){let r=0;for(const s of e.routes)for(const o of s.path)o.extended_details&&o.extended_details.deepbookv3_deep_fee&&(r+=Number(o.extended_details.deepbookv3_deep_fee));let n;if(e.packages!=null){n=new Map;for(const[s,o]of Object.entries(e.packages))n.set(s,o)}return{amountIn:new rs.default(e.amount_in.toString()),amountOut:new rs.default(e.amount_out.toString()),byAmountIn:t,insufficientLiquidity:!1,routes:e.routes.map(s=>({path:s.path.map(o=>{var a,c,u,l,f,h,y;let b;o.provider===ih&&(b=o.extended_details.aftermath_pool_flatness===0?"v2":"v3");let w;return(o.provider===R4||o.provider===ih||o.provider===k4||o.provider===N4||o.provider===D4||o.provider===$4)&&(w={aftermathLpSupplyType:(a=o.extended_details)==null?void 0:a.aftermath_lp_supply_type,turbosFeeType:(c=o.extended_details)==null?void 0:c.turbos_fee_type,afterSqrtPrice:(u=o.extended_details)==null?void 0:u.after_sqrt_price,deepbookv3DeepFee:(l=o.extended_details)==null?void 0:l.deepbookv3_deep_fee,scallopScoinTreasury:(f=o.extended_details)==null?void 0:f.scallop_scoin_treasury,haedalPmmBasePriceSeed:(h=o.extended_details)==null?void 0:h.haedal_pmm_base_price_seed,haedalPmmQuotePriceSeed:(y=o.extended_details)==null?void 0:y.haedal_pmm_quote_price_seed}),{id:o.id,direction:o.direction,provider:o.provider,from:o.from,target:o.target,feeRate:o.fee_rate,amountIn:o.amount_in,amountOut:o.amount_out,extendedDetails:w,version:b}}),amountIn:new rs.default(s.amount_in.toString()),amountOut:new rs.default(s.amount_out.toString()),initialPrice:new fu(s.initial_price.toString())})),totalDeepFee:r,packages:n}}var ni="0x0000000000000000000000000000000000000000000000000000000000000006",lN="aggregator_v2",fN="aggregator_v2_extend";function yr(e,t){var r;return t instanceof Map&&(r=t.get(lN))!=null?r:e}function ta(e,t){var r;return t instanceof Map&&(r=t.get(fN))!=null?r:e}Qo(ea());function dN(e){return e.endsWith("/find_routes")?e.replace("/find_routes",""):e}function hN(e,t){return _t(this,null,function*(){let r;if(t.liquidityChanges&&t.liquidityChanges.length>0?r=yield mN(e,t):r=yield pN(e,t),!r)return null;if(!r.ok)return{amountIn:Ci,amountOut:Ci,routes:[],byAmountIn:t.byAmountIn,insufficientLiquidity:!1,error:{code:10001,msg:Jf(10001)}};const n=yield r.json(),i=n.msg==="liquidity is not enough";return n.msg&&n.msg.indexOf("HoneyPot scam")>-1?{amountIn:Ci,amountOut:Ci,routes:[],byAmountIn:t.byAmountIn,insufficientLiquidity:i,error:{code:10004,msg:Jf(10004)}}:n.data!=null?uN(n.data,t.byAmountIn):{amountIn:Ci,amountOut:Ci,routes:[],insufficientLiquidity:i,byAmountIn:t.byAmountIn,error:{code:10003,msg:Jf(10003)}}})}function pN(e,t){return _t(this,null,function*(){try{const{from:r,target:n,amount:i,byAmountIn:s,depth:o,splitAlgorithm:a,splitFactor:c,splitCount:u,providers:l}=t,f=ls(r),h=ls(n);let y=`${e}/find_routes?from=${f}&target=${h}&amount=${i.toString()}&by_amount_in=${s}`;return o&&(y+=`&depth=${o}`),a&&(y+=`&split_algorithm=${a}`),c&&(y+=`&split_factor=${c}`),u&&(y+=`&split_count=${u}`),l&&l.length>0&&(y+=`&providers=${l.join(",")}`),y+="&v=1000321",yield fetch(y)}catch(r){return console.error(r),null}})}function mN(e,t){return _t(this,null,function*(){const{from:r,target:n,amount:i,byAmountIn:s,depth:o,splitAlgorithm:a,splitFactor:c,splitCount:u,providers:l,liquidityChanges:f}=t,h=ls(r),y=ls(n),b=`${e}/find_routes`,w=l==null?void 0:l.join(","),T={from:h,target:y,amount:Number(i.toString()),by_amount_in:s,depth:o,split_algorithm:a,split_factor:c,split_count:u,providers:w,liquidity_changes:f.map(P=>({pool:P.poolID,tick_lower:P.ticklower,tick_upper:P.tickUpper,delta_liquidity:P.deltaLiquidity}))};try{return yield fetch(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T)})}catch(P){return console.error("Error:",P),null}})}function gN(e){return _t(this,null,function*(){const t=`${e}/deepbookv3_config`;try{return(yield fetch(t)).json()}catch(r){return console.error("Error:",r),null}})}var B4=(e=>(e[e.Mainnet=0]="Mainnet",e[e.Testnet=1]="Testnet",e))(B4||{}),L4=cN,vN=B4,Eg=MR,Ga=Gs;const F4="0x2::sui::SUI",yN="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI";function U4(e){return Tr(e).full_address===F4}function Cg(e,...t){const r=Array.isArray(t[t.length-1])?t.pop():[];let i=[e,...t].filter(Boolean).join("::");return r&&r.length&&(i+=`<${r.join(", ")}>`),i}function Tr(e){var t;try{let r=e.replace(/\s/g,"");const n=r.match(/(<.+>)$/),i=(t=n==null?void 0:n[0])==null?void 0:t.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);if(i){r=r.slice(0,r.indexOf("<"));const u={...Tr(r),type_arguments:i.map(l=>Tr(l).source_address)};return u.type_arguments=u.type_arguments.map(l=>U4(l)?l:Tr(l).source_address),u.source_address=Cg(u.full_address,u.type_arguments),u}const s=r.split("::"),a={full_address:r,address:r===F4||r===yN?"0x2":Ai(s[0]),module:s[1],name:s[2],type_arguments:[],source_address:""};return a.full_address=`${a.address}::${a.module}::${a.name}`,a.source_address=Cg(a.full_address,a.type_arguments),a}catch{return{full_address:e,address:"",module:"",name:"",type_arguments:[],source_address:e}}}function bN(e){return e.startsWith("0x")?`${e.slice(2)}`:e}const Ni=(e,t=!0)=>{const r=e.split("::"),n=r.shift();let i=Ai(n);return t&&(i=bN(i)),`${i}::${r.join("::")}`};/*!
39
39
  * decimal.js v10.4.3
40
40
  * An arbitrary-precision Decimal type for JavaScript.
41
41
  * https://github.com/MikeMcl/decimal.js