@swapkit/helpers 1.0.0-rc.37 → 1.0.0-rc.39

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.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var Te=Object.create;var D=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var Be=(s,e,t)=>e in s?D(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var Ie=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Se(e))!$e.call(s,n)&&n!==t&&D(s,n,{get:()=>e[n],enumerable:!(r=ve(e,n))||r.enumerable});return s};var Ee=(s,e,t)=>(t=s!=null?Te(Re(s)):{},Ie(e||!s||!s.__esModule?D(t,"default",{value:s,enumerable:!0}):t,s));var p=(s,e,t)=>(Be(s,typeof e!="symbol"?e+"":e,t),t),Me=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var A=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)};var d=(s,e,t)=>(Me(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@swapkit/types"),Oe="0x313ce567",ie=async({chain:s,to:e})=>{try{const{result:t}=await _e.post(i.ChainToRPC[s],{headers:{accept:"*/*","content-type":"application/json","cache-control":"no-cache"},body:JSON.stringify({id:44,jsonrpc:"2.0",method:"eth_call",params:[{to:e.toLowerCase(),data:Oe},"latest"]})});return parseInt(BigInt(t).toString())}catch(t){return console.error(t),i.BaseDecimal[s]}},qe=async s=>{if(s===i.Chain.Ethereum)return i.BaseDecimal.ETH;const[,e]=s.split("-");return e!=null&&e.startsWith("0x")?ie({chain:i.Chain.Ethereum,to:e}):i.BaseDecimal.ETH},xe=async s=>{const[,e]=s.split("-");return e!=null&&e.startsWith("0x")?ie({chain:i.Chain.Avalanche,to:e.toLowerCase()}):i.BaseDecimal.AVAX},Ve=async s=>(s===i.Chain.BinanceSmartChain,i.BaseDecimal.BSC),ae=async({chain:s,symbol:e})=>{switch(s){case i.Chain.Ethereum:return qe(e);case i.Chain.Avalanche:return xe(e);case i.Chain.BinanceSmartChain:return Ve(e);default:return i.BaseDecimal[s]}},Pe={[i.FeeOption.Average]:1.2,[i.FeeOption.Fast]:1.5,[i.FeeOption.Fastest]:2},K=({chain:s,symbol:e})=>{switch(s){case i.Chain.Bitcoin:case i.Chain.BitcoinCash:case i.Chain.Litecoin:case i.Chain.Dogecoin:case i.Chain.Binance:case i.Chain.Ethereum:case i.Chain.Avalanche:return e===s;case i.Chain.Arbitrum:case i.Chain.Optimism:return e==="ETH";case i.Chain.Maya:return e==="CACAO";case i.Chain.Kujira:return e==="KUJI";case i.Chain.Cosmos:return e==="ATOM";case i.Chain.Polygon:return e==="MATIC";case i.Chain.BinanceSmartChain:return e==="BNB";case i.Chain.THORChain:return e==="RUNE"}},oe=s=>{switch(s){case"ETH.THOR":return{identifier:"ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",decimal:18};case"ETH.vTHOR":return{identifier:"ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",decimal:18};case i.Chain.Cosmos:return{identifier:"GAIA.ATOM",decimal:i.BaseDecimal[s]};case i.Chain.THORChain:return{identifier:"THOR.RUNE",decimal:i.BaseDecimal[s]};case i.Chain.BinanceSmartChain:return{identifier:"BSC.BNB",decimal:i.BaseDecimal[s]};case i.Chain.Maya:return{identifier:"MAYA.CACAO",decimal:i.BaseDecimal.MAYA};case"MAYA.MAYA":return{identifier:"MAYA.MAYA",decimal:4};case i.Chain.Kujira:case i.Chain.Arbitrum:case i.Chain.Optimism:case i.Chain.BitcoinCash:case i.Chain.Litecoin:case i.Chain.Dogecoin:case i.Chain.Binance:case i.Chain.Avalanche:case i.Chain.Polygon:case i.Chain.Bitcoin:case i.Chain.Ethereum:return{identifier:`${s}.${s}`,decimal:i.BaseDecimal[s]}}},ce=({chain:s,symbol:e})=>{if(e.includes("/"))return"Synth";switch(s){case i.Chain.Bitcoin:case i.Chain.BitcoinCash:case i.Chain.Dogecoin:case i.Chain.Litecoin:case i.Chain.Maya:case i.Chain.THORChain:return"Native";case i.Chain.Cosmos:return e==="ATOM"?"Native":i.Chain.Cosmos;case i.Chain.Kujira:return e===i.Chain.Kujira?"Native":i.Chain.Kujira;case i.Chain.Binance:return e===i.Chain.Binance?"Native":"BEP2";case i.Chain.BinanceSmartChain:return e===i.Chain.Binance?"Native":"BEP20";case i.Chain.Ethereum:return e===i.Chain.Ethereum?"Native":"ERC20";case i.Chain.Avalanche:return e===i.Chain.Avalanche?"Native":i.Chain.Avalanche;case i.Chain.Polygon:return e===i.Chain.Polygon?"Native":"POLYGON";case i.Chain.Arbitrum:return[i.Chain.Ethereum,i.Chain.Arbitrum].includes(e)?"Native":"ARBITRUM";case i.Chain.Optimism:return[i.Chain.Ethereum,i.Chain.Optimism].includes(e)?"Native":"OPTIMISM"}},ke=s=>{var o;const[e,...t]=s.split("."),r=s.includes("/"),n=t.join("."),a=(o=n==null?void 0:n.split("-"))==null?void 0:o[0];return{chain:e,symbol:n,ticker:a,synth:r}},Ne=new RegExp(/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,"gmi"),De=s=>{const[e,t]=s.split(".");if(!i.EVMChainList.includes(e))return!0;const[,r]=t.split("-");return K({chain:e,symbol:t})||!!r},je=s=>s.filter(e=>{const t=`${e.chain}.${e.symbol}`;return!Ne.test(t)&&De(t)&&e.value!=="0"}),ue=({liquidityUnits:s,poolUnits:e,runeDepth:t})=>{const r=m(s),n=m(e),a=m(t),o=r.mul(a),c=n.mul(n).mul(2),u=n.mul(r).mul(2),h=r.mul(r),l=n.mul(n).mul(n);return o.mul(c.sub(u).add(h)).div(l)},le=({liquidityUnits:s,poolUnits:e,assetDepth:t})=>{const r=m(s),n=m(e),a=m(t),o=r.mul(a),c=n.mul(n).mul(2),u=n.mul(r).mul(2),h=r.mul(r),l=o.mul(c.sub(u).add(h)),g=n.mul(n).mul(n);return l.div(g)},He=({percent:s,runeDepth:e,liquidityUnits:t,poolUnits:r})=>ue({runeDepth:e,liquidityUnits:t,poolUnits:r}).mul(s),Le=({percent:s,assetDepth:e,liquidityUnits:t,poolUnits:r})=>le({assetDepth:e,liquidityUnits:t,poolUnits:r}).mul(s),m=s=>f.fromBigInt(BigInt(s),i.BaseDecimal.THOR),he=({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:r})=>({assetAmount:m(r).mul(s).div(e),runeAmount:m(t).mul(s).div(e)}),Fe=({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:r,percent:n})=>Object.fromEntries(Object.entries(he({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:r})).map(([a,o])=>[a,o.mul(n)])),Ue=({runeDepth:s,poolUnits:e,assetDepth:t,liquidityUnits:r,runeAmount:n,assetAmount:a})=>{const o=new f({value:s,decimal:8}),c=new f({value:t,decimal:8}),u=new f({value:e,decimal:8}),h=new f({value:n,decimal:8}),l=new f({value:a,decimal:8}),g=h.mul(c),w=l.mul(o),k=h.mul(l),be=o.mul(c),Ce=u.mul(g.add(w.add(k.mul(2)))),we=g.add(w.add(be.mul(2))),Q=Ce.div(we),N=m(r).add(Q);if(Q.getBaseValue("number")===0)return N.div(u).getBaseValue("number");const Ae=u.add(N);return N.div(Ae).getBaseValue("number")},We=({runeAmount:s,assetAmount:e,runeDepth:t,assetDepth:r})=>{if(s==="0"||e==="0"||t==="0"||r==="0")return 0;const n=m(t),a=m(r),o=m(e),c=m(s),u=o.mul(n).sub(a.mul(c)),h=a.mul(c).add(n.mul(a));return Math.abs(u.div(h).getBaseValue("number"))},Ge=({symbol:s,ticker:e,chain:t})=>t==="ETH"&&e!=="ETH"?`${e}-${s.slice(-3)}`:s,Ke=(s,e)=>{switch(s){case i.MemoType.LEAVE:case i.MemoType.BOND:{const{address:t}=e;return`${s}:${t}`}case i.MemoType.UNBOND:{const{address:t,unbondAmount:r}=e;return`${s}:${t}:${r*10**8}`}case i.MemoType.THORNAME_REGISTER:{const{name:t,chain:r,address:n,owner:a}=e;return`${s}:${t}:${r}:${n}${a?`:${a}`:""}`}case i.MemoType.DEPOSIT:{const{chain:t,symbol:r,address:n,singleSide:a}=e;return a?`${s}:${t}/${r}::t:0`:`${s}:${t}.${r}:${n||""}:t:0`}case i.MemoType.WITHDRAW:{const{chain:t,ticker:r,symbol:n,basisPoints:a,targetAssetString:o,singleSide:c}=e,u=!c&&o?`:${o}`:"",h=Ge({chain:t,symbol:n,ticker:r});return`${s}:${t}${c?"/":"."}${h}:${a}${u}`}case i.MemoType.OPEN_LOAN:case i.MemoType.CLOSE_LOAN:{const{asset:t,address:r}=e;return`${s}:${t}:${r}`}default:return""}},Ye=s=>{if(s<0)throw new Error("Invalid number of year");return 10+s},ze=s=>{if(s.length>30)return!1;const e=/^[a-zA-Z0-9+_-]+$/g;return!!s.match(e)},Je=([s,e,t,r,n])=>`${s}'/${e}'/${t}'/${r}${typeof n!="number"?"":`/${n}`}`;class X extends Error{constructor(e,t,r){const n=e.status||e.status===0?e.status:"",a=e.statusText||"",o=`${n} ${a}`.trim(),c=o?`status code ${o}`:"an unknown error";super(`Request failed with ${c}`),Object.defineProperty(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="HTTPError",this.response=e,this.request=t,this.options=r}}class de extends Error{constructor(e){super("Request timed out"),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="TimeoutError",this.request=e}}const q=s=>s!==null&&typeof s=="object",M=(...s)=>{for(const e of s)if((!q(e)||Array.isArray(e))&&e!==void 0)throw new TypeError("The `options` argument must be an object");return Y({},...s)},me=(s={},e={})=>{const t=new globalThis.Headers(s),r=e instanceof globalThis.Headers,n=new globalThis.Headers(e);for(const[a,o]of n.entries())r&&o==="undefined"||o===void 0?t.delete(a):t.set(a,o);return t},Y=(...s)=>{let e={},t={};for(const r of s)if(Array.isArray(r))Array.isArray(e)||(e=[]),e=[...e,...r];else if(q(r)){for(let[n,a]of Object.entries(r))q(a)&&n in e&&(a=Y(e[n],a)),e={...e,[n]:a};q(r.headers)&&(t=me(t,r.headers),e.headers=t)}return e},Qe=(()=>{let s=!1,e=!1;const t=typeof globalThis.ReadableStream=="function",r=typeof globalThis.Request=="function";return t&&r&&(e=new globalThis.Request("https://empty.invalid",{body:new globalThis.ReadableStream,method:"POST",get duplex(){return s=!0,"half"}}).headers.has("Content-Type")),s&&!e})(),Xe=typeof globalThis.AbortController=="function",Ze=typeof globalThis.ReadableStream=="function",et=typeof globalThis.FormData=="function",pe=["get","post","put","patch","head","delete"],tt={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},j=2147483647,fe=Symbol("stop"),st={json:!0,parseJson:!0,searchParams:!0,prefixUrl:!0,retry:!0,timeout:!0,hooks:!0,throwHttpErrors:!0,onDownloadProgress:!0,fetch:!0},rt={method:!0,headers:!0,body:!0,mode:!0,credentials:!0,cache:!0,redirect:!0,referrer:!0,referrerPolicy:!0,integrity:!0,keepalive:!0,signal:!0,window:!0,dispatcher:!0,duplex:!0},nt=s=>pe.includes(s)?s.toUpperCase():s,it=["get","put","head","delete","options","trace"],at=[408,413,429,500,502,503,504],ge=[413,429,503],Z={limit:2,methods:it,statusCodes:at,afterStatusCodes:ge,maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY,delay:s=>.3*2**(s-1)*1e3},ot=(s={})=>{if(typeof s=="number")return{...Z,limit:s};if(s.methods&&!Array.isArray(s.methods))throw new Error("retry.methods must be an array");if(s.statusCodes&&!Array.isArray(s.statusCodes))throw new Error("retry.statusCodes must be an array");return{...Z,...s,afterStatusCodes:ge}};async function ct(s,e,t,r){return new Promise((n,a)=>{const o=setTimeout(()=>{t&&t.abort(),a(new de(s))},r.timeout);r.fetch(s,e).then(n).catch(a).then(()=>{clearTimeout(o)})})}async function ut(s,{signal:e}){return new Promise((t,r)=>{e&&(e.throwIfAborted(),e.addEventListener("abort",n,{once:!0}));function n(){clearTimeout(a),r(e.reason)}const a=setTimeout(()=>{e==null||e.removeEventListener("abort",n),t()},s)})}const lt=(s,e)=>{const t={};for(const r in e)!(r in rt)&&!(r in st)&&!(r in s)&&(t[r]=e[r]);return t};class V{static create(e,t){const r=new V(e,t),n=async()=>{if(typeof r._options.timeout=="number"&&r._options.timeout>j)throw new RangeError(`The \`timeout\` option cannot be greater than ${j}`);await Promise.resolve();let c=await r._fetch();for(const u of r._options.hooks.afterResponse){const h=await u(r.request,r._options,r._decorateResponse(c.clone()));h instanceof globalThis.Response&&(c=h)}if(r._decorateResponse(c),!c.ok&&r._options.throwHttpErrors){let u=new X(c,r.request,r._options);for(const h of r._options.hooks.beforeError)u=await h(u);throw u}if(r._options.onDownloadProgress){if(typeof r._options.onDownloadProgress!="function")throw new TypeError("The `onDownloadProgress` option must be a function");if(!Ze)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return r._stream(c.clone(),r._options.onDownloadProgress)}return c},o=r._options.retry.methods.includes(r.request.method.toLowerCase())?r._retry(n):n();for(const[c,u]of Object.entries(tt))o[c]=async()=>{r.request.headers.set("accept",r.request.headers.get("accept")||u);const l=(await o).clone();if(c==="json"){if(l.status===204||(await l.clone().arrayBuffer()).byteLength===0)return"";if(t.parseJson)return t.parseJson(await l.text())}return l[c]()};return o}constructor(e,t={}){if(Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"abortController",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_input",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._input=e,this._options={credentials:this._input.credentials||"same-origin",...t,headers:me(this._input.headers,t.headers),hooks:Y({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},t.hooks),method:nt(t.method??this._input.method),prefixUrl:String(t.prefixUrl||""),retry:ot(t.retry),throwHttpErrors:t.throwHttpErrors!==!1,timeout:t.timeout??1e4,fetch:t.fetch??globalThis.fetch.bind(globalThis)},typeof this._input!="string"&&!(this._input instanceof URL||this._input instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this._options.prefixUrl&&typeof this._input=="string"){if(this._input.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this._options.prefixUrl.endsWith("/")||(this._options.prefixUrl+="/"),this._input=this._options.prefixUrl+this._input}if(Xe){if(this.abortController=new globalThis.AbortController,this._options.signal){const r=this._options.signal;this._options.signal.addEventListener("abort",()=>{this.abortController.abort(r.reason)})}this._options.signal=this.abortController.signal}if(Qe&&(this._options.duplex="half"),this.request=new globalThis.Request(this._input,this._options),this._options.searchParams){const n="?"+(typeof this._options.searchParams=="string"?this._options.searchParams.replace(/^\?/,""):new URLSearchParams(this._options.searchParams).toString()),a=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,n);(et&&this._options.body instanceof globalThis.FormData||this._options.body instanceof URLSearchParams)&&!(this._options.headers&&this._options.headers["content-type"])&&this.request.headers.delete("content-type"),this.request=new globalThis.Request(new globalThis.Request(a,{...this.request}),this._options)}this._options.json!==void 0&&(this._options.body=JSON.stringify(this._options.json),this.request.headers.set("content-type",this._options.headers.get("content-type")??"application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}))}_calculateRetryDelay(e){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(e instanceof de)){if(e instanceof X){if(!this._options.retry.statusCodes.includes(e.response.status))return 0;const r=e.response.headers.get("Retry-After");if(r&&this._options.retry.afterStatusCodes.includes(e.response.status)){let n=Number(r);return Number.isNaN(n)?n=Date.parse(r)-Date.now():n*=1e3,this._options.retry.maxRetryAfter!==void 0&&n>this._options.retry.maxRetryAfter?0:n}if(e.response.status===413)return 0}const t=this._options.retry.delay(this._retryCount);return Math.min(this._options.retry.backoffLimit,t)}return 0}_decorateResponse(e){return this._options.parseJson&&(e.json=async()=>this._options.parseJson(await e.text())),e}async _retry(e){try{return await e()}catch(t){const r=Math.min(this._calculateRetryDelay(t),j);if(r!==0&&this._retryCount>0){await ut(r,{signal:this._options.signal});for(const n of this._options.hooks.beforeRetry)if(await n({request:this.request,options:this._options,error:t,retryCount:this._retryCount})===fe)return;return this._retry(e)}throw t}}async _fetch(){for(const t of this._options.hooks.beforeRequest){const r=await t(this.request,this._options);if(r instanceof Request){this.request=r;break}if(r instanceof Response)return r}const e=lt(this.request,this._options);return this._options.timeout===!1?this._options.fetch(this.request.clone(),e):ct(this.request.clone(),e,this.abortController,this._options)}_stream(e,t){const r=Number(e.headers.get("content-length"))||0;let n=0;return e.status===204?(t&&t({percent:1,totalBytes:r,transferredBytes:n},new Uint8Array),new globalThis.Response(null,{status:e.status,statusText:e.statusText,headers:e.headers})):new globalThis.Response(new globalThis.ReadableStream({async start(a){const o=e.body.getReader();t&&t({percent:0,transferredBytes:0,totalBytes:r},new Uint8Array);async function c(){const{done:u,value:h}=await o.read();if(u){a.close();return}if(t){n+=h.byteLength;const l=r===0?0:n/r;t({percent:l,transferredBytes:n,totalBytes:r},h)}a.enqueue(h),await c()}await c()}}),{status:e.status,statusText:e.statusText,headers:e.headers})}}/*! MIT License © Sindre Sorhus */const H=s=>{const e=(t,r)=>V.create(t,M(s,r));for(const t of pe)e[t]=(r,n)=>V.create(r,M(s,n,{method:t}));return e.create=t=>H(M(t)),e.extend=t=>H(M(s,t)),e.stop=fe,e},ht=H(),dt=ht,mt=typeof window<"u"?{}:{referrer:"https://sk.thorswap.net",referer:"https://sk.thorswap.net"},ee=dt.create({headers:mt}),_e={get:(s,e)=>ee.get(s,e).json(),post:(s,e)=>ee.post(s,e).json()},te=Object.values(i.Chain),pt=(s="")=>{const e=s.toUpperCase(),[t]=e.split(".");if(te.includes(t))return!0;const[r]=e.split("/");if(te.includes(r))return!0;throw new Error(`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`)},$=8,b=s=>10n**BigInt(s),S=s=>Math.log10(parseFloat(s.toString()));function B({value:s,bigIntDecimal:e=$,decimal:t=$}){const r=s<0n;let n=s.toString().substring(r?1:0);const a=t-(n.length-1);a>0&&(n="0".repeat(a)+n);const o=n.length-t;let c=n.slice(-t);return parseInt(c[e])>=5?c=`${c.substring(0,e-1)}${(parseInt(c[e-1])+1).toString()}`:c=c.substring(0,e),`${r?"-":""}${n.slice(0,o)}.${c}`.replace(/\.?0*$/,"")}var C,R,_,T,P,ye,I,L,E,F;const J=class J{constructor(e){A(this,C);A(this,_);A(this,P);A(this,I);A(this,E);p(this,"decimalMultiplier",10n**8n);p(this,"bigIntValue",0n);p(this,"decimal");const t=U(e),r=typeof e=="object";this.decimal=r?e.decimal:void 0,this.decimalMultiplier=r&&"decimalMultiplier"in e?e.decimalMultiplier:b(Math.max(se(O(t)),this.decimal||0)),d(this,P,ye).call(this,t)}static fromBigInt(e,t){return new J({decimal:t,value:B({value:e,bigIntDecimal:t,decimal:t})})}static shiftDecimals({value:e,from:t,to:r}){return this.fromBigInt(e.getBaseValue("bigint")*b(r)/b(t),r)}set(e){return new this.constructor({decimal:this.decimal,value:e,identifier:this.toString()})}add(...e){return d(this,C,R).call(this,"add",...e)}sub(...e){return d(this,C,R).call(this,"sub",...e)}mul(...e){return d(this,C,R).call(this,"mul",...e)}div(...e){return d(this,C,R).call(this,"div",...e)}gt(e){return d(this,_,T).call(this,"gt",e)}gte(e){return d(this,_,T).call(this,"gte",e)}lt(e){return d(this,_,T).call(this,"lt",e)}lte(e){return d(this,_,T).call(this,"lte",e)}eqValue(e){return d(this,_,T).call(this,"eqValue",e)}getValue(e){const t=this.formatBigIntToSafeValue(this.bigIntValue,this.decimal||S(this.decimalMultiplier));switch(e){case"number":return Number(t);case"string":return t;case"bigint":return this.bigIntValue*10n**BigInt(this.decimal||8n)/this.decimalMultiplier}}getBaseValue(e){const t=this.decimalMultiplier/b(this.decimal||i.BaseDecimal.THOR),r=this.bigIntValue/t;switch(e){case"number":return Number(r);case"string":return r.toString();case"bigint":return r}}getBigIntValue(e,t){if(!t&&typeof e=="object")return e.bigIntValue;const r=U(e),n=O(r);return n==="0"||n==="undefined"?0n:d(this,E,F).call(this,n,t)}toSignificant(e=6){const[t,r]=this.getValue("string").split("."),n=t||"",a=r||"";if((parseInt(n)?n.length+a.length:a.length)<=e)return this.getValue("string");if(n.length>=e)return n.slice(0,e).padEnd(n.length,"0");if(parseInt(n))return`${n}.${a.slice(0,e-n.length)}`.padEnd(e-n.length,"0");const c=parseInt(a),u=`${c}`.slice(0,e);return`0.${u.padStart(a.length-`${c}`.length+u.length,"0")}`}toFixed(e=6){const[t,r]=this.getValue("string").split("."),n=t||"",a=r||"";if(parseInt(n))return`${n}.${a.slice(0,e)}`.padEnd(e,"0");const o=parseInt(a),c=`${o}`.slice(0,e);return`0.${c.padStart(a.length-`${o}`.length+c.length,"0")}`}toAbbreviation(e=2){const t=this.getValue("number"),r=["","K","M","B","T","Q","Qi","S"],n=Math.floor(Math.log10(Math.abs(t))/3),a=r[n];if(!a)return this.getValue("string");const o=10**(n*3);return`${(t/o).toFixed(e)}${a}`}toCurrency(e="$",{currencyPosition:t="start",decimal:r=2,decimalSeparator:n=".",thousandSeparator:a=","}={}){const o=this.getValue("number"),[c,u=""]=o.toFixed(6).split("."),h=c.replace(/\B(?=(\d{3})+(?!\d))/g,a),l=!c&&!u?"0.00":c==="0"?`${parseFloat(`0.${u}`)}`.replace(".",n):`${h}${parseInt(u)?`${n}${u.slice(0,r)}`:""}`;return`${t==="start"?e:""}${l}${t==="end"?e:""}`}formatBigIntToSafeValue(e,t){const r=t||this.decimal||$,n=Math.max(r,S(this.decimalMultiplier)),a=e<0n,o=e.toString().substring(a?1:0),c=n-(o.length-1),u=c>0?"0".repeat(c)+o:o,h=u.length-n;let l=u.slice(-n);return parseInt(l[r])>=5?l=`${l.substring(0,r-1)}${(parseInt(l[r-1])+1).toString()}`:l=l.substring(0,r),`${a?"-":""}${u.slice(0,h)}.${l}`.replace(/\.?0*$/,"")}};C=new WeakSet,R=function(e,...t){const r=d(this,I,L).call(this,this,...t),n=Math.max(r,S(this.decimalMultiplier)),a=b(n),o=t.reduce((u,h)=>{const l=this.getBigIntValue(h,n);switch(e){case"add":return u+l;case"sub":return u-l;case"mul":return u*l/a;case"div":{if(l===0n)throw new RangeError("Division by zero");return u*a/l}default:return u}},this.bigIntValue*a/this.decimalMultiplier),c=B({bigIntDecimal:n,decimal:n,value:o});return new this.constructor({decimalMultiplier:b(n),decimal:this.decimal,value:c,identifier:this.toString()})},_=new WeakSet,T=function(e,...t){const r=d(this,I,L).call(this,this,...t),n=this.getBigIntValue(t[0],r),a=this.getBigIntValue(this,r);switch(e){case"gt":return a>n;case"gte":return a>=n;case"lt":return a<n;case"lte":return a<=n;case"eqValue":return a===n}},P=new WeakSet,ye=function(e){const t=O(e)||"0";this.bigIntValue=d(this,E,F).call(this,t)},I=new WeakSet,L=function(...e){const t=e.map(r=>typeof r=="object"?r.decimal||S(r.decimalMultiplier):se(O(r))).filter(Boolean);return Math.max(...t,$)},E=new WeakSet,F=function(e,t){const r=t?b(t):this.decimalMultiplier,n=S(r),[a="",o=""]=e.split(".");return BigInt(`${a}${o.padEnd(n,"0")}`)};let v=J;const ft=Intl.NumberFormat("fullwide",{useGrouping:!1,maximumFractionDigits:20});function O(s){const t=`${typeof s=="number"?ft.format(s):U(s)}`.replaceAll(",",".").split(".");return t.length>1?`${t.slice(0,-1).join("")}.${t.at(-1)}`:t[0]}function se(s){var t;const e=((t=s.split(".")[1])==null?void 0:t.length)||0;return Math.max(e,$)}function U(s){return typeof s=="object"?"getValue"in s?s.getValue("string"):s.value:s}const x=(s,e)=>typeof s=="bigint"?B({value:s,bigIntDecimal:e,decimal:e}):s;let W;const re=s=>{if(!W)throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");return W.get(s.toUpperCase())||{decimal:i.BaseDecimal.THOR,identifier:""}},ne=async(s,e=0)=>{pt(s);const t=await ae(G(s)),r=x(e,t);return new y({decimal:t,value:r,identifier:s})};class y extends v{constructor(t){const r="identifier"in t?t.identifier:`${t.chain}.${t.symbol}`;super(t.value instanceof v?t.value:{decimal:t.decimal,value:t.value});p(this,"address");p(this,"chain");p(this,"isGasAsset",!1);p(this,"isSynthetic",!1);p(this,"symbol");p(this,"tax");p(this,"ticker");p(this,"type");const n=G(r);this.type=ce(n),this.chain=n.chain,this.ticker=n.ticker,this.symbol=n.symbol,this.address=n.address,this.isSynthetic=n.isSynthetic,this.isGasAsset=n.isGasAsset,this.tax=t.tax}toString(t=!1){const r=this.isSynthetic?this.symbol.split("-")[0]:this.ticker;return t?r:`${this.chain}.${this.symbol}`}eq({chain:t,symbol:r}){return this.chain===t&&this.symbol===r}static async fromString(t,r=0){return ne(t,r)}static fromStringSync(t,r=0){const{isSynthetic:n}=G(t),{tax:a,decimal:o,identifier:c}=re(t),u=x(r,o);return c?new y({tax:a,decimal:o,identifier:c,value:u}):n?new y({tax:a,decimal:8,identifier:t,value:u}):void 0}static async fromIdentifier(t,r=0){return ne(t,r)}static fromIdentifierSync(t,r=0){const{decimal:n,identifier:a}=re(t),o=x(r,n);return new y({decimal:n,identifier:a,value:o})}static fromChainOrSignature(t,r=0){const{decimal:n,identifier:a}=oe(t),o=x(r,n);return new y({value:o,decimal:n,identifier:a})}static async loadStaticAssets(){return new Promise(async(t,r)=>{try{const{ThorchainList:n,NativeList:a,...o}=await import("@swapkit/tokens");W=[a,...Object.values(o)].reduce((u,{tokens:h})=>(h.forEach(({identifier:l,chain:g,...w})=>{const k="decimals"in w?w.decimals:i.BaseDecimal[g];u.set(l,{identifier:l,decimal:k})}),u),new Map),t({ok:!0})}catch(n){console.error(n),r({ok:!1,error:n,message:"Couldn't load static assets. Ensure you have installed @swapkit/tokens package"})}})}}const gt=s=>{const e=y.fromChainOrSignature(s);switch(s){case i.Chain.Bitcoin:case i.Chain.Litecoin:case i.Chain.BitcoinCash:return e.set(10001e-8);case i.Chain.Dogecoin:return e.set(1.00000001);case i.Chain.Avalanche:case i.Chain.Ethereum:return e.set(1e-8);case i.Chain.THORChain:case i.Chain.Maya:return e.set(0);default:return e.set(1e-8)}},G=s=>{const e=s.slice(0,14).includes("/"),[t,r]=s.split(".").pop().split("/"),n=s.includes(".")&&!e?s:`${i.Chain.THORChain}.${r}`,[a,o]=n.split("."),[c,u]=(e?r:o).split("-");return{address:u==null?void 0:u.toLowerCase(),chain:a,isGasAsset:K({chain:a,symbol:o}),isSynthetic:e,symbol:(e?`${t}/`:"")+(u?`${c}-${(u==null?void 0:u.toLowerCase())??""}`:o),ticker:c}},_t={core_wallet_connection_not_found:10001,core_estimated_max_spendable_chain_not_supported:10002,core_extend_error:10003,core_inbound_data_not_found:10004,core_approve_asset_address_or_from_not_found:10005,core_chain_halted:10099,core_wallet_xdefi_not_installed:10101,core_wallet_evmwallet_not_installed:10102,core_wallet_walletconnect_not_installed:10103,core_wallet_keystore_not_installed:10104,core_wallet_ledger_not_installed:10105,core_wallet_trezor_not_installed:10106,core_wallet_keplr_not_installed:10107,core_wallet_okx_not_installed:10108,core_swap_invalid_params:10200,core_swap_route_not_complete:10201,core_swap_asset_not_recognized:10202,core_swap_contract_not_found:10203,core_swap_route_transaction_not_found:10204,core_swap_contract_not_supported:10205,core_swap_transaction_error:10206,core_swap_quote_mode_not_supported:10207,core_transaction_deposit_error:10301,core_transaction_create_liquidity_rune_error:10302,core_transaction_create_liquidity_asset_error:10303,core_transaction_create_liquidity_invalid_params:10304,core_transaction_add_liquidity_invalid_params:10305,core_transaction_add_liquidity_no_rune_address:10306,core_transaction_add_liquidity_rune_error:10307,core_transaction_add_liquidity_asset_error:10308,core_transaction_withdraw_error:10309,core_transaction_deposit_to_pool_error:10310,core_transaction_deposit_insufficient_funds_error:10311,core_transaction_deposit_gas_error:10312,core_transaction_deposit_server_error:10313,wallet_ledger_connection_error:20001,helpers_number_different_decimals:99101};class z extends Error{constructor(e,t){console.error(t),super(e,{cause:{code:_t[e],message:e}}),Object.setPrototypeOf(this,z.prototype)}}class f extends v{eq(e){return this.eqValue(e)}static fromBigInt(e,t){return new f({decimal:t,value:B({value:e,bigIntDecimal:t,decimal:t})})}}exports.AssetValue=y;exports.BigIntArithmetics=v;exports.RequestClient=_e;exports.SwapKitError=z;exports.SwapKitNumber=f;exports.assetFromString=ke;exports.derivationPathToString=Je;exports.filterAssets=je;exports.formatBigIntToSafeValue=B;exports.gasFeeMultiplier=Pe;exports.getAssetType=ce;exports.getAsymmetricAssetShare=le;exports.getAsymmetricAssetWithdrawAmount=Le;exports.getAsymmetricRuneShare=ue;exports.getAsymmetricRuneWithdrawAmount=He;exports.getCommonAssetInfo=oe;exports.getDecimal=ae;exports.getEstimatedPoolShare=Ue;exports.getLiquiditySlippage=We;exports.getMemoFor=Ke;exports.getMinAmountByChain=gt;exports.getSymmetricPoolShare=he;exports.getSymmetricWithdraw=Fe;exports.getTHORNameCost=Ye;exports.isGasAsset=K;exports.validateTHORName=ze;
1
+ "use strict";var Te=Object.create;var D=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var Be=(s,e,t)=>e in s?D(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var Ie=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Se(e))!$e.call(s,r)&&r!==t&&D(s,r,{get:()=>e[r],enumerable:!(n=ve(e,r))||n.enumerable});return s};var Me=(s,e,t)=>(t=s!=null?Te(Re(s)):{},Ie(e||!s||!s.__esModule?D(t,"default",{value:s,enumerable:!0}):t,s));var p=(s,e,t)=>(Be(s,typeof e!="symbol"?e+"":e,t),t),Oe=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var A=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)};var d=(s,e,t)=>(Oe(s,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@swapkit/types"),Ee="0x313ce567",ie=async({chain:s,to:e})=>{try{const{result:t}=await _e.post(i.ChainToRPC[s],{headers:{accept:"*/*","content-type":"application/json","cache-control":"no-cache"},body:JSON.stringify({id:44,jsonrpc:"2.0",method:"eth_call",params:[{to:e.toLowerCase(),data:Ee},"latest"]})});return parseInt(BigInt(t).toString())}catch(t){return console.error(t),i.BaseDecimal[s]}},qe=async s=>{if(s===i.Chain.Ethereum)return i.BaseDecimal.ETH;const[,e]=s.split("-");return e!=null&&e.startsWith("0x")?ie({chain:i.Chain.Ethereum,to:e}):i.BaseDecimal.ETH},xe=async s=>{const[,e]=s.split("-");return e!=null&&e.startsWith("0x")?ie({chain:i.Chain.Avalanche,to:e.toLowerCase()}):i.BaseDecimal.AVAX},Ve=async s=>(s===i.Chain.BinanceSmartChain,i.BaseDecimal.BSC),ae=async({chain:s,symbol:e})=>{switch(s){case i.Chain.Ethereum:return qe(e);case i.Chain.Avalanche:return xe(e);case i.Chain.BinanceSmartChain:return Ve(e);default:return i.BaseDecimal[s]}},ke={[i.FeeOption.Average]:1.2,[i.FeeOption.Fast]:1.5,[i.FeeOption.Fastest]:2},K=({chain:s,symbol:e})=>{switch(s){case i.Chain.Bitcoin:case i.Chain.BitcoinCash:case i.Chain.Litecoin:case i.Chain.Dogecoin:case i.Chain.Binance:case i.Chain.Ethereum:case i.Chain.Avalanche:return e===s;case i.Chain.Arbitrum:case i.Chain.Optimism:return e==="ETH";case i.Chain.Maya:return e==="CACAO";case i.Chain.Kujira:return e==="KUJI";case i.Chain.Cosmos:return e==="ATOM";case i.Chain.Polygon:return e==="MATIC";case i.Chain.BinanceSmartChain:return e==="BNB";case i.Chain.THORChain:return e==="RUNE"}},oe=s=>{switch(s){case"ETH.THOR":return{identifier:"ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",decimal:18};case"ETH.vTHOR":return{identifier:"ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",decimal:18};case i.Chain.Cosmos:return{identifier:"GAIA.ATOM",decimal:i.BaseDecimal[s]};case i.Chain.THORChain:return{identifier:"THOR.RUNE",decimal:i.BaseDecimal[s]};case i.Chain.BinanceSmartChain:return{identifier:"BSC.BNB",decimal:i.BaseDecimal[s]};case i.Chain.Maya:return{identifier:"MAYA.CACAO",decimal:i.BaseDecimal.MAYA};case"MAYA.MAYA":return{identifier:"MAYA.MAYA",decimal:4};case i.Chain.Kujira:case i.Chain.Arbitrum:case i.Chain.Optimism:case i.Chain.BitcoinCash:case i.Chain.Litecoin:case i.Chain.Dogecoin:case i.Chain.Binance:case i.Chain.Avalanche:case i.Chain.Polygon:case i.Chain.Bitcoin:case i.Chain.Ethereum:return{identifier:`${s}.${s}`,decimal:i.BaseDecimal[s]}}},ce=({chain:s,symbol:e})=>{if(e.includes("/"))return"Synth";switch(s){case i.Chain.Bitcoin:case i.Chain.BitcoinCash:case i.Chain.Dogecoin:case i.Chain.Litecoin:case i.Chain.Maya:case i.Chain.THORChain:return"Native";case i.Chain.Cosmos:return e==="ATOM"?"Native":i.Chain.Cosmos;case i.Chain.Kujira:return e===i.Chain.Kujira?"Native":i.Chain.Kujira;case i.Chain.Binance:return e===i.Chain.Binance?"Native":"BEP2";case i.Chain.BinanceSmartChain:return e===i.Chain.Binance?"Native":"BEP20";case i.Chain.Ethereum:return e===i.Chain.Ethereum?"Native":"ERC20";case i.Chain.Avalanche:return e===i.Chain.Avalanche?"Native":i.Chain.Avalanche;case i.Chain.Polygon:return e===i.Chain.Polygon?"Native":"POLYGON";case i.Chain.Arbitrum:return[i.Chain.Ethereum,i.Chain.Arbitrum].includes(e)?"Native":"ARBITRUM";case i.Chain.Optimism:return[i.Chain.Ethereum,i.Chain.Optimism].includes(e)?"Native":"OPTIMISM"}},Pe=s=>{var o;const[e,...t]=s.split("."),n=s.includes("/"),r=t.join("."),a=(o=r==null?void 0:r.split("-"))==null?void 0:o[0];return{chain:e,symbol:r,ticker:a,synth:n}},Ne=new RegExp(/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,"gmi"),De=s=>{const[e,t]=s.split(".");if(!i.EVMChainList.includes(e))return!0;const[,n]=t.split("-");return K({chain:e,symbol:t})||!!n},je=s=>s.filter(e=>{const t=`${e.chain}.${e.symbol}`;return!Ne.test(t)&&De(t)&&e.value!=="0"}),ue=({liquidityUnits:s,poolUnits:e,runeDepth:t})=>{const n=m(s),r=m(e),a=m(t),o=n.mul(a),c=r.mul(r).mul(2),u=r.mul(n).mul(2),h=n.mul(n),l=r.mul(r).mul(r);return o.mul(c.sub(u).add(h)).div(l)},le=({liquidityUnits:s,poolUnits:e,assetDepth:t})=>{const n=m(s),r=m(e),a=m(t),o=n.mul(a),c=r.mul(r).mul(2),u=r.mul(n).mul(2),h=n.mul(n),l=o.mul(c.sub(u).add(h)),g=r.mul(r).mul(r);return l.div(g)},He=({percent:s,runeDepth:e,liquidityUnits:t,poolUnits:n})=>ue({runeDepth:e,liquidityUnits:t,poolUnits:n}).mul(s),Le=({percent:s,assetDepth:e,liquidityUnits:t,poolUnits:n})=>le({assetDepth:e,liquidityUnits:t,poolUnits:n}).mul(s),m=s=>f.fromBigInt(BigInt(s),i.BaseDecimal.THOR),he=({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:n})=>({assetAmount:m(n).mul(s).div(e),runeAmount:m(t).mul(s).div(e)}),Fe=({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:n,percent:r})=>Object.fromEntries(Object.entries(he({liquidityUnits:s,poolUnits:e,runeDepth:t,assetDepth:n})).map(([a,o])=>[a,o.mul(r)])),Ue=({runeDepth:s,poolUnits:e,assetDepth:t,liquidityUnits:n,runeAmount:r,assetAmount:a})=>{const o=new f({value:s,decimal:8}),c=new f({value:t,decimal:8}),u=new f({value:e,decimal:8}),h=new f({value:r,decimal:8}),l=new f({value:a,decimal:8}),g=h.mul(c),w=l.mul(o),P=h.mul(l),be=o.mul(c),Ce=u.mul(g.add(w.add(P.mul(2)))),we=g.add(w.add(be.mul(2))),Q=Ce.div(we),N=m(n).add(Q);if(Q.getBaseValue("number")===0)return N.div(u).getBaseValue("number");const Ae=u.add(N);return N.div(Ae).getBaseValue("number")},We=({runeAmount:s,assetAmount:e,runeDepth:t,assetDepth:n})=>{if(s==="0"||e==="0"||t==="0"||n==="0")return 0;const r=m(t),a=m(n),o=m(e),c=m(s),u=o.mul(r).sub(a.mul(c)),h=a.mul(c).add(r.mul(a));return Math.abs(u.div(h).getBaseValue("number"))},Ge=({symbol:s,ticker:e,chain:t})=>t==="ETH"&&e!=="ETH"?`${e}-${s.slice(-3)}`:s,Ke=(s,e)=>{switch(s){case i.MemoType.LEAVE:case i.MemoType.BOND:{const{address:t}=e;return`${s}:${t}`}case i.MemoType.UNBOND:{const{address:t,unbondAmount:n}=e;return`${s}:${t}:${n*10**8}`}case i.MemoType.THORNAME_REGISTER:{const{name:t,chain:n,address:r,owner:a}=e;return`${s}:${t}:${n}:${r}${a?`:${a}`:""}`}case i.MemoType.DEPOSIT:{const{chain:t,symbol:n,address:r,singleSide:a}=e;return a?`${s}:${t}/${n}::t:0`:`${s}:${t}.${n}:${r||""}:t:0`}case i.MemoType.WITHDRAW:{const{chain:t,ticker:n,symbol:r,basisPoints:a,targetAssetString:o,singleSide:c}=e,u=!c&&o?`:${o}`:"",h=Ge({chain:t,symbol:r,ticker:n});return`${s}:${t}${c?"/":"."}${h}:${a}${u}`}case i.MemoType.OPEN_LOAN:case i.MemoType.CLOSE_LOAN:{const{asset:t,address:n}=e;return`${s}:${t}:${n}`}default:return""}},Ye=s=>{if(s<0)throw new Error("Invalid number of year");return 10+s},ze=s=>{if(s.length>30)return!1;const e=/^[a-zA-Z0-9+_-]+$/g;return!!s.match(e)},Je=([s,e,t,n,r])=>`${s}'/${e}'/${t}'/${n}${typeof r!="number"?"":`/${r}`}`;class X extends Error{constructor(e,t,n){const r=e.status||e.status===0?e.status:"",a=e.statusText||"",o=`${r} ${a}`.trim(),c=o?`status code ${o}`:"an unknown error";super(`Request failed with ${c}`),Object.defineProperty(this,"response",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="HTTPError",this.response=e,this.request=t,this.options=n}}class de extends Error{constructor(e){super("Request timed out"),Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name="TimeoutError",this.request=e}}const q=s=>s!==null&&typeof s=="object",O=(...s)=>{for(const e of s)if((!q(e)||Array.isArray(e))&&e!==void 0)throw new TypeError("The `options` argument must be an object");return Y({},...s)},me=(s={},e={})=>{const t=new globalThis.Headers(s),n=e instanceof globalThis.Headers,r=new globalThis.Headers(e);for(const[a,o]of r.entries())n&&o==="undefined"||o===void 0?t.delete(a):t.set(a,o);return t},Y=(...s)=>{let e={},t={};for(const n of s)if(Array.isArray(n))Array.isArray(e)||(e=[]),e=[...e,...n];else if(q(n)){for(let[r,a]of Object.entries(n))q(a)&&r in e&&(a=Y(e[r],a)),e={...e,[r]:a};q(n.headers)&&(t=me(t,n.headers),e.headers=t)}return e},Qe=(()=>{let s=!1,e=!1;const t=typeof globalThis.ReadableStream=="function",n=typeof globalThis.Request=="function";return t&&n&&(e=new globalThis.Request("https://empty.invalid",{body:new globalThis.ReadableStream,method:"POST",get duplex(){return s=!0,"half"}}).headers.has("Content-Type")),s&&!e})(),Xe=typeof globalThis.AbortController=="function",Ze=typeof globalThis.ReadableStream=="function",et=typeof globalThis.FormData=="function",pe=["get","post","put","patch","head","delete"],tt={json:"application/json",text:"text/*",formData:"multipart/form-data",arrayBuffer:"*/*",blob:"*/*"},j=2147483647,fe=Symbol("stop"),st={json:!0,parseJson:!0,searchParams:!0,prefixUrl:!0,retry:!0,timeout:!0,hooks:!0,throwHttpErrors:!0,onDownloadProgress:!0,fetch:!0},nt={method:!0,headers:!0,body:!0,mode:!0,credentials:!0,cache:!0,redirect:!0,referrer:!0,referrerPolicy:!0,integrity:!0,keepalive:!0,signal:!0,window:!0,dispatcher:!0,duplex:!0},rt=s=>pe.includes(s)?s.toUpperCase():s,it=["get","put","head","delete","options","trace"],at=[408,413,429,500,502,503,504],ge=[413,429,503],Z={limit:2,methods:it,statusCodes:at,afterStatusCodes:ge,maxRetryAfter:Number.POSITIVE_INFINITY,backoffLimit:Number.POSITIVE_INFINITY,delay:s=>.3*2**(s-1)*1e3},ot=(s={})=>{if(typeof s=="number")return{...Z,limit:s};if(s.methods&&!Array.isArray(s.methods))throw new Error("retry.methods must be an array");if(s.statusCodes&&!Array.isArray(s.statusCodes))throw new Error("retry.statusCodes must be an array");return{...Z,...s,afterStatusCodes:ge}};async function ct(s,e,t,n){return new Promise((r,a)=>{const o=setTimeout(()=>{t&&t.abort(),a(new de(s))},n.timeout);n.fetch(s,e).then(r).catch(a).then(()=>{clearTimeout(o)})})}async function ut(s,{signal:e}){return new Promise((t,n)=>{e&&(e.throwIfAborted(),e.addEventListener("abort",r,{once:!0}));function r(){clearTimeout(a),n(e.reason)}const a=setTimeout(()=>{e==null||e.removeEventListener("abort",r),t()},s)})}const lt=(s,e)=>{const t={};for(const n in e)!(n in nt)&&!(n in st)&&!(n in s)&&(t[n]=e[n]);return t};class V{static create(e,t){const n=new V(e,t),r=async()=>{if(typeof n._options.timeout=="number"&&n._options.timeout>j)throw new RangeError(`The \`timeout\` option cannot be greater than ${j}`);await Promise.resolve();let c=await n._fetch();for(const u of n._options.hooks.afterResponse){const h=await u(n.request,n._options,n._decorateResponse(c.clone()));h instanceof globalThis.Response&&(c=h)}if(n._decorateResponse(c),!c.ok&&n._options.throwHttpErrors){let u=new X(c,n.request,n._options);for(const h of n._options.hooks.beforeError)u=await h(u);throw u}if(n._options.onDownloadProgress){if(typeof n._options.onDownloadProgress!="function")throw new TypeError("The `onDownloadProgress` option must be a function");if(!Ze)throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");return n._stream(c.clone(),n._options.onDownloadProgress)}return c},o=n._options.retry.methods.includes(n.request.method.toLowerCase())?n._retry(r):r();for(const[c,u]of Object.entries(tt))o[c]=async()=>{n.request.headers.set("accept",n.request.headers.get("accept")||u);const l=(await o).clone();if(c==="json"){if(l.status===204||(await l.clone().arrayBuffer()).byteLength===0)return"";if(t.parseJson)return t.parseJson(await l.text())}return l[c]()};return o}constructor(e,t={}){if(Object.defineProperty(this,"request",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"abortController",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_retryCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_input",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._input=e,this._options={credentials:this._input.credentials||"same-origin",...t,headers:me(this._input.headers,t.headers),hooks:Y({beforeRequest:[],beforeRetry:[],beforeError:[],afterResponse:[]},t.hooks),method:rt(t.method??this._input.method),prefixUrl:String(t.prefixUrl||""),retry:ot(t.retry),throwHttpErrors:t.throwHttpErrors!==!1,timeout:t.timeout??1e4,fetch:t.fetch??globalThis.fetch.bind(globalThis)},typeof this._input!="string"&&!(this._input instanceof URL||this._input instanceof globalThis.Request))throw new TypeError("`input` must be a string, URL, or Request");if(this._options.prefixUrl&&typeof this._input=="string"){if(this._input.startsWith("/"))throw new Error("`input` must not begin with a slash when using `prefixUrl`");this._options.prefixUrl.endsWith("/")||(this._options.prefixUrl+="/"),this._input=this._options.prefixUrl+this._input}if(Xe){if(this.abortController=new globalThis.AbortController,this._options.signal){const n=this._options.signal;this._options.signal.addEventListener("abort",()=>{this.abortController.abort(n.reason)})}this._options.signal=this.abortController.signal}if(Qe&&(this._options.duplex="half"),this.request=new globalThis.Request(this._input,this._options),this._options.searchParams){const r="?"+(typeof this._options.searchParams=="string"?this._options.searchParams.replace(/^\?/,""):new URLSearchParams(this._options.searchParams).toString()),a=this.request.url.replace(/(?:\?.*?)?(?=#|$)/,r);(et&&this._options.body instanceof globalThis.FormData||this._options.body instanceof URLSearchParams)&&!(this._options.headers&&this._options.headers["content-type"])&&this.request.headers.delete("content-type"),this.request=new globalThis.Request(new globalThis.Request(a,{...this.request}),this._options)}this._options.json!==void 0&&(this._options.body=JSON.stringify(this._options.json),this.request.headers.set("content-type",this._options.headers.get("content-type")??"application/json"),this.request=new globalThis.Request(this.request,{body:this._options.body}))}_calculateRetryDelay(e){if(this._retryCount++,this._retryCount<this._options.retry.limit&&!(e instanceof de)){if(e instanceof X){if(!this._options.retry.statusCodes.includes(e.response.status))return 0;const n=e.response.headers.get("Retry-After");if(n&&this._options.retry.afterStatusCodes.includes(e.response.status)){let r=Number(n);return Number.isNaN(r)?r=Date.parse(n)-Date.now():r*=1e3,this._options.retry.maxRetryAfter!==void 0&&r>this._options.retry.maxRetryAfter?0:r}if(e.response.status===413)return 0}const t=this._options.retry.delay(this._retryCount);return Math.min(this._options.retry.backoffLimit,t)}return 0}_decorateResponse(e){return this._options.parseJson&&(e.json=async()=>this._options.parseJson(await e.text())),e}async _retry(e){try{return await e()}catch(t){const n=Math.min(this._calculateRetryDelay(t),j);if(n!==0&&this._retryCount>0){await ut(n,{signal:this._options.signal});for(const r of this._options.hooks.beforeRetry)if(await r({request:this.request,options:this._options,error:t,retryCount:this._retryCount})===fe)return;return this._retry(e)}throw t}}async _fetch(){for(const t of this._options.hooks.beforeRequest){const n=await t(this.request,this._options);if(n instanceof Request){this.request=n;break}if(n instanceof Response)return n}const e=lt(this.request,this._options);return this._options.timeout===!1?this._options.fetch(this.request.clone(),e):ct(this.request.clone(),e,this.abortController,this._options)}_stream(e,t){const n=Number(e.headers.get("content-length"))||0;let r=0;return e.status===204?(t&&t({percent:1,totalBytes:n,transferredBytes:r},new Uint8Array),new globalThis.Response(null,{status:e.status,statusText:e.statusText,headers:e.headers})):new globalThis.Response(new globalThis.ReadableStream({async start(a){const o=e.body.getReader();t&&t({percent:0,transferredBytes:0,totalBytes:n},new Uint8Array);async function c(){const{done:u,value:h}=await o.read();if(u){a.close();return}if(t){r+=h.byteLength;const l=n===0?0:r/n;t({percent:l,transferredBytes:r,totalBytes:n},h)}a.enqueue(h),await c()}await c()}}),{status:e.status,statusText:e.statusText,headers:e.headers})}}/*! MIT License © Sindre Sorhus */const H=s=>{const e=(t,n)=>V.create(t,O(s,n));for(const t of pe)e[t]=(n,r)=>V.create(n,O(s,r,{method:t}));return e.create=t=>H(O(t)),e.extend=t=>H(O(s,t)),e.stop=fe,e},ht=H(),dt=ht,mt=typeof window<"u"?{}:{referrer:"https://sk.thorswap.net",referer:"https://sk.thorswap.net"},ee=dt.create({headers:mt}),_e={get:(s,e)=>ee.get(s,e).json(),post:(s,e)=>ee.post(s,e).json()},te=Object.values(i.Chain),pt=(s="")=>{const e=s.toUpperCase(),[t]=e.split(".");if(te.includes(t))return!0;const[n]=e.split("/");if(te.includes(n))return!0;throw new Error(`Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`)},$=8,b=s=>10n**BigInt(s),S=s=>Math.log10(parseFloat(s.toString()));function B({value:s,bigIntDecimal:e=$,decimal:t=$}){const n=s<0n;let r=s.toString().substring(n?1:0);const a=t-(r.length-1);a>0&&(r="0".repeat(a)+r);const o=r.length-t;let c=r.slice(-t);return parseInt(c[e])>=5?c=`${c.substring(0,e-1)}${(parseInt(c[e-1])+1).toString()}`:c=c.substring(0,e),`${n?"-":""}${r.slice(0,o)}.${c}`.replace(/\.?0*$/,"")}var C,R,_,T,k,ye,I,L,M,F;const J=class J{constructor(e){A(this,C);A(this,_);A(this,k);A(this,I);A(this,M);p(this,"decimalMultiplier",10n**8n);p(this,"bigIntValue",0n);p(this,"decimal");const t=U(e),n=typeof e=="object";this.decimal=n?e.decimal:void 0,this.decimalMultiplier=n&&"decimalMultiplier"in e?e.decimalMultiplier:b(Math.max(se(E(t)),this.decimal||0)),d(this,k,ye).call(this,t)}static fromBigInt(e,t){return new J({decimal:t,value:B({value:e,bigIntDecimal:t,decimal:t})})}static shiftDecimals({value:e,from:t,to:n}){return this.fromBigInt(e.getBaseValue("bigint")*b(n)/b(t),n)}set(e){return new this.constructor({decimal:this.decimal,value:e,identifier:this.toString()})}add(...e){return d(this,C,R).call(this,"add",...e)}sub(...e){return d(this,C,R).call(this,"sub",...e)}mul(...e){return d(this,C,R).call(this,"mul",...e)}div(...e){return d(this,C,R).call(this,"div",...e)}gt(e){return d(this,_,T).call(this,"gt",e)}gte(e){return d(this,_,T).call(this,"gte",e)}lt(e){return d(this,_,T).call(this,"lt",e)}lte(e){return d(this,_,T).call(this,"lte",e)}eqValue(e){return d(this,_,T).call(this,"eqValue",e)}getValue(e){const t=this.formatBigIntToSafeValue(this.bigIntValue,this.decimal||S(this.decimalMultiplier));switch(e){case"number":return Number(t);case"string":return t;case"bigint":return this.bigIntValue*10n**BigInt(this.decimal||8n)/this.decimalMultiplier}}getBaseValue(e){const t=this.decimalMultiplier/b(this.decimal||i.BaseDecimal.THOR),n=this.bigIntValue/t;switch(e){case"number":return Number(n);case"string":return n.toString();case"bigint":return n}}getBigIntValue(e,t){if(!t&&typeof e=="object")return e.bigIntValue;const n=U(e),r=E(n);return r==="0"||r==="undefined"?0n:d(this,M,F).call(this,r,t)}toSignificant(e=6){const[t,n]=this.getValue("string").split("."),r=t||"",a=n||"";if((parseInt(r)?r.length+a.length:a.length)<=e)return this.getValue("string");if(r.length>=e)return r.slice(0,e).padEnd(r.length,"0");if(parseInt(r))return`${r}.${a.slice(0,e-r.length)}`.padEnd(e-r.length,"0");const c=parseInt(a),u=`${c}`.slice(0,e);return`0.${u.padStart(a.length-`${c}`.length+u.length,"0")}`}toFixed(e=6){const[t,n]=this.getValue("string").split("."),r=t||"",a=n||"";if(parseInt(r))return`${r}.${a.slice(0,e)}`.padEnd(e,"0");const o=parseInt(a),c=`${o}`.slice(0,e);return`0.${c.padStart(a.length-`${o}`.length+c.length,"0")}`}toAbbreviation(e=2){const t=this.getValue("number"),n=["","K","M","B","T","Q","Qi","S"],r=Math.floor(Math.log10(Math.abs(t))/3),a=n[r];if(!a)return this.getValue("string");const o=10**(r*3);return`${(t/o).toFixed(e)}${a}`}toCurrency(e="$",{currencyPosition:t="start",decimal:n=2,decimalSeparator:r=".",thousandSeparator:a=","}={}){const o=this.getValue("number"),[c,u=""]=o.toFixed(6).split("."),h=c.replace(/\B(?=(\d{3})+(?!\d))/g,a),l=!c&&!u?"0.00":c==="0"?`${parseFloat(`0.${u}`)}`.replace(".",r):`${h}${parseInt(u)?`${r}${u.slice(0,n)}`:""}`;return`${t==="start"?e:""}${l}${t==="end"?e:""}`}formatBigIntToSafeValue(e,t){const n=t||this.decimal||$,r=Math.max(n,S(this.decimalMultiplier)),a=e<0n,o=e.toString().substring(a?1:0),c=r-(o.length-1),u=c>0?"0".repeat(c)+o:o,h=u.length-r;let l=u.slice(-r);return parseInt(l[n])>=5?l=`${l.substring(0,n-1)}${(parseInt(l[n-1])+1).toString()}`:l=l.substring(0,n),`${a?"-":""}${u.slice(0,h)}.${l}`.replace(/\.?0*$/,"")}};C=new WeakSet,R=function(e,...t){const n=d(this,I,L).call(this,this,...t),r=Math.max(n,S(this.decimalMultiplier)),a=b(r),o=t.reduce((u,h)=>{const l=this.getBigIntValue(h,r);switch(e){case"add":return u+l;case"sub":return u-l;case"mul":return u*l/a;case"div":{if(l===0n)throw new RangeError("Division by zero");return u*a/l}default:return u}},this.bigIntValue*a/this.decimalMultiplier),c=B({bigIntDecimal:r,decimal:r,value:o});return new this.constructor({decimalMultiplier:b(r),decimal:this.decimal,value:c,identifier:this.toString()})},_=new WeakSet,T=function(e,...t){const n=d(this,I,L).call(this,this,...t),r=this.getBigIntValue(t[0],n),a=this.getBigIntValue(this,n);switch(e){case"gt":return a>r;case"gte":return a>=r;case"lt":return a<r;case"lte":return a<=r;case"eqValue":return a===r}},k=new WeakSet,ye=function(e){const t=E(e)||"0";this.bigIntValue=d(this,M,F).call(this,t)},I=new WeakSet,L=function(...e){const t=e.map(n=>typeof n=="object"?n.decimal||S(n.decimalMultiplier):se(E(n))).filter(Boolean);return Math.max(...t,$)},M=new WeakSet,F=function(e,t){const n=t?b(t):this.decimalMultiplier,r=S(n),[a="",o=""]=e.split(".");return BigInt(`${a}${o.padEnd(r,"0")}`)};let v=J;const ft=Intl.NumberFormat("fullwide",{useGrouping:!1,maximumFractionDigits:20});function E(s){const t=`${typeof s=="number"?ft.format(s):U(s)}`.replaceAll(",",".").split(".");return t.length>1?`${t.slice(0,-1).join("")}.${t.at(-1)}`:t[0]}function se(s){var t;const e=((t=s.split(".")[1])==null?void 0:t.length)||0;return Math.max(e,$)}function U(s){return typeof s=="object"?"getValue"in s?s.getValue("string"):s.value:s}const x=(s,e)=>typeof s=="bigint"?B({value:s,bigIntDecimal:e,decimal:e}):s;let W;const ne=s=>{if(!W)throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");return W.get(s.toUpperCase())||{decimal:i.BaseDecimal.THOR,identifier:""}},re=async(s,e=0)=>{pt(s);const t=await ae(G(s)),n=x(e,t);return new y({decimal:t,value:n,identifier:s})};class y extends v{constructor(t){const n="identifier"in t?t.identifier:`${t.chain}.${t.symbol}`;super(t.value instanceof v?t.value:{decimal:t.decimal,value:t.value});p(this,"address");p(this,"chain");p(this,"isGasAsset",!1);p(this,"isSynthetic",!1);p(this,"symbol");p(this,"tax");p(this,"ticker");p(this,"type");const r=G(n);this.type=ce(r),this.chain=r.chain,this.ticker=r.ticker,this.symbol=r.symbol,this.address=r.address,this.isSynthetic=r.isSynthetic,this.isGasAsset=r.isGasAsset,this.tax=t.tax}toString(t=!1){return t?this.ticker:this.isSynthetic?this.symbol:`${this.chain}.${this.symbol}`}eq({chain:t,symbol:n}){return this.chain===t&&this.symbol===n}static async fromString(t,n=0){return re(t,n)}static fromStringSync(t,n=0){const{isSynthetic:r}=G(t),{tax:a,decimal:o,identifier:c}=ne(t),u=x(n,o);return c?new y({tax:a,decimal:o,identifier:c,value:u}):r?new y({tax:a,decimal:8,identifier:t,value:u}):void 0}static async fromIdentifier(t,n=0){return re(t,n)}static fromIdentifierSync(t,n=0){const{decimal:r,identifier:a}=ne(t),o=x(n,r);return new y({decimal:r,identifier:a,value:o})}static fromChainOrSignature(t,n=0){const{decimal:r,identifier:a}=oe(t),o=x(n,r);return new y({value:o,decimal:r,identifier:a})}static async loadStaticAssets(){return new Promise(async(t,n)=>{try{const{ThorchainList:r,NativeList:a,...o}=await import("@swapkit/tokens");W=[a,...Object.values(o)].reduce((u,{tokens:h})=>(h.forEach(({identifier:l,chain:g,...w})=>{const P="decimals"in w?w.decimals:i.BaseDecimal[g];u.set(l,{identifier:l,decimal:P})}),u),new Map),t({ok:!0})}catch(r){console.error(r),n({ok:!1,error:r,message:"Couldn't load static assets. Ensure you have installed @swapkit/tokens package"})}})}}const gt=s=>{const e=y.fromChainOrSignature(s);switch(s){case i.Chain.Bitcoin:case i.Chain.Litecoin:case i.Chain.BitcoinCash:return e.set(10001e-8);case i.Chain.Dogecoin:return e.set(1.00000001);case i.Chain.Avalanche:case i.Chain.Ethereum:return e.set(1e-8);case i.Chain.THORChain:case i.Chain.Maya:return e.set(0);default:return e.set(1e-8)}},G=s=>{const e=s.slice(0,14).includes("/"),[t,n]=s.split(".").pop().split("/"),r=s.includes(".")&&!e?s:`${i.Chain.THORChain}.${n}`,[a,o]=r.split("."),[c,u]=(e?n:o).split("-");return{address:u==null?void 0:u.toLowerCase(),chain:a,isGasAsset:K({chain:a,symbol:o}),isSynthetic:e,symbol:(e?`${t}/`:"")+(u?`${c}-${(u==null?void 0:u.toLowerCase())??""}`:o),ticker:c}},_t={core_wallet_connection_not_found:10001,core_estimated_max_spendable_chain_not_supported:10002,core_extend_error:10003,core_inbound_data_not_found:10004,core_approve_asset_address_or_from_not_found:10005,core_chain_halted:10099,core_wallet_xdefi_not_installed:10101,core_wallet_evmwallet_not_installed:10102,core_wallet_walletconnect_not_installed:10103,core_wallet_keystore_not_installed:10104,core_wallet_ledger_not_installed:10105,core_wallet_trezor_not_installed:10106,core_wallet_keplr_not_installed:10107,core_wallet_okx_not_installed:10108,core_swap_invalid_params:10200,core_swap_route_not_complete:10201,core_swap_asset_not_recognized:10202,core_swap_contract_not_found:10203,core_swap_route_transaction_not_found:10204,core_swap_contract_not_supported:10205,core_swap_transaction_error:10206,core_swap_quote_mode_not_supported:10207,core_transaction_deposit_error:10301,core_transaction_create_liquidity_rune_error:10302,core_transaction_create_liquidity_asset_error:10303,core_transaction_create_liquidity_invalid_params:10304,core_transaction_add_liquidity_invalid_params:10305,core_transaction_add_liquidity_no_rune_address:10306,core_transaction_add_liquidity_rune_error:10307,core_transaction_add_liquidity_asset_error:10308,core_transaction_withdraw_error:10309,core_transaction_deposit_to_pool_error:10310,core_transaction_deposit_insufficient_funds_error:10311,core_transaction_deposit_gas_error:10312,core_transaction_deposit_server_error:10313,wallet_ledger_connection_error:20001,helpers_number_different_decimals:99101};class z extends Error{constructor(e,t){console.error(t,{stack:t==null?void 0:t.stack,message:t==null?void 0:t.message}),super(e,{cause:{code:_t[e],message:e}}),Object.setPrototypeOf(this,z.prototype)}}class f extends v{eq(e){return this.eqValue(e)}static fromBigInt(e,t){return new f({decimal:t,value:B({value:e,bigIntDecimal:t,decimal:t})})}}exports.AssetValue=y;exports.BigIntArithmetics=v;exports.RequestClient=_e;exports.SwapKitError=z;exports.SwapKitNumber=f;exports.assetFromString=Pe;exports.derivationPathToString=Je;exports.filterAssets=je;exports.formatBigIntToSafeValue=B;exports.gasFeeMultiplier=ke;exports.getAssetType=ce;exports.getAsymmetricAssetShare=le;exports.getAsymmetricAssetWithdrawAmount=Le;exports.getAsymmetricRuneShare=ue;exports.getAsymmetricRuneWithdrawAmount=He;exports.getCommonAssetInfo=oe;exports.getDecimal=ae;exports.getEstimatedPoolShare=Ue;exports.getLiquiditySlippage=We;exports.getMemoFor=Ke;exports.getMinAmountByChain=gt;exports.getSymmetricPoolShare=he;exports.getSymmetricWithdraw=Fe;exports.getTHORNameCost=Ye;exports.isGasAsset=K;exports.validateTHORName=ze;
package/dist/index.es.js CHANGED
@@ -1,19 +1,19 @@
1
1
  var bt = Object.defineProperty;
2
- var yt = (s, t, e) => t in s ? bt(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var f = (s, t, e) => (yt(s, typeof t != "symbol" ? t + "" : t, e), e), wt = (s, t, e) => {
4
- if (!t.has(s))
2
+ var yt = (r, t, e) => t in r ? bt(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var f = (r, t, e) => (yt(r, typeof t != "symbol" ? t + "" : t, e), e), wt = (r, t, e) => {
4
+ if (!t.has(r))
5
5
  throw TypeError("Cannot " + e);
6
6
  };
7
- var $ = (s, t, e) => {
8
- if (t.has(s))
7
+ var $ = (r, t, e) => {
8
+ if (t.has(r))
9
9
  throw TypeError("Cannot add the same private member more than once");
10
- t instanceof WeakSet ? t.add(s) : t.set(s, e);
10
+ t instanceof WeakSet ? t.add(r) : t.set(r, e);
11
11
  };
12
- var m = (s, t, e) => (wt(s, t, "access private method"), e);
12
+ var m = (r, t, e) => (wt(r, t, "access private method"), e);
13
13
  import { FeeOption as L, BaseDecimal as h, Chain as o, EVMChainList as At, ChainToRPC as vt, MemoType as g } from "@swapkit/types";
14
- const Tt = "0x313ce567", it = async ({ chain: s, to: t }) => {
14
+ const Tt = "0x313ce567", it = async ({ chain: r, to: t }) => {
15
15
  try {
16
- const { result: e } = await Zt.post(vt[s], {
16
+ const { result: e } = await Zt.post(vt[r], {
17
17
  headers: {
18
18
  accept: "*/*",
19
19
  "content-type": "application/json",
@@ -28,18 +28,18 @@ const Tt = "0x313ce567", it = async ({ chain: s, to: t }) => {
28
28
  });
29
29
  return parseInt(BigInt(e).toString());
30
30
  } catch (e) {
31
- return console.error(e), h[s];
31
+ return console.error(e), h[r];
32
32
  }
33
- }, $t = async (s) => {
34
- if (s === o.Ethereum)
33
+ }, $t = async (r) => {
34
+ if (r === o.Ethereum)
35
35
  return h.ETH;
36
- const [, t] = s.split("-");
36
+ const [, t] = r.split("-");
37
37
  return t != null && t.startsWith("0x") ? it({ chain: o.Ethereum, to: t }) : h.ETH;
38
- }, Rt = async (s) => {
39
- const [, t] = s.split("-");
38
+ }, Rt = async (r) => {
39
+ const [, t] = r.split("-");
40
40
  return t != null && t.startsWith("0x") ? it({ chain: o.Avalanche, to: t.toLowerCase() }) : h.AVAX;
41
- }, St = async (s) => s === o.BinanceSmartChain ? h.BSC : h.BSC, Ct = async ({ chain: s, symbol: t }) => {
42
- switch (s) {
41
+ }, St = async (r) => r === o.BinanceSmartChain ? h.BSC : h.BSC, Ct = async ({ chain: r, symbol: t }) => {
42
+ switch (r) {
43
43
  case o.Ethereum:
44
44
  return $t(t);
45
45
  case o.Avalanche:
@@ -47,14 +47,14 @@ const Tt = "0x313ce567", it = async ({ chain: s, to: t }) => {
47
47
  case o.BinanceSmartChain:
48
48
  return St(t);
49
49
  default:
50
- return h[s];
50
+ return h[r];
51
51
  }
52
52
  }, ie = {
53
53
  [L.Average]: 1.2,
54
54
  [L.Fast]: 1.5,
55
55
  [L.Fastest]: 2
56
- }, ot = ({ chain: s, symbol: t }) => {
57
- switch (s) {
56
+ }, ot = ({ chain: r, symbol: t }) => {
57
+ switch (r) {
58
58
  case o.Bitcoin:
59
59
  case o.BitcoinCash:
60
60
  case o.Litecoin:
@@ -62,7 +62,7 @@ const Tt = "0x313ce567", it = async ({ chain: s, to: t }) => {
62
62
  case o.Binance:
63
63
  case o.Ethereum:
64
64
  case o.Avalanche:
65
- return t === s;
65
+ return t === r;
66
66
  case o.Arbitrum:
67
67
  case o.Optimism:
68
68
  return t === "ETH";
@@ -79,18 +79,18 @@ const Tt = "0x313ce567", it = async ({ chain: s, to: t }) => {
79
79
  case o.THORChain:
80
80
  return t === "RUNE";
81
81
  }
82
- }, It = (s) => {
83
- switch (s) {
82
+ }, It = (r) => {
83
+ switch (r) {
84
84
  case "ETH.THOR":
85
85
  return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
86
86
  case "ETH.vTHOR":
87
87
  return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
88
88
  case o.Cosmos:
89
- return { identifier: "GAIA.ATOM", decimal: h[s] };
89
+ return { identifier: "GAIA.ATOM", decimal: h[r] };
90
90
  case o.THORChain:
91
- return { identifier: "THOR.RUNE", decimal: h[s] };
91
+ return { identifier: "THOR.RUNE", decimal: h[r] };
92
92
  case o.BinanceSmartChain:
93
- return { identifier: "BSC.BNB", decimal: h[s] };
93
+ return { identifier: "BSC.BNB", decimal: h[r] };
94
94
  case o.Maya:
95
95
  return { identifier: "MAYA.CACAO", decimal: h.MAYA };
96
96
  case "MAYA.MAYA":
@@ -106,12 +106,12 @@ const Tt = "0x313ce567", it = async ({ chain: s, to: t }) => {
106
106
  case o.Polygon:
107
107
  case o.Bitcoin:
108
108
  case o.Ethereum:
109
- return { identifier: `${s}.${s}`, decimal: h[s] };
109
+ return { identifier: `${r}.${r}`, decimal: h[r] };
110
110
  }
111
- }, Et = ({ chain: s, symbol: t }) => {
111
+ }, Ot = ({ chain: r, symbol: t }) => {
112
112
  if (t.includes("/"))
113
113
  return "Synth";
114
- switch (s) {
114
+ switch (r) {
115
115
  case o.Bitcoin:
116
116
  case o.BitcoinCash:
117
117
  case o.Dogecoin:
@@ -138,134 +138,134 @@ const Tt = "0x313ce567", it = async ({ chain: s, to: t }) => {
138
138
  case o.Optimism:
139
139
  return [o.Ethereum, o.Optimism].includes(t) ? "Native" : "OPTIMISM";
140
140
  }
141
- }, oe = (s) => {
141
+ }, oe = (r) => {
142
142
  var a;
143
- const [t, ...e] = s.split("."), r = s.includes("/"), n = e.join("."), i = (a = n == null ? void 0 : n.split("-")) == null ? void 0 : a[0];
144
- return { chain: t, symbol: n, ticker: i, synth: r };
145
- }, Ot = new RegExp(
143
+ const [t, ...e] = r.split("."), s = r.includes("/"), n = e.join("."), i = (a = n == null ? void 0 : n.split("-")) == null ? void 0 : a[0];
144
+ return { chain: t, symbol: n, ticker: i, synth: s };
145
+ }, Et = new RegExp(
146
146
  /(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
147
147
  "gmi"
148
- ), Mt = (s) => {
149
- const [t, e] = s.split(".");
148
+ ), Mt = (r) => {
149
+ const [t, e] = r.split(".");
150
150
  if (!At.includes(t))
151
151
  return !0;
152
- const [, r] = e.split("-");
153
- return ot({ chain: t, symbol: e }) || !!r;
154
- }, ae = (s) => s.filter((t) => {
152
+ const [, s] = e.split("-");
153
+ return ot({ chain: t, symbol: e }) || !!s;
154
+ }, ae = (r) => r.filter((t) => {
155
155
  const e = `${t.chain}.${t.symbol}`;
156
- return !Ot.test(e) && Mt(e) && t.value !== "0";
156
+ return !Et.test(e) && Mt(e) && t.value !== "0";
157
157
  }), Bt = ({
158
- liquidityUnits: s,
158
+ liquidityUnits: r,
159
159
  poolUnits: t,
160
160
  runeDepth: e
161
161
  }) => {
162
- const r = p(s), n = p(t), i = p(e), a = r.mul(i), c = n.mul(n).mul(2), u = n.mul(r).mul(2), d = r.mul(r), l = n.mul(n).mul(n);
162
+ const s = p(r), n = p(t), i = p(e), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), d = s.mul(s), l = n.mul(n).mul(n);
163
163
  return a.mul(c.sub(u).add(d)).div(l);
164
164
  }, xt = ({
165
- liquidityUnits: s,
165
+ liquidityUnits: r,
166
166
  poolUnits: t,
167
167
  assetDepth: e
168
168
  }) => {
169
- const r = p(s), n = p(t), i = p(e), a = r.mul(i), c = n.mul(n).mul(2), u = n.mul(r).mul(2), d = r.mul(r), l = a.mul(c.sub(u).add(d)), _ = n.mul(n).mul(n);
169
+ const s = p(r), n = p(t), i = p(e), a = s.mul(i), c = n.mul(n).mul(2), u = n.mul(s).mul(2), d = s.mul(s), l = a.mul(c.sub(u).add(d)), _ = n.mul(n).mul(n);
170
170
  return l.div(_);
171
171
  }, ce = ({
172
- percent: s,
172
+ percent: r,
173
173
  runeDepth: t,
174
174
  liquidityUnits: e,
175
- poolUnits: r
176
- }) => Bt({ runeDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), ue = ({
177
- percent: s,
175
+ poolUnits: s
176
+ }) => Bt({ runeDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), ue = ({
177
+ percent: r,
178
178
  assetDepth: t,
179
179
  liquidityUnits: e,
180
- poolUnits: r
181
- }) => xt({ assetDepth: t, liquidityUnits: e, poolUnits: r }).mul(s), p = (s) => b.fromBigInt(BigInt(s), h.THOR), qt = ({
182
- liquidityUnits: s,
180
+ poolUnits: s
181
+ }) => xt({ assetDepth: t, liquidityUnits: e, poolUnits: s }).mul(r), p = (r) => b.fromBigInt(BigInt(r), h.THOR), qt = ({
182
+ liquidityUnits: r,
183
183
  poolUnits: t,
184
184
  runeDepth: e,
185
- assetDepth: r
185
+ assetDepth: s
186
186
  }) => ({
187
- assetAmount: p(r).mul(s).div(t),
188
- runeAmount: p(e).mul(s).div(t)
187
+ assetAmount: p(s).mul(r).div(t),
188
+ runeAmount: p(e).mul(r).div(t)
189
189
  }), le = ({
190
- liquidityUnits: s,
190
+ liquidityUnits: r,
191
191
  poolUnits: t,
192
192
  runeDepth: e,
193
- assetDepth: r,
193
+ assetDepth: s,
194
194
  percent: n
195
195
  }) => Object.fromEntries(
196
- Object.entries(qt({ liquidityUnits: s, poolUnits: t, runeDepth: e, assetDepth: r })).map(
196
+ Object.entries(qt({ liquidityUnits: r, poolUnits: t, runeDepth: e, assetDepth: s })).map(
197
197
  ([i, a]) => [i, a.mul(n)]
198
198
  )
199
199
  ), de = ({
200
- runeDepth: s,
200
+ runeDepth: r,
201
201
  poolUnits: t,
202
202
  assetDepth: e,
203
- liquidityUnits: r,
203
+ liquidityUnits: s,
204
204
  runeAmount: n,
205
205
  assetAmount: i
206
206
  }) => {
207
- const a = new b({ value: s, decimal: 8 }), c = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), d = new b({ value: n, decimal: 8 }), l = new b({ value: i, decimal: 8 }), _ = d.mul(c), T = l.mul(a), j = d.mul(l), pt = a.mul(c), ft = u.mul(_.add(T.add(j.mul(2)))), _t = _.add(T.add(pt.mul(2))), Q = ft.div(_t), H = p(r).add(Q);
207
+ const a = new b({ value: r, decimal: 8 }), c = new b({ value: e, decimal: 8 }), u = new b({ value: t, decimal: 8 }), d = new b({ value: n, decimal: 8 }), l = new b({ value: i, decimal: 8 }), _ = d.mul(c), T = l.mul(a), j = d.mul(l), pt = a.mul(c), ft = u.mul(_.add(T.add(j.mul(2)))), _t = _.add(T.add(pt.mul(2))), Q = ft.div(_t), H = p(s).add(Q);
208
208
  if (Q.getBaseValue("number") === 0)
209
209
  return H.div(u).getBaseValue("number");
210
210
  const gt = u.add(H);
211
211
  return H.div(gt).getBaseValue("number");
212
212
  }, he = ({
213
- runeAmount: s,
213
+ runeAmount: r,
214
214
  assetAmount: t,
215
215
  runeDepth: e,
216
- assetDepth: r
216
+ assetDepth: s
217
217
  }) => {
218
- if (s === "0" || t === "0" || e === "0" || r === "0")
218
+ if (r === "0" || t === "0" || e === "0" || s === "0")
219
219
  return 0;
220
- const n = p(e), i = p(r), a = p(t), c = p(s), u = a.mul(n).sub(i.mul(c)), d = i.mul(c).add(n.mul(i));
220
+ const n = p(e), i = p(s), a = p(t), c = p(r), u = a.mul(n).sub(i.mul(c)), d = i.mul(c).add(n.mul(i));
221
221
  return Math.abs(u.div(d).getBaseValue("number"));
222
- }, Vt = ({
223
- symbol: s,
222
+ }, kt = ({
223
+ symbol: r,
224
224
  ticker: t,
225
225
  chain: e
226
- }) => e === "ETH" && t !== "ETH" ? `${t}-${s.slice(-3)}` : s, me = (s, t) => {
227
- switch (s) {
226
+ }) => e === "ETH" && t !== "ETH" ? `${t}-${r.slice(-3)}` : r, me = (r, t) => {
227
+ switch (r) {
228
228
  case g.LEAVE:
229
229
  case g.BOND: {
230
230
  const { address: e } = t;
231
- return `${s}:${e}`;
231
+ return `${r}:${e}`;
232
232
  }
233
233
  case g.UNBOND: {
234
- const { address: e, unbondAmount: r } = t;
235
- return `${s}:${e}:${r * 10 ** 8}`;
234
+ const { address: e, unbondAmount: s } = t;
235
+ return `${r}:${e}:${s * 10 ** 8}`;
236
236
  }
237
237
  case g.THORNAME_REGISTER: {
238
- const { name: e, chain: r, address: n, owner: i } = t;
239
- return `${s}:${e}:${r}:${n}${i ? `:${i}` : ""}`;
238
+ const { name: e, chain: s, address: n, owner: i } = t;
239
+ return `${r}:${e}:${s}:${n}${i ? `:${i}` : ""}`;
240
240
  }
241
241
  case g.DEPOSIT: {
242
- const { chain: e, symbol: r, address: n, singleSide: i } = t;
243
- return i ? `${s}:${e}/${r}::t:0` : `${s}:${e}.${r}:${n || ""}:t:0`;
242
+ const { chain: e, symbol: s, address: n, singleSide: i } = t;
243
+ return i ? `${r}:${e}/${s}::t:0` : `${r}:${e}.${s}:${n || ""}:t:0`;
244
244
  }
245
245
  case g.WITHDRAW: {
246
- const { chain: e, ticker: r, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", d = Vt({ chain: e, symbol: n, ticker: r });
247
- return `${s}:${e}${c ? "/" : "."}${d}:${i}${u}`;
246
+ const { chain: e, ticker: s, symbol: n, basisPoints: i, targetAssetString: a, singleSide: c } = t, u = !c && a ? `:${a}` : "", d = kt({ chain: e, symbol: n, ticker: s });
247
+ return `${r}:${e}${c ? "/" : "."}${d}:${i}${u}`;
248
248
  }
249
249
  case g.OPEN_LOAN:
250
250
  case g.CLOSE_LOAN: {
251
- const { asset: e, address: r } = t;
252
- return `${s}:${e}:${r}`;
251
+ const { asset: e, address: s } = t;
252
+ return `${r}:${e}:${s}`;
253
253
  }
254
254
  default:
255
255
  return "";
256
256
  }
257
- }, pe = (s) => {
258
- if (s < 0)
257
+ }, pe = (r) => {
258
+ if (r < 0)
259
259
  throw new Error("Invalid number of year");
260
- return 10 + s;
261
- }, fe = (s) => {
262
- if (s.length > 30)
260
+ return 10 + r;
261
+ }, fe = (r) => {
262
+ if (r.length > 30)
263
263
  return !1;
264
264
  const t = /^[a-zA-Z0-9+_-]+$/g;
265
- return !!s.match(t);
266
- }, _e = ([s, t, e, r, n]) => `${s}'/${t}'/${e}'/${r}${typeof n != "number" ? "" : `/${n}`}`;
265
+ return !!r.match(t);
266
+ }, _e = ([r, t, e, s, n]) => `${r}'/${t}'/${e}'/${s}${typeof n != "number" ? "" : `/${n}`}`;
267
267
  class X extends Error {
268
- constructor(t, e, r) {
268
+ constructor(t, e, s) {
269
269
  const n = t.status || t.status === 0 ? t.status : "", i = t.statusText || "", a = `${n} ${i}`.trim(), c = a ? `status code ${a}` : "an unknown error";
270
270
  super(`Request failed with ${c}`), Object.defineProperty(this, "response", {
271
271
  enumerable: !0,
@@ -282,7 +282,7 @@ class X extends Error {
282
282
  configurable: !0,
283
283
  writable: !0,
284
284
  value: void 0
285
- }), this.name = "HTTPError", this.response = t, this.request = e, this.options = r;
285
+ }), this.name = "HTTPError", this.response = t, this.request = e, this.options = s;
286
286
  }
287
287
  }
288
288
  class at extends Error {
@@ -295,38 +295,38 @@ class at extends Error {
295
295
  }), this.name = "TimeoutError", this.request = t;
296
296
  }
297
297
  }
298
- const q = (s) => s !== null && typeof s == "object", B = (...s) => {
299
- for (const t of s)
298
+ const q = (r) => r !== null && typeof r == "object", B = (...r) => {
299
+ for (const t of r)
300
300
  if ((!q(t) || Array.isArray(t)) && t !== void 0)
301
301
  throw new TypeError("The `options` argument must be an object");
302
- return J({}, ...s);
303
- }, ct = (s = {}, t = {}) => {
304
- const e = new globalThis.Headers(s), r = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
302
+ return J({}, ...r);
303
+ }, ct = (r = {}, t = {}) => {
304
+ const e = new globalThis.Headers(r), s = t instanceof globalThis.Headers, n = new globalThis.Headers(t);
305
305
  for (const [i, a] of n.entries())
306
- r && a === "undefined" || a === void 0 ? e.delete(i) : e.set(i, a);
306
+ s && a === "undefined" || a === void 0 ? e.delete(i) : e.set(i, a);
307
307
  return e;
308
- }, J = (...s) => {
308
+ }, J = (...r) => {
309
309
  let t = {}, e = {};
310
- for (const r of s)
311
- if (Array.isArray(r))
312
- Array.isArray(t) || (t = []), t = [...t, ...r];
313
- else if (q(r)) {
314
- for (let [n, i] of Object.entries(r))
310
+ for (const s of r)
311
+ if (Array.isArray(s))
312
+ Array.isArray(t) || (t = []), t = [...t, ...s];
313
+ else if (q(s)) {
314
+ for (let [n, i] of Object.entries(s))
315
315
  q(i) && n in t && (i = J(t[n], i)), t = { ...t, [n]: i };
316
- q(r.headers) && (e = ct(e, r.headers), t.headers = e);
316
+ q(s.headers) && (e = ct(e, s.headers), t.headers = e);
317
317
  }
318
318
  return t;
319
- }, kt = (() => {
320
- let s = !1, t = !1;
321
- const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function";
322
- return e && r && (t = new globalThis.Request("https://empty.invalid", {
319
+ }, Vt = (() => {
320
+ let r = !1, t = !1;
321
+ const e = typeof globalThis.ReadableStream == "function", s = typeof globalThis.Request == "function";
322
+ return e && s && (t = new globalThis.Request("https://empty.invalid", {
323
323
  body: new globalThis.ReadableStream(),
324
324
  method: "POST",
325
325
  // @ts-expect-error - Types are outdated.
326
326
  get duplex() {
327
- return s = !0, "half";
327
+ return r = !0, "half";
328
328
  }
329
- }).headers.has("Content-Type")), s && !t;
329
+ }).headers.has("Content-Type")), r && !t;
330
330
  })(), Pt = typeof globalThis.AbortController == "function", Nt = typeof globalThis.ReadableStream == "function", jt = typeof globalThis.FormData == "function", ut = ["get", "post", "put", "patch", "head", "delete"], Ht = {
331
331
  json: "application/json",
332
332
  text: "text/*",
@@ -360,86 +360,86 @@ const q = (s) => s !== null && typeof s == "object", B = (...s) => {
360
360
  window: !0,
361
361
  dispatcher: !0,
362
362
  duplex: !0
363
- }, Ut = (s) => ut.includes(s) ? s.toUpperCase() : s, Ft = ["get", "put", "head", "delete", "options", "trace"], Wt = [408, 413, 429, 500, 502, 503, 504], dt = [413, 429, 503], Z = {
363
+ }, Ut = (r) => ut.includes(r) ? r.toUpperCase() : r, Ft = ["get", "put", "head", "delete", "options", "trace"], Wt = [408, 413, 429, 500, 502, 503, 504], dt = [413, 429, 503], Z = {
364
364
  limit: 2,
365
365
  methods: Ft,
366
366
  statusCodes: Wt,
367
367
  afterStatusCodes: dt,
368
368
  maxRetryAfter: Number.POSITIVE_INFINITY,
369
369
  backoffLimit: Number.POSITIVE_INFINITY,
370
- delay: (s) => 0.3 * 2 ** (s - 1) * 1e3
371
- }, Gt = (s = {}) => {
372
- if (typeof s == "number")
370
+ delay: (r) => 0.3 * 2 ** (r - 1) * 1e3
371
+ }, Gt = (r = {}) => {
372
+ if (typeof r == "number")
373
373
  return {
374
374
  ...Z,
375
- limit: s
375
+ limit: r
376
376
  };
377
- if (s.methods && !Array.isArray(s.methods))
377
+ if (r.methods && !Array.isArray(r.methods))
378
378
  throw new Error("retry.methods must be an array");
379
- if (s.statusCodes && !Array.isArray(s.statusCodes))
379
+ if (r.statusCodes && !Array.isArray(r.statusCodes))
380
380
  throw new Error("retry.statusCodes must be an array");
381
381
  return {
382
382
  ...Z,
383
- ...s,
383
+ ...r,
384
384
  afterStatusCodes: dt
385
385
  };
386
386
  };
387
- async function Yt(s, t, e, r) {
387
+ async function Yt(r, t, e, s) {
388
388
  return new Promise((n, i) => {
389
389
  const a = setTimeout(() => {
390
- e && e.abort(), i(new at(s));
391
- }, r.timeout);
392
- r.fetch(s, t).then(n).catch(i).then(() => {
390
+ e && e.abort(), i(new at(r));
391
+ }, s.timeout);
392
+ s.fetch(r, t).then(n).catch(i).then(() => {
393
393
  clearTimeout(a);
394
394
  });
395
395
  });
396
396
  }
397
- async function zt(s, { signal: t }) {
398
- return new Promise((e, r) => {
397
+ async function zt(r, { signal: t }) {
398
+ return new Promise((e, s) => {
399
399
  t && (t.throwIfAborted(), t.addEventListener("abort", n, { once: !0 }));
400
400
  function n() {
401
- clearTimeout(i), r(t.reason);
401
+ clearTimeout(i), s(t.reason);
402
402
  }
403
403
  const i = setTimeout(() => {
404
404
  t == null || t.removeEventListener("abort", n), e();
405
- }, s);
405
+ }, r);
406
406
  });
407
407
  }
408
- const Jt = (s, t) => {
408
+ const Jt = (r, t) => {
409
409
  const e = {};
410
- for (const r in t)
411
- !(r in Dt) && !(r in Lt) && !(r in s) && (e[r] = t[r]);
410
+ for (const s in t)
411
+ !(s in Dt) && !(s in Lt) && !(s in r) && (e[s] = t[s]);
412
412
  return e;
413
413
  };
414
- class k {
414
+ class V {
415
415
  static create(t, e) {
416
- const r = new k(t, e), n = async () => {
417
- if (typeof r._options.timeout == "number" && r._options.timeout > D)
416
+ const s = new V(t, e), n = async () => {
417
+ if (typeof s._options.timeout == "number" && s._options.timeout > D)
418
418
  throw new RangeError(`The \`timeout\` option cannot be greater than ${D}`);
419
419
  await Promise.resolve();
420
- let c = await r._fetch();
421
- for (const u of r._options.hooks.afterResponse) {
422
- const d = await u(r.request, r._options, r._decorateResponse(c.clone()));
420
+ let c = await s._fetch();
421
+ for (const u of s._options.hooks.afterResponse) {
422
+ const d = await u(s.request, s._options, s._decorateResponse(c.clone()));
423
423
  d instanceof globalThis.Response && (c = d);
424
424
  }
425
- if (r._decorateResponse(c), !c.ok && r._options.throwHttpErrors) {
426
- let u = new X(c, r.request, r._options);
427
- for (const d of r._options.hooks.beforeError)
425
+ if (s._decorateResponse(c), !c.ok && s._options.throwHttpErrors) {
426
+ let u = new X(c, s.request, s._options);
427
+ for (const d of s._options.hooks.beforeError)
428
428
  u = await d(u);
429
429
  throw u;
430
430
  }
431
- if (r._options.onDownloadProgress) {
432
- if (typeof r._options.onDownloadProgress != "function")
431
+ if (s._options.onDownloadProgress) {
432
+ if (typeof s._options.onDownloadProgress != "function")
433
433
  throw new TypeError("The `onDownloadProgress` option must be a function");
434
434
  if (!Nt)
435
435
  throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
436
- return r._stream(c.clone(), r._options.onDownloadProgress);
436
+ return s._stream(c.clone(), s._options.onDownloadProgress);
437
437
  }
438
438
  return c;
439
- }, a = r._options.retry.methods.includes(r.request.method.toLowerCase()) ? r._retry(n) : n();
439
+ }, a = s._options.retry.methods.includes(s.request.method.toLowerCase()) ? s._retry(n) : n();
440
440
  for (const [c, u] of Object.entries(Ht))
441
441
  a[c] = async () => {
442
- r.request.headers.set("accept", r.request.headers.get("accept") || u);
442
+ s.request.headers.set("accept", s.request.headers.get("accept") || u);
443
443
  const l = (await a).clone();
444
444
  if (c === "json") {
445
445
  if (l.status === 204 || (await l.clone().arrayBuffer()).byteLength === 0)
@@ -505,14 +505,14 @@ class k {
505
505
  }
506
506
  if (Pt) {
507
507
  if (this.abortController = new globalThis.AbortController(), this._options.signal) {
508
- const r = this._options.signal;
508
+ const s = this._options.signal;
509
509
  this._options.signal.addEventListener("abort", () => {
510
- this.abortController.abort(r.reason);
510
+ this.abortController.abort(s.reason);
511
511
  });
512
512
  }
513
513
  this._options.signal = this.abortController.signal;
514
514
  }
515
- if (kt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
515
+ if (Vt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) {
516
516
  const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n);
517
517
  (jt && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(i, { ...this.request }), this._options);
518
518
  }
@@ -523,10 +523,10 @@ class k {
523
523
  if (t instanceof X) {
524
524
  if (!this._options.retry.statusCodes.includes(t.response.status))
525
525
  return 0;
526
- const r = t.response.headers.get("Retry-After");
527
- if (r && this._options.retry.afterStatusCodes.includes(t.response.status)) {
528
- let n = Number(r);
529
- return Number.isNaN(n) ? n = Date.parse(r) - Date.now() : n *= 1e3, this._options.retry.maxRetryAfter !== void 0 && n > this._options.retry.maxRetryAfter ? 0 : n;
526
+ const s = t.response.headers.get("Retry-After");
527
+ if (s && this._options.retry.afterStatusCodes.includes(t.response.status)) {
528
+ let n = Number(s);
529
+ return Number.isNaN(n) ? n = Date.parse(s) - Date.now() : n *= 1e3, this._options.retry.maxRetryAfter !== void 0 && n > this._options.retry.maxRetryAfter ? 0 : n;
530
530
  }
531
531
  if (t.response.status === 413)
532
532
  return 0;
@@ -543,9 +543,9 @@ class k {
543
543
  try {
544
544
  return await t();
545
545
  } catch (e) {
546
- const r = Math.min(this._calculateRetryDelay(e), D);
547
- if (r !== 0 && this._retryCount > 0) {
548
- await zt(r, { signal: this._options.signal });
546
+ const s = Math.min(this._calculateRetryDelay(e), D);
547
+ if (s !== 0 && this._retryCount > 0) {
548
+ await zt(s, { signal: this._options.signal });
549
549
  for (const n of this._options.hooks.beforeRetry)
550
550
  if (await n({
551
551
  request: this.request,
@@ -561,29 +561,29 @@ class k {
561
561
  }
562
562
  async _fetch() {
563
563
  for (const e of this._options.hooks.beforeRequest) {
564
- const r = await e(this.request, this._options);
565
- if (r instanceof Request) {
566
- this.request = r;
564
+ const s = await e(this.request, this._options);
565
+ if (s instanceof Request) {
566
+ this.request = s;
567
567
  break;
568
568
  }
569
- if (r instanceof Response)
570
- return r;
569
+ if (s instanceof Response)
570
+ return s;
571
571
  }
572
572
  const t = Jt(this.request, this._options);
573
573
  return this._options.timeout === !1 ? this._options.fetch(this.request.clone(), t) : Yt(this.request.clone(), t, this.abortController, this._options);
574
574
  }
575
575
  /* istanbul ignore next */
576
576
  _stream(t, e) {
577
- const r = Number(t.headers.get("content-length")) || 0;
577
+ const s = Number(t.headers.get("content-length")) || 0;
578
578
  let n = 0;
579
- return t.status === 204 ? (e && e({ percent: 1, totalBytes: r, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, {
579
+ return t.status === 204 ? (e && e({ percent: 1, totalBytes: s, transferredBytes: n }, new Uint8Array()), new globalThis.Response(null, {
580
580
  status: t.status,
581
581
  statusText: t.statusText,
582
582
  headers: t.headers
583
583
  })) : new globalThis.Response(new globalThis.ReadableStream({
584
584
  async start(i) {
585
585
  const a = t.body.getReader();
586
- e && e({ percent: 0, transferredBytes: 0, totalBytes: r }, new Uint8Array());
586
+ e && e({ percent: 0, transferredBytes: 0, totalBytes: s }, new Uint8Array());
587
587
  async function c() {
588
588
  const { done: u, value: d } = await a.read();
589
589
  if (u) {
@@ -592,8 +592,8 @@ class k {
592
592
  }
593
593
  if (e) {
594
594
  n += d.byteLength;
595
- const l = r === 0 ? 0 : n / r;
596
- e({ percent: l, transferredBytes: n, totalBytes: r }, d);
595
+ const l = s === 0 ? 0 : n / s;
596
+ e({ percent: l, transferredBytes: n, totalBytes: s }, d);
597
597
  }
598
598
  i.enqueue(d), await c();
599
599
  }
@@ -607,54 +607,54 @@ class k {
607
607
  }
608
608
  }
609
609
  /*! MIT License © Sindre Sorhus */
610
- const U = (s) => {
611
- const t = (e, r) => k.create(e, B(s, r));
610
+ const U = (r) => {
611
+ const t = (e, s) => V.create(e, B(r, s));
612
612
  for (const e of ut)
613
- t[e] = (r, n) => k.create(r, B(s, n, { method: e }));
614
- return t.create = (e) => U(B(e)), t.extend = (e) => U(B(s, e)), t.stop = lt, t;
613
+ t[e] = (s, n) => V.create(s, B(r, n, { method: e }));
614
+ return t.create = (e) => U(B(e)), t.extend = (e) => U(B(r, e)), t.stop = lt, t;
615
615
  }, Kt = U(), Qt = Kt, Xt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Qt.create({ headers: Xt }), Zt = {
616
- get: (s, t) => tt.get(s, t).json(),
617
- post: (s, t) => tt.post(s, t).json()
618
- }, et = Object.values(o), te = (s = "") => {
619
- const t = s.toUpperCase(), [e] = t.split(".");
616
+ get: (r, t) => tt.get(r, t).json(),
617
+ post: (r, t) => tt.post(r, t).json()
618
+ }, et = Object.values(o), te = (r = "") => {
619
+ const t = r.toUpperCase(), [e] = t.split(".");
620
620
  if (et.includes(e))
621
621
  return !0;
622
- const [r] = t.split("/");
623
- if (et.includes(r))
622
+ const [s] = t.split("/");
623
+ if (et.includes(s))
624
624
  return !0;
625
625
  throw new Error(
626
- `Invalid identifier: ${s}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
626
+ `Invalid identifier: ${r}. Expected format: <Chain>.<Ticker> or <Chain>.<Ticker>-<ContractAddress>`
627
627
  );
628
- }, I = 8, w = (s) => 10n ** BigInt(s), S = (s) => Math.log10(parseFloat(s.toString()));
628
+ }, I = 8, w = (r) => 10n ** BigInt(r), S = (r) => Math.log10(parseFloat(r.toString()));
629
629
  function P({
630
- value: s,
630
+ value: r,
631
631
  bigIntDecimal: t = I,
632
632
  decimal: e = I
633
633
  }) {
634
- const r = s < 0n;
635
- let n = s.toString().substring(r ? 1 : 0);
634
+ const s = r < 0n;
635
+ let n = r.toString().substring(s ? 1 : 0);
636
636
  const i = e - (n.length - 1);
637
637
  i > 0 && (n = "0".repeat(i) + n);
638
638
  const a = n.length - e;
639
639
  let c = n.slice(-e);
640
- return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${r ? "-" : ""}${n.slice(0, a)}.${c}`.replace(
640
+ return parseInt(c[t]) >= 5 ? c = `${c.substring(0, t - 1)}${(parseInt(c[t - 1]) + 1).toString()}` : c = c.substring(0, t), `${s ? "-" : ""}${n.slice(0, a)}.${c}`.replace(
641
641
  /\.?0*$/,
642
642
  ""
643
643
  );
644
644
  }
645
- var v, C, y, R, N, ht, O, F, M, W;
645
+ var v, C, y, R, N, ht, E, F, M, W;
646
646
  const K = class K {
647
647
  constructor(t) {
648
648
  $(this, v);
649
649
  $(this, y);
650
650
  $(this, N);
651
- $(this, O);
651
+ $(this, E);
652
652
  $(this, M);
653
653
  f(this, "decimalMultiplier", 10n ** 8n);
654
654
  f(this, "bigIntValue", 0n);
655
655
  f(this, "decimal");
656
- const e = G(t), r = typeof t == "object";
657
- this.decimal = r ? t.decimal : void 0, this.decimalMultiplier = r && "decimalMultiplier" in t ? t.decimalMultiplier : w(Math.max(rt(x(e)), this.decimal || 0)), m(this, N, ht).call(this, e);
656
+ const e = G(t), s = typeof t == "object";
657
+ this.decimal = s ? t.decimal : void 0, this.decimalMultiplier = s && "decimalMultiplier" in t ? t.decimalMultiplier : w(Math.max(st(x(e)), this.decimal || 0)), m(this, N, ht).call(this, e);
658
658
  }
659
659
  static fromBigInt(t, e) {
660
660
  return new K({
@@ -665,11 +665,11 @@ const K = class K {
665
665
  static shiftDecimals({
666
666
  value: t,
667
667
  from: e,
668
- to: r
668
+ to: s
669
669
  }) {
670
670
  return this.fromBigInt(
671
- t.getBaseValue("bigint") * w(r) / w(e),
672
- r
671
+ t.getBaseValue("bigint") * w(s) / w(e),
672
+ s
673
673
  );
674
674
  }
675
675
  set(t) {
@@ -719,24 +719,24 @@ const K = class K {
719
719
  }
720
720
  // @ts-expect-error
721
721
  getBaseValue(t) {
722
- const e = this.decimalMultiplier / w(this.decimal || h.THOR), r = this.bigIntValue / e;
722
+ const e = this.decimalMultiplier / w(this.decimal || h.THOR), s = this.bigIntValue / e;
723
723
  switch (t) {
724
724
  case "number":
725
- return Number(r);
725
+ return Number(s);
726
726
  case "string":
727
- return r.toString();
727
+ return s.toString();
728
728
  case "bigint":
729
- return r;
729
+ return s;
730
730
  }
731
731
  }
732
732
  getBigIntValue(t, e) {
733
733
  if (!e && typeof t == "object")
734
734
  return t.bigIntValue;
735
- const r = G(t), n = x(r);
735
+ const s = G(t), n = x(s);
736
736
  return n === "0" || n === "undefined" ? 0n : m(this, M, W).call(this, n, e);
737
737
  }
738
738
  toSignificant(t = 6) {
739
- const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
739
+ const [e, s] = this.getValue("string").split("."), n = e || "", i = s || "";
740
740
  if ((parseInt(n) ? n.length + i.length : i.length) <= t)
741
741
  return this.getValue("string");
742
742
  if (n.length >= t)
@@ -753,7 +753,7 @@ const K = class K {
753
753
  )}`;
754
754
  }
755
755
  toFixed(t = 6) {
756
- const [e, r] = this.getValue("string").split("."), n = e || "", i = r || "";
756
+ const [e, s] = this.getValue("string").split("."), n = e || "", i = s || "";
757
757
  if (parseInt(n))
758
758
  return `${n}.${i.slice(0, t)}`.padEnd(t, "0");
759
759
  const a = parseInt(i), c = `${a}`.slice(0, t);
@@ -763,7 +763,7 @@ const K = class K {
763
763
  )}`;
764
764
  }
765
765
  toAbbreviation(t = 2) {
766
- const e = this.getValue("number"), r = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(e)) / 3), i = r[n];
766
+ const e = this.getValue("number"), s = ["", "K", "M", "B", "T", "Q", "Qi", "S"], n = Math.floor(Math.log10(Math.abs(e)) / 3), i = s[n];
767
767
  if (!i)
768
768
  return this.getValue("string");
769
769
  const a = 10 ** (n * 3);
@@ -771,27 +771,27 @@ const K = class K {
771
771
  }
772
772
  toCurrency(t = "$", {
773
773
  currencyPosition: e = "start",
774
- decimal: r = 2,
774
+ decimal: s = 2,
775
775
  decimalSeparator: n = ".",
776
776
  thousandSeparator: i = ","
777
777
  } = {}) {
778
- const a = this.getValue("number"), [c, u = ""] = a.toFixed(6).split("."), d = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), l = !c && !u ? "0.00" : c === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${d}${parseInt(u) ? `${n}${u.slice(0, r)}` : ""}`;
778
+ const a = this.getValue("number"), [c, u = ""] = a.toFixed(6).split("."), d = c.replace(/\B(?=(\d{3})+(?!\d))/g, i), l = !c && !u ? "0.00" : c === "0" ? `${parseFloat(`0.${u}`)}`.replace(".", n) : `${d}${parseInt(u) ? `${n}${u.slice(0, s)}` : ""}`;
779
779
  return `${e === "start" ? t : ""}${l}${e === "end" ? t : ""}`;
780
780
  }
781
781
  formatBigIntToSafeValue(t, e) {
782
- const r = e || this.decimal || I, n = Math.max(
783
- r,
782
+ const s = e || this.decimal || I, n = Math.max(
783
+ s,
784
784
  S(this.decimalMultiplier)
785
785
  ), i = t < 0n, a = t.toString().substring(i ? 1 : 0), c = n - (a.length - 1), u = c > 0 ? "0".repeat(c) + a : a, d = u.length - n;
786
786
  let l = u.slice(-n);
787
- return parseInt(l[r]) >= 5 ? l = `${l.substring(0, r - 1)}${(parseInt(l[r - 1]) + 1).toString()}` : l = l.substring(0, r), `${i ? "-" : ""}${u.slice(
787
+ return parseInt(l[s]) >= 5 ? l = `${l.substring(0, s - 1)}${(parseInt(l[s - 1]) + 1).toString()}` : l = l.substring(0, s), `${i ? "-" : ""}${u.slice(
788
788
  0,
789
789
  d
790
790
  )}.${l}`.replace(/\.?0*$/, "");
791
791
  }
792
792
  };
793
793
  v = new WeakSet(), C = function(t, ...e) {
794
- const r = m(this, O, F).call(this, this, ...e), n = Math.max(r, S(this.decimalMultiplier)), i = w(n), a = e.reduce(
794
+ const s = m(this, E, F).call(this, this, ...e), n = Math.max(s, S(this.decimalMultiplier)), i = w(n), a = e.reduce(
795
795
  (u, d) => {
796
796
  const l = this.getBigIntValue(d, n);
797
797
  switch (t) {
@@ -824,7 +824,7 @@ v = new WeakSet(), C = function(t, ...e) {
824
824
  identifier: this.toString()
825
825
  });
826
826
  }, y = new WeakSet(), R = function(t, ...e) {
827
- const r = m(this, O, F).call(this, this, ...e), n = this.getBigIntValue(e[0], r), i = this.getBigIntValue(this, r);
827
+ const s = m(this, E, F).call(this, this, ...e), n = this.getBigIntValue(e[0], s), i = this.getBigIntValue(this, s);
828
828
  switch (t) {
829
829
  case "gt":
830
830
  return i > n;
@@ -840,46 +840,46 @@ v = new WeakSet(), C = function(t, ...e) {
840
840
  }, N = new WeakSet(), ht = function(t) {
841
841
  const e = x(t) || "0";
842
842
  this.bigIntValue = m(this, M, W).call(this, e);
843
- }, O = new WeakSet(), F = function(...t) {
844
- const e = t.map((r) => typeof r == "object" ? r.decimal || S(r.decimalMultiplier) : rt(x(r))).filter(Boolean);
843
+ }, E = new WeakSet(), F = function(...t) {
844
+ const e = t.map((s) => typeof s == "object" ? s.decimal || S(s.decimalMultiplier) : st(x(s))).filter(Boolean);
845
845
  return Math.max(...e, I);
846
846
  }, M = new WeakSet(), W = function(t, e) {
847
- const r = e ? w(e) : this.decimalMultiplier, n = S(r), [i = "", a = ""] = t.split(".");
847
+ const s = e ? w(e) : this.decimalMultiplier, n = S(s), [i = "", a = ""] = t.split(".");
848
848
  return BigInt(`${i}${a.padEnd(n, "0")}`);
849
849
  };
850
- let E = K;
850
+ let O = K;
851
851
  const ee = Intl.NumberFormat("fullwide", {
852
852
  useGrouping: !1,
853
853
  maximumFractionDigits: 20
854
854
  });
855
- function x(s) {
856
- const e = `${typeof s == "number" ? ee.format(s) : G(s)}`.replaceAll(",", ".").split(".");
855
+ function x(r) {
856
+ const e = `${typeof r == "number" ? ee.format(r) : G(r)}`.replaceAll(",", ".").split(".");
857
857
  return e.length > 1 ? `${e.slice(0, -1).join("")}.${e.at(-1)}` : e[0];
858
858
  }
859
- function rt(s) {
859
+ function st(r) {
860
860
  var e;
861
- const t = ((e = s.split(".")[1]) == null ? void 0 : e.length) || 0;
861
+ const t = ((e = r.split(".")[1]) == null ? void 0 : e.length) || 0;
862
862
  return Math.max(t, I);
863
863
  }
864
- function G(s) {
865
- return typeof s == "object" ? "getValue" in s ? s.getValue("string") : s.value : s;
864
+ function G(r) {
865
+ return typeof r == "object" ? "getValue" in r ? r.getValue("string") : r.value : r;
866
866
  }
867
- const V = (s, t) => typeof s == "bigint" ? P({ value: s, bigIntDecimal: t, decimal: t }) : s;
867
+ const k = (r, t) => typeof r == "bigint" ? P({ value: r, bigIntDecimal: t, decimal: t }) : r;
868
868
  let Y;
869
- const st = (s) => {
869
+ const rt = (r) => {
870
870
  if (!Y)
871
871
  throw new Error("Static assets not loaded, call await AssetValue.loadStaticAssets() first");
872
- return Y.get(s.toUpperCase()) || { decimal: h.THOR, identifier: "" };
873
- }, nt = async (s, t = 0) => {
874
- te(s);
875
- const e = await Ct(z(s)), r = V(t, e);
876
- return new A({ decimal: e, value: r, identifier: s });
872
+ return Y.get(r.toUpperCase()) || { decimal: h.THOR, identifier: "" };
873
+ }, nt = async (r, t = 0) => {
874
+ te(r);
875
+ const e = await Ct(z(r)), s = k(t, e);
876
+ return new A({ decimal: e, value: s, identifier: r });
877
877
  };
878
- class A extends E {
878
+ class A extends O {
879
879
  constructor(e) {
880
- const r = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`;
880
+ const s = "identifier" in e ? e.identifier : `${e.chain}.${e.symbol}`;
881
881
  super(
882
- e.value instanceof E ? e.value : { decimal: e.decimal, value: e.value }
882
+ e.value instanceof O ? e.value : { decimal: e.decimal, value: e.value }
883
883
  );
884
884
  f(this, "address");
885
885
  f(this, "chain");
@@ -889,44 +889,40 @@ class A extends E {
889
889
  f(this, "tax");
890
890
  f(this, "ticker");
891
891
  f(this, "type");
892
- const n = z(r);
893
- this.type = Et(n), this.chain = n.chain, this.ticker = n.ticker, this.symbol = n.symbol, this.address = n.address, this.isSynthetic = n.isSynthetic, this.isGasAsset = n.isGasAsset, this.tax = e.tax;
892
+ const n = z(s);
893
+ this.type = Ot(n), this.chain = n.chain, this.ticker = n.ticker, this.symbol = n.symbol, this.address = n.address, this.isSynthetic = n.isSynthetic, this.isGasAsset = n.isGasAsset, this.tax = e.tax;
894
894
  }
895
895
  toString(e = !1) {
896
- const r = this.isSynthetic ? this.symbol.split("-")[0] : this.ticker;
897
- return e ? r : (
898
- // THOR.ETH/ETH | ETH.USDT-0x1234567890
899
- `${this.chain}.${this.symbol}`
900
- );
896
+ return e ? this.ticker : this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
901
897
  }
902
- eq({ chain: e, symbol: r }) {
903
- return this.chain === e && this.symbol === r;
898
+ eq({ chain: e, symbol: s }) {
899
+ return this.chain === e && this.symbol === s;
904
900
  }
905
- static async fromString(e, r = 0) {
906
- return nt(e, r);
901
+ static async fromString(e, s = 0) {
902
+ return nt(e, s);
907
903
  }
908
- static fromStringSync(e, r = 0) {
904
+ static fromStringSync(e, s = 0) {
909
905
  const { isSynthetic: n } = z(e), {
910
906
  tax: i,
911
907
  decimal: a,
912
908
  identifier: c
913
- } = st(e), u = V(r, a);
909
+ } = rt(e), u = k(s, a);
914
910
  return c ? new A({ tax: i, decimal: a, identifier: c, value: u }) : n ? new A({ tax: i, decimal: 8, identifier: e, value: u }) : void 0;
915
911
  }
916
- static async fromIdentifier(e, r = 0) {
917
- return nt(e, r);
912
+ static async fromIdentifier(e, s = 0) {
913
+ return nt(e, s);
918
914
  }
919
- static fromIdentifierSync(e, r = 0) {
920
- const { decimal: n, identifier: i } = st(e), a = V(r, n);
915
+ static fromIdentifierSync(e, s = 0) {
916
+ const { decimal: n, identifier: i } = rt(e), a = k(s, n);
921
917
  return new A({ decimal: n, identifier: i, value: a });
922
918
  }
923
- static fromChainOrSignature(e, r = 0) {
924
- const { decimal: n, identifier: i } = It(e), a = V(r, n);
919
+ static fromChainOrSignature(e, s = 0) {
920
+ const { decimal: n, identifier: i } = It(e), a = k(s, n);
925
921
  return new A({ value: a, decimal: n, identifier: i });
926
922
  }
927
923
  static async loadStaticAssets() {
928
924
  return new Promise(
929
- async (e, r) => {
925
+ async (e, s) => {
930
926
  try {
931
927
  const {
932
928
  // Omit ThorchainList from import to avoid decimals conflict (TC uses 8 for all)
@@ -943,7 +939,7 @@ class A extends E {
943
939
  /* @__PURE__ */ new Map()
944
940
  ), e({ ok: !0 });
945
941
  } catch (n) {
946
- console.error(n), r({
942
+ console.error(n), s({
947
943
  ok: !1,
948
944
  error: n,
949
945
  message: "Couldn't load static assets. Ensure you have installed @swapkit/tokens package"
@@ -953,9 +949,9 @@ class A extends E {
953
949
  );
954
950
  }
955
951
  }
956
- const ge = (s) => {
957
- const t = A.fromChainOrSignature(s);
958
- switch (s) {
952
+ const ge = (r) => {
953
+ const t = A.fromChainOrSignature(r);
954
+ switch (r) {
959
955
  case o.Bitcoin:
960
956
  case o.Litecoin:
961
957
  case o.BitcoinCash:
@@ -971,8 +967,8 @@ const ge = (s) => {
971
967
  default:
972
968
  return t.set(1e-8);
973
969
  }
974
- }, z = (s) => {
975
- const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").pop().split("/"), n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, a] = n.split("."), [c, u] = (t ? r : a).split("-");
970
+ }, z = (r) => {
971
+ const t = r.slice(0, 14).includes("/"), [e, s] = r.split(".").pop().split("/"), n = r.includes(".") && !t ? r : `${o.THORChain}.${s}`, [i, a] = n.split("."), [c, u] = (t ? s : a).split("-");
976
972
  return {
977
973
  address: u == null ? void 0 : u.toLowerCase(),
978
974
  chain: i,
@@ -981,7 +977,7 @@ const ge = (s) => {
981
977
  symbol: (t ? `${e}/` : "") + (u ? `${c}-${(u == null ? void 0 : u.toLowerCase()) ?? ""}` : a),
982
978
  ticker: c
983
979
  };
984
- }, re = {
980
+ }, se = {
985
981
  /**
986
982
  * Core
987
983
  */
@@ -1040,10 +1036,10 @@ const ge = (s) => {
1040
1036
  };
1041
1037
  class mt extends Error {
1042
1038
  constructor(t, e) {
1043
- console.error(e), super(t, { cause: { code: re[t], message: t } }), Object.setPrototypeOf(this, mt.prototype);
1039
+ console.error(e, { stack: e == null ? void 0 : e.stack, message: e == null ? void 0 : e.message }), super(t, { cause: { code: se[t], message: t } }), Object.setPrototypeOf(this, mt.prototype);
1044
1040
  }
1045
1041
  }
1046
- class b extends E {
1042
+ class b extends O {
1047
1043
  eq(t) {
1048
1044
  return this.eqValue(t);
1049
1045
  }
@@ -1056,7 +1052,7 @@ class b extends E {
1056
1052
  }
1057
1053
  export {
1058
1054
  A as AssetValue,
1059
- E as BigIntArithmetics,
1055
+ O as BigIntArithmetics,
1060
1056
  Zt as RequestClient,
1061
1057
  mt as SwapKitError,
1062
1058
  b as SwapKitNumber,
@@ -1065,7 +1061,7 @@ export {
1065
1061
  ae as filterAssets,
1066
1062
  P as formatBigIntToSafeValue,
1067
1063
  ie as gasFeeMultiplier,
1068
- Et as getAssetType,
1064
+ Ot as getAssetType,
1069
1065
  xt as getAsymmetricAssetShare,
1070
1066
  ue as getAsymmetricAssetWithdrawAmount,
1071
1067
  Bt as getAsymmetricRuneShare,
package/package.json CHANGED
@@ -8,16 +8,16 @@
8
8
  "@vitest/coverage-istanbul": "0.34.6",
9
9
  "vite": "4.5.0",
10
10
  "vitest": "0.34.6",
11
- "@internal/config": "0.0.0-rc.3",
12
- "@swapkit/tokens": "1.0.0-rc.18",
13
- "@swapkit/types": "1.0.0-rc.17"
11
+ "@internal/config": "0.0.0-rc.5",
12
+ "@swapkit/tokens": "1.0.0-rc.20",
13
+ "@swapkit/types": "1.0.0-rc.19"
14
14
  },
15
15
  "eslintConfig": {
16
16
  "extends": "../../../internal/eslint-config"
17
17
  },
18
18
  "peerDependencies": {
19
- "@swapkit/tokens": "1.0.0-rc.18",
20
- "@swapkit/types": "1.0.0-rc.17"
19
+ "@swapkit/tokens": "1.0.0-rc.20",
20
+ "@swapkit/types": "1.0.0-rc.19"
21
21
  },
22
22
  "exports": {
23
23
  ".": {
@@ -42,7 +42,7 @@
42
42
  "repository": "https://github.com/thorswap/SwapKit.git",
43
43
  "type": "module",
44
44
  "types": "./dist/index.d.ts",
45
- "version": "1.0.0-rc.37",
45
+ "version": "1.0.0-rc.39",
46
46
  "scripts": {
47
47
  "build": "vite build",
48
48
  "clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
@@ -27,8 +27,8 @@ describe('AssetValue', () => {
27
27
  value: 1234567890,
28
28
  });
29
29
 
30
- expect(ethSynth.toString()).toBe('THOR.ETH/ETH');
31
- expect(ethSynth.toString(true)).toBe('ETH/ETH');
30
+ expect(ethSynth.toString()).toBe('ETH/ETH');
31
+ expect(ethSynth.toString(true)).toBe('ETH');
32
32
  expect(ethSynth.mul(21.37).getValue('string')).toBe('26382715809.3');
33
33
 
34
34
  const atomDerived = new AssetValue({
@@ -98,7 +98,7 @@ describe('AssetValue', () => {
98
98
  expect(thor.toString()).toBe('ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044');
99
99
 
100
100
  const ethSynth = await AssetValue.fromIdentifier('ETH/ETH');
101
- expect(ethSynth.toString()).toBe('THOR.ETH/ETH');
101
+ expect(ethSynth.toString()).toBe('ETH/ETH');
102
102
  });
103
103
  });
104
104
 
@@ -104,13 +104,7 @@ export class AssetValue extends BigIntArithmetics {
104
104
  }
105
105
 
106
106
  toString(short = false) {
107
- // THOR.RUNE | ETH/ETH
108
- const shortFormat = this.isSynthetic ? this.symbol.split('-')[0] : this.ticker;
109
-
110
- return short
111
- ? shortFormat
112
- : // THOR.ETH/ETH | ETH.USDT-0x1234567890
113
- `${this.chain}.${this.symbol}`;
107
+ return short ? this.ticker : this.isSynthetic ? this.symbol : `${this.chain}.${this.symbol}`;
114
108
  }
115
109
 
116
110
  eq({ chain, symbol }: { chain: Chain; symbol: string }) {
@@ -62,7 +62,7 @@ export type Keys = keyof typeof errorMessages;
62
62
 
63
63
  export class SwapKitError extends Error {
64
64
  constructor(errorKey: Keys, sourceError?: any) {
65
- console.error(sourceError);
65
+ console.error(sourceError, { stack: sourceError?.stack, message: sourceError?.message });
66
66
 
67
67
  super(errorKey, { cause: { code: errorMessages[errorKey], message: errorKey } });
68
68
  Object.setPrototypeOf(this, SwapKitError.prototype);