UNPKG

@multiversx/sdk-dapp-swap

Version:

A library to hold the main logic for swapping between tokens on the MultiversX blockchain

240 lines (235 loc) 53.9 kB
"use strict";var qt=Object.create;var Oe=Object.defineProperty,Ht=Object.defineProperties,jt=Object.getOwnPropertyDescriptor,Kt=Object.getOwnPropertyDescriptors,Xt=Object.getOwnPropertyNames,_e=Object.getOwnPropertySymbols,Yt=Object.getPrototypeOf,sr=Object.prototype.hasOwnProperty,Gr=Object.prototype.propertyIsEnumerable;var Mr=(t,e,r)=>e in t?Oe(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,R=(t,e)=>{for(var r in e||(e={}))sr.call(e,r)&&Mr(t,r,e[r]);if(_e)for(var r of _e(e))Gr.call(e,r)&&Mr(t,r,e[r]);return t},G=(t,e)=>Ht(t,Kt(e));var Qr=(t,e)=>{var r={};for(var n in t)sr.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&_e)for(var n of _e(t))e.indexOf(n)<0&&Gr.call(t,n)&&(r[n]=t[n]);return r};var Zt=(t,e)=>()=>(t&&(e=t(t=0)),e);var $e=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Jt=(t,e)=>{for(var r in e)Oe(t,r,{get:e[r],enumerable:!0})},Wr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xt(e))!sr.call(t,o)&&o!==r&&Oe(t,o,{get:()=>e[o],enumerable:!(n=jt(e,o))||n.enumerable});return t};var te=(t,e,r)=>(r=t!=null?qt(Yt(t)):{},Wr(e||!t||!t.__esModule?Oe(r,"default",{value:t,enumerable:!0}):r,t)),en=t=>Wr(Oe({},"__esModule",{value:!0}),t);var ar=(t,e,r)=>new Promise((n,o)=>{var i=c=>{try{p(r.next(c))}catch(g){o(g)}},s=c=>{try{p(r.throw(c))}catch(g){o(g)}},p=c=>c.done?n(c.value):Promise.resolve(c.value).then(i,s);p((r=r.apply(t,e)).next())});var qr=$e(Me=>{"use strict";a();Me.byteLength=tn;Me.toByteArray=on;Me.fromByteArray=un;var ie=[],Y=[],rn=typeof Uint8Array!="undefined"?Uint8Array:Array,ur="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(Te=0,Vr=ur.length;Te<Vr;++Te)ie[Te]=ur[Te],Y[ur.charCodeAt(Te)]=Te;var Te,Vr;Y["-".charCodeAt(0)]=62;Y["_".charCodeAt(0)]=63;function zr(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function tn(t){var e=zr(t),r=e[0],n=e[1];return(r+n)*3/4-n}function nn(t,e,r){return(e+r)*3/4-r}function on(t){var e,r=zr(t),n=r[0],o=r[1],i=new rn(nn(t,n,o)),s=0,p=o>0?n-4:n,c;for(c=0;c<p;c+=4)e=Y[t.charCodeAt(c)]<<18|Y[t.charCodeAt(c+1)]<<12|Y[t.charCodeAt(c+2)]<<6|Y[t.charCodeAt(c+3)],i[s++]=e>>16&255,i[s++]=e>>8&255,i[s++]=e&255;return o===2&&(e=Y[t.charCodeAt(c)]<<2|Y[t.charCodeAt(c+1)]>>4,i[s++]=e&255),o===1&&(e=Y[t.charCodeAt(c)]<<10|Y[t.charCodeAt(c+1)]<<4|Y[t.charCodeAt(c+2)]>>2,i[s++]=e>>8&255,i[s++]=e&255),i}function sn(t){return ie[t>>18&63]+ie[t>>12&63]+ie[t>>6&63]+ie[t&63]}function an(t,e,r){for(var n,o=[],i=e;i<r;i+=3)n=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(t[i+2]&255),o.push(sn(n));return o.join("")}function un(t){for(var e,r=t.length,n=r%3,o=[],i=16383,s=0,p=r-n;s<p;s+=i)o.push(an(t,s,s+i>p?p:s+i));return n===1?(e=t[r-1],o.push(ie[e>>2]+ie[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(ie[e>>10]+ie[e>>4&63]+ie[e<<2&63]+"=")),o.join("")}});var Hr=$e(pr=>{a();pr.read=function(t,e,r,n,o){var i,s,p=o*8-n-1,c=(1<<p)-1,g=c>>1,h=-7,y=r?o-1:0,P=r?-1:1,b=t[e+y];for(y+=P,i=b&(1<<-h)-1,b>>=-h,h+=p;h>0;i=i*256+t[e+y],y+=P,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=n;h>0;s=s*256+t[e+y],y+=P,h-=8);if(i===0)i=1-g;else{if(i===c)return s?NaN:(b?-1:1)*(1/0);s=s+Math.pow(2,n),i=i-g}return(b?-1:1)*s*Math.pow(2,i-n)};pr.write=function(t,e,r,n,o,i){var s,p,c,g=i*8-o-1,h=(1<<g)-1,y=h>>1,P=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,b=n?0:i-1,w=n?1:-1,D=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(p=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),s+y>=1?e+=P/c:e+=P*Math.pow(2,1-y),e*c>=2&&(s++,c/=2),s+y>=h?(p=0,s=h):s+y>=1?(p=(e*c-1)*Math.pow(2,o),s=s+y):(p=e*Math.pow(2,y-1)*Math.pow(2,o),s=0));o>=8;t[r+b]=p&255,b+=w,p/=256,o-=8);for(s=s<<o|p,g+=o;g>0;t[r+b]=s&255,b+=w,s/=256,g-=8);t[r+b-w]|=D*128}});var st=$e(Se=>{"use strict";a();var cr=qr(),Ae=Hr(),jr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;Se.Buffer=u;Se.SlowBuffer=hn;Se.INSPECT_MAX_BYTES=50;var Ge=2147483647;Se.kMaxLength=Ge;u.TYPED_ARRAY_SUPPORT=pn();!u.TYPED_ARRAY_SUPPORT&&typeof console!="undefined"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function pn(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),t.foo()===42}catch(r){return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(!!u.isBuffer(this))return this.buffer}});Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(!!u.isBuffer(this))return this.byteOffset}});function fe(t){if(t>Ge)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(t,e,r){if(typeof t=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return hr(t)}return Yr(t,e,r)}u.poolSize=8192;function Yr(t,e,r){if(typeof t=="string")return fn(t,e);if(ArrayBuffer.isView(t))return ln(t);if(t==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(se(t,ArrayBuffer)||t&&se(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(se(t,SharedArrayBuffer)||t&&se(t.buffer,SharedArrayBuffer)))return lr(t,e,r);if(typeof t=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(n!=null&&n!==t)return u.from(n,e,r);var o=mn(t);if(o)return o;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return u.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}u.from=function(t,e,r){return Yr(t,e,r)};Object.setPrototypeOf(u.prototype,Uint8Array.prototype);Object.setPrototypeOf(u,Uint8Array);function Zr(t){if(typeof t!="number")throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function cn(t,e,r){return Zr(t),t<=0?fe(t):e!==void 0?typeof r=="string"?fe(t).fill(e,r):fe(t).fill(e):fe(t)}u.alloc=function(t,e,r){return cn(t,e,r)};function hr(t){return Zr(t),fe(t<0?0:dr(t)|0)}u.allocUnsafe=function(t){return hr(t)};u.allocUnsafeSlow=function(t){return hr(t)};function fn(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=Jr(t,e)|0,n=fe(r),o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}function fr(t){for(var e=t.length<0?0:dr(t.length)|0,r=fe(e),n=0;n<e;n+=1)r[n]=t[n]&255;return r}function ln(t){if(se(t,Uint8Array)){var e=new Uint8Array(t);return lr(e.buffer,e.byteOffset,e.byteLength)}return fr(t)}function lr(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return e===void 0&&r===void 0?n=new Uint8Array(t):r===void 0?n=new Uint8Array(t,e):n=new Uint8Array(t,e,r),Object.setPrototypeOf(n,u.prototype),n}function mn(t){if(u.isBuffer(t)){var e=dr(t.length)|0,r=fe(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||yr(t.length)?fe(0):fr(t);if(t.type==="Buffer"&&Array.isArray(t.data))return fr(t.data)}function dr(t){if(t>=Ge)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ge.toString(16)+" bytes");return t|0}function hn(t){return+t!=t&&(t=0),u.alloc(+t)}u.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==u.prototype};u.compare=function(e,r){if(se(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),se(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),!u.isBuffer(e)||!u.isBuffer(r))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===r)return 0;for(var n=e.length,o=r.length,i=0,s=Math.min(n,o);i<s;++i)if(e[i]!==r[i]){n=e[i],o=r[i];break}return n<o?-1:o<n?1:0};u.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};u.concat=function(e,r){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return u.alloc(0);var n;if(r===void 0)for(r=0,n=0;n<e.length;++n)r+=e[n].length;var o=u.allocUnsafe(r),i=0;for(n=0;n<e.length;++n){var s=e[n];if(se(s,Uint8Array))i+s.length>o.length?u.from(s).copy(o,i):Uint8Array.prototype.set.call(o,s,i);else if(u.isBuffer(s))s.copy(o,i);else throw new TypeError('"list" argument must be an Array of Buffers');i+=s.length}return o};function Jr(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||se(t,ArrayBuffer))return t.byteLength;if(typeof t!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&r===0)return 0;for(var o=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return mr(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return it(t).length;default:if(o)return n?-1:mr(t).length;e=(""+e).toLowerCase(),o=!0}}u.byteLength=Jr;function dn(t,e,r){var n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,e>>>=0,r<=e))return"";for(t||(t="utf8");;)switch(t){case"hex":return kn(this,e,r);case"utf8":case"utf-8":return rt(this,e,r);case"ascii":return An(this,e,r);case"latin1":case"binary":return Sn(this,e,r);case"base64":return In(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Fn(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}u.prototype._isBuffer=!0;function ge(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}u.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<e;r+=2)ge(this,r,r+1);return this};u.prototype.swap32=function(){var e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<e;r+=4)ge(this,r,r+3),ge(this,r+1,r+2);return this};u.prototype.swap64=function(){var e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<e;r+=8)ge(this,r,r+7),ge(this,r+1,r+6),ge(this,r+2,r+5),ge(this,r+3,r+4);return this};u.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?rt(this,0,e):dn.apply(this,arguments)};u.prototype.toLocaleString=u.prototype.toString;u.prototype.equals=function(e){if(!u.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:u.compare(this,e)===0};u.prototype.inspect=function(){var e="",r=Se.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};jr&&(u.prototype[jr]=u.prototype.inspect);u.prototype.compare=function(e,r,n,o,i){if(se(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(r===void 0&&(r=0),n===void 0&&(n=e?e.length:0),o===void 0&&(o=0),i===void 0&&(i=this.length),r<0||n>e.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&r>=n)return 0;if(o>=i)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,o>>>=0,i>>>=0,this===e)return 0;for(var s=i-o,p=n-r,c=Math.min(s,p),g=this.slice(o,i),h=e.slice(r,n),y=0;y<c;++y)if(g[y]!==h[y]){s=g[y],p=h[y];break}return s<p?-1:p<s?1:0};function et(t,e,r,n,o){if(t.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,yr(r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0)if(o)r=0;else return-1;if(typeof e=="string"&&(e=u.from(e,n)),u.isBuffer(e))return e.length===0?-1:Kr(t,e,r,n,o);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):Kr(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function Kr(t,e,r,n,o){var i=1,s=t.length,p=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||e.length<2)return-1;i=2,s/=2,p/=2,r/=2}function c(b,w){return i===1?b[w]:b.readUInt16BE(w*i)}var g;if(o){var h=-1;for(g=r;g<s;g++)if(c(t,g)===c(e,h===-1?0:g-h)){if(h===-1&&(h=g),g-h+1===p)return h*i}else h!==-1&&(g-=g-h),h=-1}else for(r+p>s&&(r=s-p),g=r;g>=0;g--){for(var y=!0,P=0;P<p;P++)if(c(t,g+P)!==c(e,P)){y=!1;break}if(y)return g}return-1}u.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};u.prototype.indexOf=function(e,r,n){return et(this,e,r,n,!0)};u.prototype.lastIndexOf=function(e,r,n){return et(this,e,r,n,!1)};function yn(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n),n>o&&(n=o)):n=o;var i=e.length;n>i/2&&(n=i/2);for(var s=0;s<n;++s){var p=parseInt(e.substr(s*2,2),16);if(yr(p))return s;t[r+s]=p}return s}function Tn(t,e,r,n){return Qe(mr(e,t.length-r),t,r,n)}function gn(t,e,r,n){return Qe(Pn(e),t,r,n)}function xn(t,e,r,n){return Qe(it(e),t,r,n)}function wn(t,e,r,n){return Qe(Un(e,t.length-r),t,r,n)}u.prototype.write=function(e,r,n,o){if(r===void 0)o="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")o=r,n=this.length,r=0;else if(isFinite(r))r=r>>>0,isFinite(n)?(n=n>>>0,o===void 0&&(o="utf8")):(o=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var i=this.length-r;if((n===void 0||n>i)&&(n=i),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");for(var s=!1;;)switch(o){case"hex":return yn(this,e,r,n);case"utf8":case"utf-8":return Tn(this,e,r,n);case"ascii":case"latin1":case"binary":return gn(this,e,r,n);case"base64":return xn(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return wn(this,e,r,n);default:if(s)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),s=!0}};u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function In(t,e,r){return e===0&&r===t.length?cr.fromByteArray(t):cr.fromByteArray(t.slice(e,r))}function rt(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i=t[o],s=null,p=i>239?4:i>223?3:i>191?2:1;if(o+p<=r){var c,g,h,y;switch(p){case 1:i<128&&(s=i);break;case 2:c=t[o+1],(c&192)===128&&(y=(i&31)<<6|c&63,y>127&&(s=y));break;case 3:c=t[o+1],g=t[o+2],(c&192)===128&&(g&192)===128&&(y=(i&15)<<12|(c&63)<<6|g&63,y>2047&&(y<55296||y>57343)&&(s=y));break;case 4:c=t[o+1],g=t[o+2],h=t[o+3],(c&192)===128&&(g&192)===128&&(h&192)===128&&(y=(i&15)<<18|(c&63)<<12|(g&63)<<6|h&63,y>65535&&y<1114112&&(s=y))}}s===null?(s=65533,p=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),o+=p}return En(n)}var Xr=4096;function En(t){var e=t.length;if(e<=Xr)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Xr));return r}function An(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]&127);return n}function Sn(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function kn(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=Bn[t[i]];return o}function Fn(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length-1;i+=2)o+=String.fromCharCode(n[i]+n[i+1]*256);return o}u.prototype.slice=function(e,r){var n=this.length;e=~~e,r=r===void 0?n:~~r,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<e&&(r=e);var o=this.subarray(e,r);return Object.setPrototypeOf(o,u.prototype),o};function $(t,e,r){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||$(e,r,this.length);for(var o=this[e],i=1,s=0;++s<r&&(i*=256);)o+=this[e+s]*i;return o};u.prototype.readUintBE=u.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||$(e,r,this.length);for(var o=this[e+--r],i=1;r>0&&(i*=256);)o+=this[e+--r]*i;return o};u.prototype.readUint8=u.prototype.readUInt8=function(e,r){return e=e>>>0,r||$(e,1,this.length),this[e]};u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||$(e,2,this.length),this[e]|this[e+1]<<8};u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||$(e,2,this.length),this[e]<<8|this[e+1]};u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||$(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};u.prototype.readUint32BE=u.prototype.readUInt32BE=function(e,r){return e=e>>>0,r||$(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readIntLE=function(e,r,n){e=e>>>0,r=r>>>0,n||$(e,r,this.length);for(var o=this[e],i=1,s=0;++s<r&&(i*=256);)o+=this[e+s]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*r)),o};u.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||$(e,r,this.length);for(var o=r,i=1,s=this[e+--o];o>0&&(i*=256);)s+=this[e+--o]*i;return i*=128,s>=i&&(s-=Math.pow(2,8*r)),s};u.prototype.readInt8=function(e,r){return e=e>>>0,r||$(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};u.prototype.readInt16LE=function(e,r){e=e>>>0,r||$(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};u.prototype.readInt16BE=function(e,r){e=e>>>0,r||$(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};u.prototype.readInt32LE=function(e,r){return e=e>>>0,r||$(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function(e,r){return e=e>>>0,r||$(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readFloatLE=function(e,r){return e=e>>>0,r||$(e,4,this.length),Ae.read(this,e,!0,23,4)};u.prototype.readFloatBE=function(e,r){return e=e>>>0,r||$(e,4,this.length),Ae.read(this,e,!1,23,4)};u.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||$(e,8,this.length),Ae.read(this,e,!0,52,8)};u.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||$(e,8,this.length),Ae.read(this,e,!1,52,8)};function j(t,e,r,n,o,i){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(e,r,n,o){if(e=+e,r=r>>>0,n=n>>>0,!o){var i=Math.pow(2,8*n)-1;j(this,e,r,n,i,0)}var s=1,p=0;for(this[r]=e&255;++p<n&&(s*=256);)this[r+p]=e/s&255;return r+n};u.prototype.writeUintBE=u.prototype.writeUIntBE=function(e,r,n,o){if(e=+e,r=r>>>0,n=n>>>0,!o){var i=Math.pow(2,8*n)-1;j(this,e,r,n,i,0)}var s=n-1,p=1;for(this[r+s]=e&255;--s>=0&&(p*=256);)this[r+s]=e/p&255;return r+n};u.prototype.writeUint8=u.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,1,255,0),this[r]=e&255,r+1};u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,2,65535,0),this[r]=e&255,this[r+1]=e>>>8,r+2};u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,2,65535,0),this[r]=e>>>8,this[r+1]=e&255,r+2};u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,4,4294967295,0),this[r+3]=e>>>24,this[r+2]=e>>>16,this[r+1]=e>>>8,this[r]=e&255,r+4};u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,4,4294967295,0),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};u.prototype.writeIntLE=function(e,r,n,o){if(e=+e,r=r>>>0,!o){var i=Math.pow(2,8*n-1);j(this,e,r,n,i-1,-i)}var s=0,p=1,c=0;for(this[r]=e&255;++s<n&&(p*=256);)e<0&&c===0&&this[r+s-1]!==0&&(c=1),this[r+s]=(e/p>>0)-c&255;return r+n};u.prototype.writeIntBE=function(e,r,n,o){if(e=+e,r=r>>>0,!o){var i=Math.pow(2,8*n-1);j(this,e,r,n,i-1,-i)}var s=n-1,p=1,c=0;for(this[r+s]=e&255;--s>=0&&(p*=256);)e<0&&c===0&&this[r+s+1]!==0&&(c=1),this[r+s]=(e/p>>0)-c&255;return r+n};u.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,1,127,-128),e<0&&(e=255+e+1),this[r]=e&255,r+1};u.prototype.writeInt16LE=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,2,32767,-32768),this[r]=e&255,this[r+1]=e>>>8,r+2};u.prototype.writeInt16BE=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,2,32767,-32768),this[r]=e>>>8,this[r+1]=e&255,r+2};u.prototype.writeInt32LE=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,4,2147483647,-2147483648),this[r]=e&255,this[r+1]=e>>>8,this[r+2]=e>>>16,this[r+3]=e>>>24,r+4};u.prototype.writeInt32BE=function(e,r,n){return e=+e,r=r>>>0,n||j(this,e,r,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[r]=e>>>24,this[r+1]=e>>>16,this[r+2]=e>>>8,this[r+3]=e&255,r+4};function tt(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function nt(t,e,r,n,o){return e=+e,r=r>>>0,o||tt(t,e,r,4,34028234663852886e22,-34028234663852886e22),Ae.write(t,e,r,n,23,4),r+4}u.prototype.writeFloatLE=function(e,r,n){return nt(this,e,r,!0,n)};u.prototype.writeFloatBE=function(e,r,n){return nt(this,e,r,!1,n)};function ot(t,e,r,n,o){return e=+e,r=r>>>0,o||tt(t,e,r,8,17976931348623157e292,-17976931348623157e292),Ae.write(t,e,r,n,52,8),r+8}u.prototype.writeDoubleLE=function(e,r,n){return ot(this,e,r,!0,n)};u.prototype.writeDoubleBE=function(e,r,n){return ot(this,e,r,!1,n)};u.prototype.copy=function(e,r,n,o){if(!u.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!o&&o!==0&&(o=this.length),r>=e.length&&(r=e.length),r||(r=0),o>0&&o<n&&(o=n),o===n||e.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),e.length-r<o-n&&(o=e.length-r+n);var i=o-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(r,n,o):Uint8Array.prototype.set.call(e,this.subarray(n,o),r),i};u.prototype.fill=function(e,r,n,o){if(typeof e=="string"){if(typeof r=="string"?(o=r,r=0,n=this.length):typeof n=="string"&&(o=n,n=this.length),o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!u.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(e.length===1){var i=e.charCodeAt(0);(o==="utf8"&&i<128||o==="latin1")&&(e=i)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);var s;if(typeof e=="number")for(s=r;s<n;++s)this[s]=e;else{var p=u.isBuffer(e)?e:u.from(e,o),c=p.length;if(c===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-r;++s)this[s+r]=p[s%c]}return this};var bn=/[^+/0-9A-Za-z-_]/g;function Dn(t){if(t=t.split("=")[0],t=t.trim().replace(bn,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function mr(t,e){e=e||1/0;for(var r,n=t.length,o=null,i=[],s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function Pn(t){for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function Un(t,e){for(var r,n,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}function it(t){return cr.toByteArray(Dn(t))}function Qe(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function se(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function yr(t){return t!==t}var Bn=function(){for(var t="0123456789abcdef",e=new Array(256),r=0;r<16;++r)for(var n=r*16,o=0;o<16;++o)e[n+o]=t[r]+t[o];return e}()});var ft=$e((ho,ct)=>{a();var L=ct.exports={},ae,ue;function Tr(){throw new Error("setTimeout has not been defined")}function gr(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?ae=setTimeout:ae=Tr}catch(t){ae=Tr}try{typeof clearTimeout=="function"?ue=clearTimeout:ue=gr}catch(t){ue=gr}})();function at(t){if(ae===setTimeout)return setTimeout(t,0);if((ae===Tr||!ae)&&setTimeout)return ae=setTimeout,setTimeout(t,0);try{return ae(t,0)}catch(e){try{return ae.call(null,t,0)}catch(r){return ae.call(this,t,0)}}}function vn(t){if(ue===clearTimeout)return clearTimeout(t);if((ue===gr||!ue)&&clearTimeout)return ue=clearTimeout,clearTimeout(t);try{return ue(t)}catch(e){try{return ue.call(null,t)}catch(r){return ue.call(this,t)}}}var le=[],ke=!1,xe,We=-1;function On(){!ke||!xe||(ke=!1,xe.length?le=xe.concat(le):We=-1,le.length&&ut())}function ut(){if(!ke){var t=at(On);ke=!0;for(var e=le.length;e;){for(xe=le,le=[];++We<e;)xe&&xe[We].run();We=-1,e=le.length}xe=null,ke=!1,vn(t)}}L.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];le.push(new pt(t,e)),le.length===1&&!ke&&at(ut)};function pt(t,e){this.fun=t,this.array=e}pt.prototype.run=function(){this.fun.apply(null,this.array)};L.title="browser";L.browser=!0;L.env={};L.argv=[];L.version="";L.versions={};function me(){}L.on=me;L.addListener=me;L.once=me;L.off=me;L.removeListener=me;L.removeAllListeners=me;L.emit=me;L.prependListener=me;L.prependOnceListener=me;L.listeners=function(t){return[]};L.binding=function(t){throw new Error("process.binding is not supported")};L.cwd=function(){return"/"};L.chdir=function(t){throw new Error("process.chdir is not supported")};L.umask=function(){return 0}});var f,l,yo,a=Zt(()=>{f=te(st()),l=te(ft()),yo=function(t){function e(){var n=this||self;return delete t.prototype.__magic__,n}if(typeof globalThis=="object")return globalThis;if(this)return e();t.defineProperty(t.prototype,"__magic__",{configurable:!0,get:e});var r=__magic__;return r}(Object)});var po={};Jt(po,{useFetchMaintenanceFlag:()=>uo,useFilteredTokens:()=>so,useInputAmountUsdValue:()=>Lr,useIntersectionObserver:()=>Cr,useIsPageVisible:()=>vr,useLazyQueryWrapper:()=>he,usePrevious:()=>Nr,useQueryWrapper:()=>Ee,useRateCalculator:()=>Br,useSwapFormHandlers:()=>ao,useSwapInfo:()=>Kn,useSwapRoute:()=>Yn,useTokens:()=>Hn,useUnwrapEgld:()=>Zn,useWrapEgld:()=>jn});module.exports=en(po);a();a();var Ue=require("react");a();a();var Cn=te(require("react")),ze=require("@apollo/client"),Rn=require("@apollo/client/link/context"),Ln=require("@apollo/client/link/error"),Nn=require("graphql");a();a();var Ve=require("react"),lt=(0,Ve.createContext)({accessToken:"",isAuthenticated:!1}),W=()=>{let t=(0,Ve.useContext)(lt);if(t==null)throw new Error("useAuthorizationContext must be used within a AuthorizationProvider");return t};a();a();a();var K=` balance decimals name identifier ticker owner assets { website description status pngUrl svgUrl } price type previous24hPrice previous7dPrice `;a();a();a();var qe=` assets { website description status pngUrl svgUrl } decimals name collection ticker `;var mt=` address lockedToken { ${qe} } lpProxyToken { ${qe} } farmProxyToken { ${qe} } intermediatedPairs intermediatedFarms `;var ht=` address firstToken { ${K} } secondToken { ${K} } type feesAPR totalFeePercent specialFeePercent lockedTokensInfo { lockingSC { ${mt} } unlockEpoch } `;a();var Fe=` value receiver gasPrice gasLimit data chainID version `;a();var Ce=` defaultSlippage slippageValues minSlippage maxSlippage minSwapAmount `;a();var _n=` __typename valueUSD `,xr=` ${K} ${_n} `;a();a();var wr=require("@apollo/client");var Ir="TRANSACTIONS_PLACEHOLDER",$n=` transactions { ${Fe} } `,dt=` query swapPackageSwapRoute ( $amountIn: String $amountOut: String $tokenInID: String! $tokenOutID: String! $tolerance: Float! ) { swap( amountIn: $amountIn amountOut: $amountOut tokenInID: $tokenInID tokenOutID: $tokenOutID tolerance: $tolerance ) { amountIn tokenInID tokenInPriceUSD tokenInExchangeRateDenom amountOut tokenOutID tokenOutPriceUSD tokenOutExchangeRateDenom fees swapType tokenRoute pricesImpact maxPriceDeviationPercent tokensPriceDeviationPercent intermediaryAmounts pairs { ${ht} } ${Ir} } } `,yt=wr.gql` ${dt.replace(Ir,$n)} `,Tt=wr.gql` ${dt.replace(Ir,"")} `;a();a();var Re=require("@apollo/client");var gt=Re.gql` query swapPackageTokens ($identifiers: [String!], $enabledSwaps: Boolean) { tokens(identifiers: $identifiers, enabledSwaps: $enabledSwaps) { ${K} } wrappingInfo { wrappedToken { ${K} } } factory { ${Ce} } } `,xt=Re.gql` query swapPackageFilteredTokens ($enabledSwaps: Boolean, $pagination: ConnectionArgs, $searchInput: String, $identifiers: [String!]) { filteredTokens (pagination: $pagination, filters: {searchToken: $searchInput, enabledSwaps: $enabledSwaps, identifiers: $identifiers}) { edges { node { ${K} } cursor } pageInfo { hasNextPage } pageData { count } } wrappingInfo { wrappedToken { ${K} } } factory { ${Ce} } } `,wt=Re.gql` query swapPackageTokensWithBalance ($identifiers: [String!], $offset: Int, $limit: Int, $enabledSwaps: Boolean) { tokens(identifiers: $identifiers, enabledSwaps: $enabledSwaps) { ${K} } userTokens (offset: $offset, limit: $limit) { ${xr} } wrappingInfo { wrappedToken { ${K} } } factory { ${Ce} } } `,It=Re.gql` query swapPackageFilteredTokensWithBalance ($identifiers: [String!], $pagination: ConnectionArgs, $searchInput: String, $offset: Int, $limit: Int, $enabledSwaps: Boolean) { filteredTokens (pagination: $pagination, filters: {searchToken: $searchInput, enabledSwaps: $enabledSwaps, identifiers: $identifiers}) { edges { node { ${K} } cursor } pageInfo { hasNextPage } pageData { count } } userTokens (offset: $offset, limit: $limit) { ${xr} } wrappingInfo { wrappedToken { ${K} } } factory { ${Ce} } } `;a();a();var Et=require("@apollo/client");var He=Et.gql` query swapPackageWrapEgld ($wrappingAmount: String!) { wrapEgld(amount: $wrappingAmount) { ${Fe} } } `;a();var At=require("@apollo/client");var je=At.gql` query swapPackageUnwrapEgld ($wrappingAmount: String!) { unwrapEgld(amount: $wrappingAmount) { ${Fe} } } `;a();a();var St=require("@apollo/client"),kt=St.gql` query swapPackageMaintenance { factory { maintenance } } `;a();a();var Le=te(require("bignumber.js"));a();a();var ne="EGLD";var Ft="10000000000000000";a();a();var N=require("@multiversx/sdk-core");a();a();var M=require("@multiversx/sdk-dapp/out/constants");a();var Mn=require("@multiversx/sdk-dapp/out/types/enums.types");a();var Er=require("@multiversx/sdk-dapp/out/utils/decoders/base64Utils");a();var Ar=require("@multiversx/sdk-dapp/out/store/store"),Sr=require("@multiversx/sdk-dapp/out/store/selectors/accountSelectors");a();var Ke=require("@multiversx/sdk-dapp-utils/out/constants"),we=require("@multiversx/sdk-dapp-utils/out/helpers/formatAmount"),pe=require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount"),be=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsFloat"),kr=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsInteger");var bt=(t,e=4)=>{if(!(0,be.stringIsFloat)(t)||new Le.default(t).isZero())return"0";let n=new Le.default(t).toFormat(e);return n=parseFloat(n)>0?n:new Le.default(t).toFormat(e+4),parseFloat(n)>0?n:new Le.default(t).toFormat(e+9)};a();var Xe=t=>t.replace(/,/g,"");a();a();var Fr=(t,e)=>{let r=new Map;return t==null||t.forEach(n=>{r.set(n.identifier,G(R({},n),{balance:"0",valueUSD:"0"}))}),e==null||e.forEach(n=>{var i,s;let o=r.get(n.identifier);o?r.set(n.identifier,G(R({},o),{balance:(i=n.balance)!=null?i:"0",valueUSD:(s=n.valueUSD)!=null?s:"0"})):n.type!=="FungibleESDT-LP"&&r.set(n.identifier,n)}),Array.from(r.values())};a();var Ye=({pairs:t,identifier:e})=>{var o;if(e===ne||e.startsWith(`W${ne}-`))return Ke.DECIMALS;let n;return t.forEach(({firstToken:i,secondToken:s})=>{if(i.identifier===e){n=i;return}if(s.identifier===e){n=s;return}}),(o=n==null?void 0:n.decimals)!=null?o:0};a();var Dt=te(require("bignumber.js")),Gn={burn:void 0,feesAPR:void 0,totalFee:void 0,lpHolders:void 0},Pt=t=>{if(!t)return Gn;let{totalFeePercent:e,specialFeePercent:r,feesAPR:n}=t,o=e*100,i=r*100,p=(e-r)*100,c=new Dt.default(n).multipliedBy(100).toNumber();return{totalFee:o,burn:i,lpHolders:p,feesAPR:c}};a();a();var Ut=t=>{var b,w;let{data:e,value:r,receiver:n,sender:o,gasLimit:i,gasPrice:s,chainID:p,version:c,options:g}=t,{address:h}=(0,Sr.accountSelector)((0,Ar.getStore)().getState()),y=e?(0,Er.isStringBase64)(e)?f.Buffer.from(e,"base64"):f.Buffer.from(e.trim()):void 0,P=new N.Transaction({value:BigInt(r),data:y,receiver:new N.Address(n),sender:new N.Address(o&&o!==""?o:h),gasLimit:BigInt((b=i.valueOf())!=null?b:M.GAS_LIMIT),gasPrice:BigInt((w=s.valueOf())!=null?w:M.GAS_PRICE),chainID:p.valueOf(),version:new N.TransactionVersion(c!=null?c:M.VERSION).valueOf()});return g&&(P.options=new N.TransactionOptions(g).valueOf()),P};var Bt=t=>{let e=Ut(t),r=new N.NetworkConfig;r.minGasLimit=BigInt(M.GAS_LIMIT),r.gasPerDataByte=BigInt(M.GAS_PER_DATA_BYTE),r.gasPriceModifier=M.GAS_PRICE_MODIFIER;try{return new N.TransactionComputer().computeTransactionFee(e,r).toString(10)}catch(n){return 0}};a();a();a();a();a();a();a();a();a();a();a();var Ot=({firstTokenId:t,secondTokenId:e,wrappedEgld:r})=>{if(!t||!e||!r)return;let n=t===ne&&e===(r==null?void 0:r.identifier),o=t===(r==null?void 0:r.identifier)&&e===ne;return n?"wrap":o?"unwrap":"swap"};a();var Ct={"Multi swap disabled!":"Smart Swaps are temporarily disabled. We suggest using an alternative route to perform the token swap.","Spread too big!":"Smart Swap not possible because you would lose more than 5%."},br=t=>{if(!t)return;let e="No trade route found.",r=Object.keys(Ct).find(n=>t.includes(n));return r?Ct[r]:e};a();var Dr=te(require("bignumber.js"));var Rt=t=>{let e=new Dr.default(t!=null?t:"0"),r=new Dr.default(Ft),n=e.minus(r);return n.isGreaterThan(0)?n.toString(10):"0"};a();var Ie=({amount:t="0",decimals:e=0,digits:r=4,addCommas:n=!1,showLastNonZeroDecimal:o=!1})=>{if(t==null||!(0,kr.stringIsInteger)(t))return"0";let i=p=>(0,we.formatAmount)({decimals:e,addCommas:n,input:t,digits:p,showLastNonZeroDecimal:o}),s=i(r);return s=parseFloat(s)>0?s:i(4+4),s=parseFloat(s)>0?s:i(4+9),parseFloat(s)>0?s:i(4+14)};a();var Ze=te(require("bignumber.js"));var Lt=({tolerance:t,secondAmount:e,isFixedOutput:r,swapActionType:n,secondTokenDecimals:o})=>{if(!e)return;if(r||n!=="swap")return e;let i=new Ze.default((0,pe.parseAmount)(e,o)),s=new Ze.default(1).dividedBy(new Ze.default(t).dividedBy(100).plus(1)).times(i).toFixed(0);return(0,we.formatAmount)({input:s,decimals:o})};a();var Nt=te(require("bignumber.js"));var Je=({tokens:t,wrappedEgld:e})=>t.sort((r,n)=>r.identifier===ne?-1:n.identifier===ne?1:r.identifier===(e==null?void 0:e.identifier)?-1:n.identifier===(e==null?void 0:e.identifier)?1:new Nt.default(n.valueUSD).minus(r.valueUSD).toNumber());a();var Pr=te(require("bignumber.js"));var _t=t=>t==null?void 0:t.reduce((e,r)=>{var o;let n=new Pr.default((o=Bt(r))!=null?o:"0");return e.plus(n)},new Pr.default("0")).toString(10);a();var Ur=({newToken:t,firstToken:e,secondToken:r,activeRoute:n,needsParsing:o})=>{if(!n||!t)return{amountIn:void 0,amountOut:void 0};let i=(n==null?void 0:n.swapType)===0,s=i?n==null?void 0:n.amountIn:n==null?void 0:n.amountOut,c=(i?n==null?void 0:n.tokenInID:n==null?void 0:n.tokenOutID)===(e==null?void 0:e.identifier)?e==null?void 0:e.decimals:r==null?void 0:r.decimals,g=Ie({amount:s,showLastNonZeroDecimal:!0,decimals:c}),h=o?(0,pe.parseAmount)(g,t==null?void 0:t.decimals):s;return{amountIn:i?h:void 0,amountOut:i?void 0:h}};a();var $t=require("@apollo/client");var er=({skip:t=!1,isPollingEnabled:e=!1})=>{let r=$t.gql` query swapPackageTokenPrices { tokens(enabledSwaps: true) { price identifier } } `,{data:n,isError:o,isLoading:i}=Ee({isPollingEnabled:e,query:r,queryOptions:{skip:t}});return{tokenPrices:n==null?void 0:n.tokens,isTokenPricesError:o,isTokenPricesLoading:i}};a();var rr=require("react");var he=({query:t,queryOptions:e})=>{let{client:r}=W(),[n,o]=(0,rr.useState)(),[i,s]=(0,rr.useState)(),[p,c]=(0,rr.useState)();return{isLoading:n,isError:i,error:p,execute:h=>ar(void 0,null,function*(){var b,w;let y=(b=h==null?void 0:h.onCompleted)!=null?b:e==null?void 0:e.onCompleted,P=(w=h==null?void 0:h.variables)!=null?w:e==null?void 0:e.variables;try{o(!0);let D=yield r==null?void 0:r.query({query:t,variables:P}),_=D==null?void 0:D.data,d=D==null?void 0:D.errors;return d&&d.length>0&&(s(!0),c(d[0].message)),_&&(s(!1),c(void 0),y==null||y(_)),o(!1),_}catch(D){o(!1),s(!0),console.error(D);return}})}};var Qn=0,Wn=500,Vn=!0,zn=!1,qn=[],Hn=t=>{var d;let{client:e,isAuthenticated:r}=W();if(!e)throw new Error("Swap GraphQL client not initialized");let n=(d=t==null?void 0:t.pricePolling)!=null?d:zn,[o,i]=(0,Ue.useState)([]),[s,p]=(0,Ue.useState)(),[c,g]=(0,Ue.useState)(),{tokenPrices:h}=er({isPollingEnabled:n}),y=T=>{if(!T)return;let{tokens:I,wrappingInfo:x,userTokens:E,factory:A}=T;A&&g(A);let S=x&&x.length?x[0].wrappedToken:void 0;if(p(S),!I){i([]);return}let B=I.map(k=>{var O,z;let U=E==null?void 0:E.find(({identifier:q})=>q===k.identifier);return G(R({},k),{balance:(O=U==null?void 0:U.balance)!=null?O:"0",valueUSD:(z=U==null?void 0:U.valueUSD)!=null?z:"0"})}),v=Je({tokens:B,wrappedEgld:S});i(v)},{isError:P,isLoading:b,execute:w}=he({query:r?wt:gt,queryOptions:{client:e,onCompleted:y}}),D=T=>{var x,E,A,S;let I={limit:(x=T==null?void 0:T.limit)!=null?x:Wn,offset:(E=T==null?void 0:T.offset)!=null?E:Qn,identifiers:(A=T==null?void 0:T.identifiers)!=null?A:qn,enabledSwaps:(S=T==null?void 0:T.enabledSwaps)!=null?S:Vn};w({variables:I})},_=(0,Ue.useMemo)(()=>o.map(T=>{var x;let I=(x=h==null?void 0:h.find(({identifier:E})=>E===T.identifier))==null?void 0:x.price;return G(R({},T),{price:I!=null?I:T.price})}),[o,h]);return{swapConfig:c,wrappedEgld:s,isTokensError:P,isTokensLoading:b,tokens:_,getTokens:D,refetch:w}};a();var jn=()=>{let{client:t}=W();if(!t)throw new Error("Swap GraphQL client not initialized");let{execute:e,isLoading:r}=he({query:He,queryOptions:{client:t}});return{wrapEgld:e,isWrapEgldLoading:r}};a();var ce=require("react"),Mt=te(require("bignumber.js"));a();var Z=require("react"),Br=({activeRoute:t})=>{let[e,r]=(0,Z.useState)("normal"),[n,o]=(0,Z.useState)(),[i,s]=(0,Z.useState)(),[p,c]=(0,Z.useState)(),[g,h]=(0,Z.useState)(),[y,P]=(0,Z.useState)(),[b,w]=(0,Z.useState)(),[D,_]=(0,Z.useState)(),[d,T]=(0,Z.useState)(),I=()=>{if(!t)return;let{tokenInID:E,tokenOutID:A,tokenInExchangeRateDenom:S,tokenInPriceUSD:B,tokenOutExchangeRateDenom:v,tokenOutPriceUSD:k}=t;s(A),h(E),o(v),c(k),w(E),T(A),P(S),_(B)},x=()=>{r(E=>E==="normal"?"reverse":"normal")};return(0,Z.useEffect)(I,[t,e]),{tokenInId:e==="normal"?i:b,tokenInIdPriceUsd:e==="normal"?p:D,tokenOutId:e==="normal"?g:d,exchangeRate:e==="normal"?n:y,switchTokensDirection:x}};var Kn=({tolerance:t,activeRoute:e,firstToken:r,firstAmount:n,secondToken:o,secondAmount:i,swapActionType:s})=>{var O,z,q,Q;let[p,c]=(0,ce.useState)(),[g,h]=(0,ce.useState)(),[y,P]=(0,ce.useState)(),[b,w]=(0,ce.useState)(),[D,_]=(0,ce.useState)(),{tokenInId:d,tokenOutId:T,exchangeRate:I,switchTokensDirection:x}=Br({activeRoute:e}),E=(0,ce.useMemo)(()=>_t(e==null?void 0:e.transactions),[e==null?void 0:e.transactions]),A=Xe(I||""),S=Xe((z=(O=r==null?void 0:r.token)==null?void 0:O.price)!=null?z:""),B=Xe((Q=(q=o==null?void 0:o.token)==null?void 0:q.price)!=null?Q:""),v=d===(r==null?void 0:r.value)?B:S,k=new Mt.default(A||"0").multipliedBy(v||"0").toString(10);return(0,ce.useEffect)(()=>{if(!e)return;let{swapType:F,pairs:C}=e,X=Lt({tolerance:t,secondAmount:i,secondTokenDecimals:o==null?void 0:o.token.decimals,isFixedOutput:F===1,swapActionType:s}),H=[];C.forEach(de=>{let{totalFee:oe,burn:ye,lpHolders:nr}=Pt(de);!(C.length===1)&&oe&&H.push(`${oe}%`),_({totalFee:oe,burn:ye,lpHolders:nr})});let ee=n?e.pricesImpact:void 0,re=n?e.fees:void 0;c(X),h(re),w(ee),P(H)},[t,e,r,n,o,i,s]),{exchangeRate:I,feeDetails:D,feeAmounts:g,pricesImpact:b,feePercentages:y,tokenInId:d,tokenOutId:T,switchTokensDirection:x,totalTransactionsFee:E,minimumAmountReceived:p,exchangeRateUsdValue:k}};a();var J=require("react");a();var Ne=require("react"),Gt=require("@apollo/client");var Ee=({query:t,queryOptions:e,refetchTrigger:r,isPollingEnabled:n=!1,isRefetchEnabled:o=!1})=>{let i=vr(),{client:s}=W(),I=(0,Gt.useQuery)(t,R({client:s,notifyOnNetworkStatusChange:!0,fetchPolicy:"no-cache",nextFetchPolicy:"no-cache"},e)),{error:p,loading:c,previousData:g,data:h=g,refetch:y,stopPolling:P,startPolling:b}=I,w=Qr(I,["error","loading","previousData","data","refetch","stopPolling","startPolling"]),D=(0,Ne.useCallback)(()=>{i&&n&&!p?b(6e3):P()},[i,n,p,e]);(0,Ne.useEffect)(()=>(D(),()=>{P()}),[D]),(0,Ne.useEffect)(()=>{!o||r===0||(y(),D())},[r,o]);let _=h==null&&c,d=Boolean(p);return R({data:d?void 0:h,error:p,isError:d,isLoading:_,isRefetching:c,refetch:y},w)};var Yn=({wrappedEgld:t,isPollingEnabled:e=!1})=>{var B,v;let{client:r,isAuthenticated:n}=W();if(!r)throw new Error("Swap GraphQL client not initialized");let[o,i]=(0,J.useState)(),[s,p]=(0,J.useState)(),[c,g]=(0,J.useState)(),h=(0,J.useRef)(),y=(0,J.useMemo)(()=>Ot({firstTokenId:o==null?void 0:o.tokenInID,secondTokenId:o==null?void 0:o.tokenOutID,wrappedEgld:t}),[o,t]),P=(0,J.useMemo)(()=>y==="wrap"?He:y==="unwrap"?je:n?yt:Tt,[n,y]),b=(0,J.useMemo)(()=>{if(!o)return!0;let{amountIn:k,amountOut:U}=o;return!Boolean(k!=null?k:U)},[o]),{data:w,error:D,refetch:_,isRefetching:d,isLoading:T,isError:I}=Ee({query:P,queryOptions:{skip:b,client:r,variables:o},isPollingEnabled:e}),x=()=>{var k,U,O;if(!o){p(void 0),g(br(D==null?void 0:D.message));return}switch(y){case"wrap":case"unwrap":let z=w==null?void 0:w.wrapEgld,q=w==null?void 0:w.unwrapEgld,Q=z!=null?z:q,F=o.amountIn?0:1,C=(k=o.amountIn)!=null?k:o.amountOut,X={amountIn:C!=null?C:"0",tokenInID:o.tokenInID,tokenInPriceUSD:(U=t==null?void 0:t.price)!=null?U:"0",tokenInExchangeRateDenom:"1",maxPriceDeviationPercent:0,tokensPriceDeviationPercent:0,amountOut:C!=null?C:"0",tokenOutID:o.tokenOutID,tokenOutPriceUSD:(O=t==null?void 0:t.price)!=null?O:"0",tokenOutExchangeRateDenom:"1",fees:[],swapType:F,tokenRoute:[],pricesImpact:[],intermediaryAmounts:[],pairs:[],transactions:Q?[Q]:[]};g(void 0),p(X);break;default:let H=w==null?void 0:w.swap,ee=br(D==null?void 0:D.message);g(ee),p(ee?void 0:H)}},E=({amountIn:k,amountOut:U,tokenInID:O,tokenOutID:z,tolerancePercentage:q=1})=>{if(!k&&!U){i(void 0);return}let Q=q<0||q>100?1:q,F={wrappingAmount:k!=null?k:U,amountIn:k,amountOut:U,tokenInID:O,tokenOutID:z,tolerance:Q/100};i(F),h.current=F};(0,J.useEffect)(x,[w,D,o]);let A=Boolean((T||d)&&((B=h.current)==null?void 0:B.amountIn)),S=Boolean((T||d)&&((v=h.current)==null?void 0:v.amountOut));return{refetch:_,getSwapRoute:E,swapRoute:s,swapActionType:y,swapRouteError:c,isAmountInLoading:S,isAmountOutLoading:A,isSwapRouteError:I,isSwapRouteLoading:T,transactions:s==null?void 0:s.transactions,previousFetchVariables:h}};a();var Zn=()=>{let{client:t}=W();if(!t)throw new Error("Swap GraphQL client not initialized");let{execute:e,isLoading:r}=he({query:je,queryOptions:{client:t}});return{unwrapEgld:e,isUnwrapEgldLoading:r}};a();var Be=require("react"),Qt=()=>typeof document===void 0?!0:document.visibilityState==="visible",vr=()=>{let[t,e]=(0,Be.useState)(Qt()),r=(0,Be.useCallback)(()=>{e(Qt())},[e]);return(0,Be.useEffect)(()=>{if(typeof document!==void 0)return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[r]),t};a();var V=require("react");a();var Wt=require("react"),Cr=({tokens:t,hasMore:e,isLoading:r,observerId:n,loadedCursors:o,currentCursor:i,setPagination:s})=>{(0,Wt.useEffect)(()=>{if(!n)return;let p=document.getElementById(n);if(!p)return;let c=new IntersectionObserver(g=>{g[0].isIntersecting&&e&&!r&&i&&!o.has(i)&&s({first:20,after:i})},{threshold:1});return c.observe(p),()=>{c.disconnect()}},[t,n])};var Jn=0,eo=500,ro=!0,to=!1,no=[],oo={first:20,after:""},io="",so=t=>{var q,Q;let e=(0,V.useRef)(!0),{client:r,isAuthenticated:n}=W();if(!r)throw new Error("Swap GraphQL client not initialized");let o=(q=t==null?void 0:t.pricePolling)!=null?q:to,i=t==null?void 0:t.searchInput,[s,p]=(0,V.useState)({first:20,after:""}),[c,g]=(0,V.useState)(!0),[h,y]=(0,V.useState)(),[P,b]=(0,V.useState)(new Set),[w,D]=(0,V.useState)([]),[_,d]=(0,V.useState)(),[T,I]=(0,V.useState)(),[x,E]=(0,V.useState)(),A=!1,{tokenPrices:S}=er({isPollingEnabled:o}),B=F=>{var or;if(!F)return;let{wrappingInfo:C,userTokens:X,factory:H,filteredTokens:ee}=F,{edges:re,pageInfo:de,pageData:oe}=ee;E(oe==null?void 0:oe.count),H&&I(H);let ye=C&&C.length?C[0].wrappedToken:void 0;if(d(ye),!re)return;y((or=re[re.length-1])==null?void 0:or.cursor);let nr=re.map(ir=>G(R({},ir.node),{balance:"0",valueUSD:"0"})),_r=Fr(nr,X),$r=Je({tokens:_r,wrappedEgld:ye});D(ir=>Fr(ir,$r)),!(de!=null&&de.hasNextPage)&&!A?g(!1):A=!1},{isError:v,isLoading:k,execute:U}=he({query:n?It:xt,queryOptions:{client:r,onCompleted:B}}),O=(F,C)=>{var H,ee,re,de,oe,ye;let X={limit:(H=F==null?void 0:F.limit)!=null?H:eo,offset:(ee=F==null?void 0:F.offset)!=null?ee:Jn,identifiers:(re=F==null?void 0:F.identifiers)!=null?re:no,enabledSwaps:(de=F==null?void 0:F.enabledSwaps)!=null?de:ro,pagination:(oe=F==null?void 0:F.pagination)!=null?oe:oo,searchInput:(ye=F==null?void 0:F.searchInput)!=null?ye:io};U({variables:X}),C&&(A=!0)},z=(0,V.useMemo)(()=>w.map(F=>{var X;let C=(X=S==null?void 0:S.find(({identifier:H})=>H===F.identifier))==null?void 0:X.price;return G(R({},F),{price:C!=null?C:F.price})}),[w,S]);return(0,V.useEffect)(()=>{if(e.current){e.current=!1;return}p({first:20,after:""}),b(new Set),g(!0),O({pagination:{first:20,after:""},searchInput:i})},[i]),(0,V.useEffect)(()=>{s.after&&(b(F=>new Set(F).add(s.after)),O({pagination:s,searchInput:i}))},[s]),Cr({tokens:w,hasMore:c,isLoading:k!=null?k:!1,observerId:(Q=t==null?void 0:t.observerId)!=null?Q:"",loadedCursors:P,currentCursor:h!=null?h:"",setPagination:p}),{swapConfig:T,wrappedEgld:_,isTokensError:v,isTokensLoading:k,tokens:z,totalTokensCount:x,getTokens:O,refetch:U}};a();var ve=require("react");a();var Vt=require("react"),Rr=te(require("bignumber.js"));var Lr=({swapRoute:t,firstToken:e,firstAmount:r,secondToken:n,secondAmount:o})=>(0,Vt.useMemo)(()=>{if(!t)return{firstAmountUsdValue:void 0,secondAmountUsdValue:void 0};let{swapType:i,amountIn:s,amountOut:p,tokenInID:c,tokenOutID:g,tokenInPriceUSD:h,tokenOutPriceUSD:y}=t,P=i===0,w=Boolean(i===1&&o&&(e==null?void 0:e.value)===c),D=Boolean(P&&r&&(n==null?void 0:n.value)===g);if(!w&&!D)return{firstAmountUsdValue:void 0,secondAmountUsdValue:void 0};let _=w?s:p,d=w?e==null?void 0:e.token.decimals:n==null?void 0:n.token.decimals,T=w?h:y,x=(0,we.formatAmount)({input:_,decimals:d,showLastNonZeroDecimal:!0}).replace(/,/g,""),E=new Rr.default(x).times(new Rr.default(T)).toString(10),A=bt(E,2);return{firstAmountUsdValue:w?A:void 0,secondAmountUsdValue:D?A:void 0}},[t,o,r,e,n]);a();var tr=require("react"),Nr=t=>{let e=(0,tr.useRef)(void 0);return(0,tr.useEffect)(()=>{e.current=t},[t]),e.current};var ao=({getSwapRoute:t,tolerancePercentage:e})=>{let[r,n]=(0,ve.useState)({firstAmount:"",secondAmount:""}),[o,i]=(0,ve.useState)(),s=(0,ve.useRef)(),p=(0,ve.useRef)(),c=Nr(r.secondToken),g=Lr({swapRoute:o,firstToken:r.firstToken,firstAmount:r.firstAmount,secondToken:r.secondToken,secondAmount:r.secondAmount}),h=d=>{if(!d){i(void 0);return}let{swapType:T,tokenInID:I,tokenOutID:x,amountIn:E,amountOut:A,pairs:S}=d;i(d);let B=T===0,v=B?A:E,U=Ye({identifier:B?x:I,pairs:S}),O=Ie({amount:v,decimals:U}),z=B&&Boolean(r.firstAmount),q=!B&&Boolean(r.secondAmount);if(s.current){let Q=Ye({identifier:d.tokenInID,pairs:S}),F=Ye({identifier:d.tokenOutID,pairs:S}),C=Ie({amount:d.amountIn,decimals:Q}),X=Ie({amount:d.amountOut,decimals:F}),H=C,ee=X;n(re=>G(R({},re),{firstAmount:H,secondAmount:ee})),s.current=!1}else n(Q=>G(R({},Q),{firstAmount:q?O:Q.firstAmount,secondAmount:z?O:Q.secondAmount}))},y=d=>