UNPKG

@multiversx/sdk-dapp-swap

Version:

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

249 lines (243 loc) 38.7 kB
"use strict";var lt=Object.create;var ie=Object.defineProperty,mt=Object.defineProperties,ht=Object.getOwnPropertyDescriptor,dt=Object.getOwnPropertyDescriptors,yt=Object.getOwnPropertyNames,he=Object.getOwnPropertySymbols,Tt=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable;var ir=(t,e,r)=>e in t?ie(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,D=(t,e)=>{for(var r in e||(e={}))Be.call(e,r)&&ir(t,r,e[r]);if(he)for(var r of he(e))sr.call(e,r)&&ir(t,r,e[r]);return t},Q=(t,e)=>mt(t,dt(e));var ar=(t,e)=>{var r={};for(var n in t)Be.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&he)for(var n of he(t))e.indexOf(n)<0&&sr.call(t,n)&&(r[n]=t[n]);return r};var gt=(t,e)=>()=>(t&&(e=t(t=0)),e);var de=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),xt=(t,e)=>{for(var r in e)ie(t,r,{get:e[r],enumerable:!0})},ur=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of yt(e))!Be.call(t,o)&&o!==r&&ie(t,o,{get:()=>e[o],enumerable:!(n=ht(e,o))||n.enumerable});return t};var B=(t,e,r)=>(r=t!=null?lt(Tt(t)):{},ur(e||!t||!t.__esModule?ie(r,"default",{value:t,enumerable:!0}):r,t)),wt=t=>ur(ie({},"__esModule",{value:!0}),t);var ve=(t,e,r)=>new Promise((n,o)=>{var s=l=>{try{m(r.next(l))}catch(y){o(y)}},a=l=>{try{m(r.throw(l))}catch(y){o(y)}},m=l=>l.done?n(l.value):Promise.resolve(l.value).then(s,a);m((r=r.apply(t,e)).next())});var fr=de(ye=>{"use strict";i();ye.byteLength=Et;ye.toByteArray=St;ye.fromByteArray=bt;var O=[],P=[],It=typeof Uint8Array!="undefined"?Uint8Array:Array,Oe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(q=0,pr=Oe.length;q<pr;++q)O[q]=Oe[q],P[Oe.charCodeAt(q)]=q;var q,pr;P["-".charCodeAt(0)]=62;P["_".charCodeAt(0)]=63;function cr(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 Et(t){var e=cr(t),r=e[0],n=e[1];return(r+n)*3/4-n}function At(t,e,r){return(e+r)*3/4-r}function St(t){var e,r=cr(t),n=r[0],o=r[1],s=new It(At(t,n,o)),a=0,m=o>0?n-4:n,l;for(l=0;l<m;l+=4)e=P[t.charCodeAt(l)]<<18|P[t.charCodeAt(l+1)]<<12|P[t.charCodeAt(l+2)]<<6|P[t.charCodeAt(l+3)],s[a++]=e>>16&255,s[a++]=e>>8&255,s[a++]=e&255;return o===2&&(e=P[t.charCodeAt(l)]<<2|P[t.charCodeAt(l+1)]>>4,s[a++]=e&255),o===1&&(e=P[t.charCodeAt(l)]<<10|P[t.charCodeAt(l+1)]<<4|P[t.charCodeAt(l+2)]>>2,s[a++]=e>>8&255,s[a++]=e&255),s}function kt(t){return O[t>>18&63]+O[t>>12&63]+O[t>>6&63]+O[t&63]}function Ft(t,e,r){for(var n,o=[],s=e;s<r;s+=3)n=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(t[s+2]&255),o.push(kt(n));return o.join("")}function bt(t){for(var e,r=t.length,n=r%3,o=[],s=16383,a=0,m=r-n;a<m;a+=s)o.push(Ft(t,a,a+s>m?m:a+s));return n===1?(e=t[r-1],o.push(O[e>>2]+O[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(O[e>>10]+O[e>>4&63]+O[e<<2&63]+"=")),o.join("")}});var lr=de(Ce=>{i();Ce.read=function(t,e,r,n,o){var s,a,m=o*8-n-1,l=(1<<m)-1,y=l>>1,h=-7,d=r?o-1:0,w=r?-1:1,g=t[e+d];for(d+=w,s=g&(1<<-h)-1,g>>=-h,h+=m;h>0;s=s*256+t[e+d],d+=w,h-=8);for(a=s&(1<<-h)-1,s>>=-h,h+=n;h>0;a=a*256+t[e+d],d+=w,h-=8);if(s===0)s=1-y;else{if(s===l)return a?NaN:(g?-1:1)*(1/0);a=a+Math.pow(2,n),s=s-y}return(g?-1:1)*a*Math.pow(2,s-n)};Ce.write=function(t,e,r,n,o,s){var a,m,l,y=s*8-o-1,h=(1<<y)-1,d=h>>1,w=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,g=n?0:s-1,S=n?1:-1,E=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(m=isNaN(e)?1:0,a=h):(a=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-a))<1&&(a--,l*=2),a+d>=1?e+=w/l:e+=w*Math.pow(2,1-d),e*l>=2&&(a++,l/=2),a+d>=h?(m=0,a=h):a+d>=1?(m=(e*l-1)*Math.pow(2,o),a=a+d):(m=e*Math.pow(2,d-1)*Math.pow(2,o),a=0));o>=8;t[r+g]=m&255,g+=S,m/=256,o-=8);for(a=a<<o|m,y+=o;y>0;t[r+g]=a&255,g+=S,a/=256,y-=8);t[r+g-S]|=E*128}});var kr=de(J=>{"use strict";i();var Re=fr(),Z=lr(),mr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;J.Buffer=u;J.SlowBuffer=Ot;J.INSPECT_MAX_BYTES=50;var Te=2147483647;J.kMaxLength=Te;u.TYPED_ARRAY_SUPPORT=Dt();!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 Dt(){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 _(t){if(t>Te)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 $e(t)}return yr(t,e,r)}u.poolSize=8192;function yr(t,e,r){if(typeof t=="string")return Ut(t,e);if(ArrayBuffer.isView(t))return Bt(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(C(t,ArrayBuffer)||t&&C(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(C(t,SharedArrayBuffer)||t&&C(t.buffer,SharedArrayBuffer)))return Ne(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=vt(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 Tr(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 Pt(t,e,r){return Tr(t),t<=0?_(t):e!==void 0?typeof r=="string"?_(t).fill(e,r):_(t).fill(e):_(t)}u.alloc=function(t,e,r){return Pt(t,e,r)};function $e(t){return Tr(t),_(t<0?0:Me(t)|0)}u.allocUnsafe=function(t){return $e(t)};u.allocUnsafeSlow=function(t){return $e(t)};function Ut(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=gr(t,e)|0,n=_(r),o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}function Le(t){for(var e=t.length<0?0:Me(t.length)|0,r=_(e),n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Bt(t){if(C(t,Uint8Array)){var e=new Uint8Array(t);return Ne(e.buffer,e.byteOffset,e.byteLength)}return Le(t)}function Ne(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 vt(t){if(u.isBuffer(t)){var e=Me(t.length)|0,r=_(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||Ge(t.length)?_(0):Le(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Le(t.data)}function Me(t){if(t>=Te)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Te.toString(16)+" bytes");return t|0}function Ot(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(C(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),C(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,s=0,a=Math.min(n,o);s<a;++s)if(e[s]!==r[s]){n=e[s],o=r[s];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),s=0;for(n=0;n<e.length;++n){var a=e[n];if(C(a,Uint8Array))s+a.length>o.length?u.from(a).copy(o,s):Uint8Array.prototype.set.call(o,a,s);else if(u.isBuffer(a))a.copy(o,s);else throw new TypeError('"list" argument must be an Array of Buffers');s+=a.length}return o};function gr(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||C(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 _e(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Sr(t).length;default:if(o)return n?-1:_e(t).length;e=(""+e).toLowerCase(),o=!0}}u.byteLength=gr;function Ct(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 Vt(this,e,r);case"utf8":case"utf-8":return wr(this,e,r);case"ascii":return Qt(this,e,r);case"latin1":case"binary":return Wt(this,e,r);case"base64":return Mt(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return zt(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}u.prototype._isBuffer=!0;function H(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)H(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)H(this,r,r+3),H(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)H(this,r,r+7),H(this,r+1,r+6),H(this,r+2,r+5),H(this,r+3,r+4);return this};u.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?wr(this,0,e):Ct.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=J.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};mr&&(u.prototype[mr]=u.prototype.inspect);u.prototype.compare=function(e,r,n,o,s){if(C(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),s===void 0&&(s=this.length),r<0||n>e.length||o<0||s>this.length)throw new RangeError("out of range index");if(o>=s&&r>=n)return 0;if(o>=s)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,o>>>=0,s>>>=0,this===e)return 0;for(var a=s-o,m=n-r,l=Math.min(a,m),y=this.slice(o,s),h=e.slice(r,n),d=0;d<l;++d)if(y[d]!==h[d]){a=y[d],m=h[d];break}return a<m?-1:m<a?1:0};function xr(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,Ge(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:hr(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):hr(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function hr(t,e,r,n,o){var s=1,a=t.length,m=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;s=2,a/=2,m/=2,r/=2}function l(g,S){return s===1?g[S]:g.readUInt16BE(S*s)}var y;if(o){var h=-1;for(y=r;y<a;y++)if(l(t,y)===l(e,h===-1?0:y-h)){if(h===-1&&(h=y),y-h+1===m)return h*s}else h!==-1&&(y-=y-h),h=-1}else for(r+m>a&&(r=a-m),y=r;y>=0;y--){for(var d=!0,w=0;w<m;w++)if(l(t,y+w)!==l(e,w)){d=!1;break}if(d)return y}return-1}u.prototype.includes=function(e,r,n){return this.indexOf(e,r,n)!==-1};u.prototype.indexOf=function(e,r,n){return xr(this,e,r,n,!0)};u.prototype.lastIndexOf=function(e,r,n){return xr(this,e,r,n,!1)};function Rt(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n),n>o&&(n=o)):n=o;var s=e.length;n>s/2&&(n=s/2);for(var a=0;a<n;++a){var m=parseInt(e.substr(a*2,2),16);if(Ge(m))return a;t[r+a]=m}return a}function Lt(t,e,r,n){return ge(_e(e,t.length-r),t,r,n)}function Nt(t,e,r,n){return ge(jt(e),t,r,n)}function _t(t,e,r,n){return ge(Sr(e),t,r,n)}function $t(t,e,r,n){return ge(Kt(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 s=this.length-r;if((n===void 0||n>s)&&(n=s),e.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");for(var a=!1;;)switch(o){case"hex":return Rt(this,e,r,n);case"utf8":case"utf-8":return Lt(this,e,r,n);case"ascii":case"latin1":case"binary":return Nt(this,e,r,n);case"base64":return _t(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $t(this,e,r,n);default:if(a)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),a=!0}};u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Mt(t,e,r){return e===0&&r===t.length?Re.fromByteArray(t):Re.fromByteArray(t.slice(e,r))}function wr(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var s=t[o],a=null,m=s>239?4:s>223?3:s>191?2:1;if(o+m<=r){var l,y,h,d;switch(m){case 1:s<128&&(a=s);break;case 2:l=t[o+1],(l&192)===128&&(d=(s&31)<<6|l&63,d>127&&(a=d));break;case 3:l=t[o+1],y=t[o+2],(l&192)===128&&(y&192)===128&&(d=(s&15)<<12|(l&63)<<6|y&63,d>2047&&(d<55296||d>57343)&&(a=d));break;case 4:l=t[o+1],y=t[o+2],h=t[o+3],(l&192)===128&&(y&192)===128&&(h&192)===128&&(d=(s&15)<<18|(l&63)<<12|(y&63)<<6|h&63,d>65535&&d<1114112&&(a=d))}}a===null?(a=65533,m=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|a&1023),n.push(a),o+=m}return Gt(n)}var dr=4096;function Gt(t){var e=t.length;if(e<=dr)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=dr));return r}function Qt(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 Wt(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 Vt(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",s=e;s<r;++s)o+=Xt[t[s]];return o}function zt(t,e,r){for(var n=t.slice(e,r),o="",s=0;s<n.length-1;s+=2)o+=String.fromCharCode(n[s]+n[s+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 I(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||I(e,r,this.length);for(var o=this[e],s=1,a=0;++a<r&&(s*=256);)o+=this[e+a]*s;return o};u.prototype.readUintBE=u.prototype.readUIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||I(e,r,this.length);for(var o=this[e+--r],s=1;r>0&&(s*=256);)o+=this[e+--r]*s;return o};u.prototype.readUint8=u.prototype.readUInt8=function(e,r){return e=e>>>0,r||I(e,1,this.length),this[e]};u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||I(e,2,this.length),this[e]|this[e+1]<<8};u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||I(e,2,this.length),this[e]<<8|this[e+1]};u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||I(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||I(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||I(e,r,this.length);for(var o=this[e],s=1,a=0;++a<r&&(s*=256);)o+=this[e+a]*s;return s*=128,o>=s&&(o-=Math.pow(2,8*r)),o};u.prototype.readIntBE=function(e,r,n){e=e>>>0,r=r>>>0,n||I(e,r,this.length);for(var o=r,s=1,a=this[e+--o];o>0&&(s*=256);)a+=this[e+--o]*s;return s*=128,a>=s&&(a-=Math.pow(2,8*r)),a};u.prototype.readInt8=function(e,r){return e=e>>>0,r||I(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};u.prototype.readInt16LE=function(e,r){e=e>>>0,r||I(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||I(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||I(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||I(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||I(e,4,this.length),Z.read(this,e,!0,23,4)};u.prototype.readFloatBE=function(e,r){return e=e>>>0,r||I(e,4,this.length),Z.read(this,e,!1,23,4)};u.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||I(e,8,this.length),Z.read(this,e,!0,52,8)};u.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||I(e,8,this.length),Z.read(this,e,!1,52,8)};function k(t,e,r,n,o,s){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<s)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 s=Math.pow(2,8*n)-1;k(this,e,r,n,s,0)}var a=1,m=0;for(this[r]=e&255;++m<n&&(a*=256);)this[r+m]=e/a&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 s=Math.pow(2,8*n)-1;k(this,e,r,n,s,0)}var a=n-1,m=1;for(this[r+a]=e&255;--a>=0&&(m*=256);)this[r+a]=e/m&255;return r+n};u.prototype.writeUint8=u.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||k(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||k(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||k(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||k(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||k(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 s=Math.pow(2,8*n-1);k(this,e,r,n,s-1,-s)}var a=0,m=1,l=0;for(this[r]=e&255;++a<n&&(m*=256);)e<0&&l===0&&this[r+a-1]!==0&&(l=1),this[r+a]=(e/m>>0)-l&255;return r+n};u.prototype.writeIntBE=function(e,r,n,o){if(e=+e,r=r>>>0,!o){var s=Math.pow(2,8*n-1);k(this,e,r,n,s-1,-s)}var a=n-1,m=1,l=0;for(this[r+a]=e&255;--a>=0&&(m*=256);)e<0&&l===0&&this[r+a+1]!==0&&(l=1),this[r+a]=(e/m>>0)-l&255;return r+n};u.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||k(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||k(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||k(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||k(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||k(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 Ir(t,e,r,n,o,s){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Er(t,e,r,n,o){return e=+e,r=r>>>0,o||Ir(t,e,r,4,34028234663852886e22,-34028234663852886e22),Z.write(t,e,r,n,23,4),r+4}u.prototype.writeFloatLE=function(e,r,n){return Er(this,e,r,!0,n)};u.prototype.writeFloatBE=function(e,r,n){return Er(this,e,r,!1,n)};function Ar(t,e,r,n,o){return e=+e,r=r>>>0,o||Ir(t,e,r,8,17976931348623157e292,-17976931348623157e292),Z.write(t,e,r,n,52,8),r+8}u.prototype.writeDoubleLE=function(e,r,n){return Ar(this,e,r,!0,n)};u.prototype.writeDoubleBE=function(e,r,n){return Ar(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 s=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),s};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 s=e.charCodeAt(0);(o==="utf8"&&s<128||o==="latin1")&&(e=s)}}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 a;if(typeof e=="number")for(a=r;a<n;++a)this[a]=e;else{var m=u.isBuffer(e)?e:u.from(e,o),l=m.length;if(l===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(a=0;a<n-r;++a)this[a+r]=m[a%l]}return this};var qt=/[^+/0-9A-Za-z-_]/g;function Ht(t){if(t=t.split("=")[0],t=t.trim().replace(qt,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function _e(t,e){e=e||1/0;for(var r,n=t.length,o=null,s=[],a=0;a<n;++a){if(r=t.charCodeAt(a),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}else if(a+1===n){(e-=3)>-1&&s.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),o=r;continue}r=(o-55296<<10|r-56320)+65536}else o&&(e-=3)>-1&&s.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,r&63|128)}else if(r<65536){if((e-=3)<0)break;s.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((e-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return s}function jt(t){for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function Kt(t,e){for(var r,n,o,s=[],a=0;a<t.length&&!((e-=2)<0);++a)r=t.charCodeAt(a),n=r>>8,o=r%256,s.push(o),s.push(n);return s}function Sr(t){return Re.toByteArray(Ht(t))}function ge(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 C(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function Ge(t){return t!==t}var Xt=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 Ur=de((_n,Pr)=>{i();var x=Pr.exports={},R,L;function Qe(){throw new Error("setTimeout has not been defined")}function We(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?R=setTimeout:R=Qe}catch(t){R=Qe}try{typeof clearTimeout=="function"?L=clearTimeout:L=We}catch(t){L=We}})();function Fr(t){if(R===setTimeout)return setTimeout(t,0);if((R===Qe||!R)&&setTimeout)return R=setTimeout,setTimeout(t,0);try{return R(t,0)}catch(e){try{return R.call(null,t,0)}catch(r){return R.call(this,t,0)}}}function Yt(t){if(L===clearTimeout)return clearTimeout(t);if((L===We||!L)&&clearTimeout)return L=clearTimeout,clearTimeout(t);try{return L(t)}catch(e){try{return L.call(null,t)}catch(r){return L.call(this,t)}}}var $=[],ee=!1,j,xe=-1;function Zt(){!ee||!j||(ee=!1,j.length?$=j.concat($):xe=-1,$.length&&br())}function br(){if(!ee){var t=Fr(Zt);ee=!0;for(var e=$.length;e;){for(j=$,$=[];++xe<e;)j&&j[xe].run();xe=-1,e=$.length}j=null,ee=!1,Yt(t)}}x.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];$.push(new Dr(t,e)),$.length===1&&!ee&&Fr(br)};function Dr(t,e){this.fun=t,this.array=e}Dr.prototype.run=function(){this.fun.apply(null,this.array)};x.title="browser";x.browser=!0;x.env={};x.argv=[];x.version="";x.versions={};function M(){}x.on=M;x.addListener=M;x.once=M;x.off=M;x.removeListener=M;x.removeAllListeners=M;x.emit=M;x.prependListener=M;x.prependOnceListener=M;x.listeners=function(t){return[]};x.binding=function(t){throw new Error("process.binding is not supported")};x.cwd=function(){return"/"};x.chdir=function(t){throw new Error("process.chdir is not supported")};x.umask=function(){return 0}});var p,c,$n,i=gt(()=>{p=B(kr()),c=B(Ur()),$n=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 On={};xt(On,{useFilteredTokens:()=>vn});module.exports=wt(On);i();var A=require("react");i();i();var Jt=B(require("react")),Ie=require("@apollo/client"),en=require("@apollo/client/link/context"),rn=require("@apollo/client/link/error"),tn=require("graphql");i();i();var we=require("react"),Br=(0,we.createContext)({accessToken:"",isAuthenticated:!1}),v=()=>{let t=(0,we.useContext)(Br);if(t==null)throw new Error("useAuthorizationContext must be used within a AuthorizationProvider");return t};i();i();i();var F=` balance decimals name identifier ticker owner assets { website description status pngUrl svgUrl } price type previous24hPrice previous7dPrice `;i();i();i();var Ee=` assets { website description status pngUrl svgUrl } decimals name collection ticker `;var vr=` address lockedToken { ${Ee} } lpProxyToken { ${Ee} } farmProxyToken { ${Ee} } intermediatedPairs intermediatedFarms `;var Or=` address firstToken { ${F} } secondToken { ${F} } type feesAPR totalFeePercent specialFeePercent lockedTokensInfo { lockingSC { ${vr} } unlockEpoch } `;i();var re=` value receiver gasPrice gasLimit data chainID version `;i();var se=` defaultSlippage slippageValues minSlippage maxSlippage minSwapAmount `;i();var nn=` __typename valueUSD `,Ve=` ${F} ${nn} `;i();i();var ze=require("@apollo/client");var qe="TRANSACTIONS_PLACEHOLDER",on=` transactions { ${re} } `,Cr=` 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 { ${Or} } ${qe} } } `,sn=ze.gql` ${Cr.replace(qe,on)} `,an=ze.gql` ${Cr.replace(qe,"")} `;i();i();var ae=require("@apollo/client");var un=ae.gql` query swapPackageTokens ($identifiers: [String!], $enabledSwaps: Boolean) { tokens(identifiers: $identifiers, enabledSwaps: $enabledSwaps) { ${F} } wrappingInfo { wrappedToken { ${F} } } factory { ${se} } } `,Rr=ae.gql` query swapPackageFilteredTokens ($enabledSwaps: Boolean, $pagination: ConnectionArgs, $searchInput: String, $identifiers: [String!]) { filteredTokens (pagination: $pagination, filters: {searchToken: $searchInput, enabledSwaps: $enabledSwaps, identifiers: $identifiers}) { edges { node { ${F} } cursor } pageInfo { hasNextPage } pageData { count } } wrappingInfo { wrappedToken { ${F} } } factory { ${se} } } `,pn=ae.gql` query swapPackageTokensWithBalance ($identifiers: [String!], $offset: Int, $limit: Int, $enabledSwaps: Boolean) { tokens(identifiers: $identifiers, enabledSwaps: $enabledSwaps) { ${F} } userTokens (offset: $offset, limit: $limit) { ${Ve} } wrappingInfo { wrappedToken { ${F} } } factory { ${se} } } `,Lr=ae.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 { ${F} } cursor } pageInfo { hasNextPage } pageData { count } } userTokens (offset: $offset, limit: $limit) { ${Ve} } wrappingInfo { wrappedToken { ${F} } } factory { ${se} } } `;i();i();var Nr=require("@apollo/client");var _r=Nr.gql` query swapPackageWrapEgld ($wrappingAmount: String!) { wrapEgld(amount: $wrappingAmount) { ${re} } } `;i();var $r=require("@apollo/client");var Mr=$r.gql` query swapPackageUnwrapEgld ($wrappingAmount: String!) { unwrapEgld(amount: $wrappingAmount) { ${re} } } `;i();i();var Gr=require("@apollo/client"),cn=Gr.gql` query swapPackageMaintenance { factory { maintenance } } `;i();i();var mn=B(require("bignumber.js"));i();i();var te="EGLD";i();i();var b=require("@multiversx/sdk-core");i();i();var U=require("@multiversx/sdk-dapp/out/constants");i();var fn=require("@multiversx/sdk-dapp/out/types/enums.types");i();var Qr=require("@multiversx/sdk-dapp/out/utils/decoders/base64Utils");i();var Wr=require("@multiversx/sdk-dapp/out/store/store"),Vr=require("@multiversx/sdk-dapp/out/store/selectors/accountSelectors");i();var He=require("@multiversx/sdk-dapp-utils/out/constants"),Ae=require("@multiversx/sdk-dapp-utils/out/helpers/formatAmount"),Se=require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount"),je=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsFloat"),zr=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsInteger");i();i();i();var Ke=(t,e)=>{let r=new Map;return t==null||t.forEach(n=>{r.set(n.identifier,Q(D({},n),{balance:"0",valueUSD:"0"}))}),e==null||e.forEach(n=>{var s,a;let o=r.get(n.identifier);o?r.set(n.identifier,Q(D({},o),{balance:(s=n.balance)!=null?s:"0",valueUSD:(a=n.valueUSD)!=null?a:"0"})):n.type!=="FungibleESDT-LP"&&r.set(n.identifier,n)}),Array.from(r.values())};i();i();var hn=B(require("bignumber.js"));i();i();i();i();i();i();i();i();i();i();i();i();i();i();i();var dn=B(require("bignumber.js"));i();i();var yn=B(require("bignumber.js"));i();var Hr=B(require("bignumber.js"));var Xe=({tokens:t,wrappedEgld:e})=>t.sort((r,n)=>r.identifier===te?-1:n.identifier===te?1:r.identifier===(e==null?void 0:e.identifier)?-1:n.identifier===(e==null?void 0:e.identifier)?1:new Hr.default(n.valueUSD).minus(r.valueUSD).toNumber());i();var Tn=B(require("bignumber.js"));i();i();var ot=require("@apollo/client");i();i();var Kr=require("react");i();var ke=require("react");var ue=({query:t,queryOptions:e})=>{let{client:r}=v(),[n,o]=(0,ke.useState)(),[s,a]=(0,ke.useState)(),[m,l]=(0,ke.useState)();return{isLoading:n,isError:s,error:m,execute:h=>ve(void 0,null,function*(){var g,S;let d=(g=h==null?void 0:h.onCompleted)!=null?g:e==null?void 0:e.onCompleted,w=(S=h==null?void 0:h.variables)!=null?S:e==null?void 0:e.variables;try{o(!0);let E=yield r==null?void 0:r.query({query:t,variables:w}),W=E==null?void 0:E.data,G=E==null?void 0:E.errors;return G&&G.length>0&&(a(!0),l(G[0].message)),W&&(a(!1),l(void 0),d==null||d(W)),o(!1),W}catch(E){o(!1),a(!0),console.error(E);return}})}};i();i();var Ze=require("react"),xn=B(require("bignumber.js"));i();var Xr=require("react");i();var be=require("react");i();var pe=require("react"),Yr=require("@apollo/client");var Fe=({query:t,queryOptions:e,refetchTrigger:r,isPollingEnabled:n=!1,isRefetchEnabled:o=!1})=>{let s=Zr(),{client:a}=v(),ce=(0,Yr.useQuery)(t,D({client:a,notifyOnNetworkStatusChange:!0,fetchPolicy:"no-cache",nextFetchPolicy:"no-cache"},e)),{error:m,loading:l,previousData:y,data:h=y,refetch:d,stopPolling:w,startPolling:g}=ce,S=ar(ce,["error","loading","previousData","data","refetch","stopPolling","startPolling"]),E=(0,pe.useCallback)(()=>{s&&n&&!m?g(6e3):w()},[s,n,m,e]);(0,pe.useEffect)(()=>(E(),()=>{w()}),[E]),(0,pe.useEffect)(()=>{!o||r===0||(d(),E())},[r,o]);let W=h==null&&l,G=Boolean(m);return D({data:G?void 0:h,error:m,isError:G,isLoading:W,isRefetching:l,refetch:d},S)};i();i();var ne=require("react"),Jr=()=>typeof document===void 0?!0:document.visibilityState==="visible",Zr=()=>{let[t,e]=(0,ne.useState)(Jr()),r=(0,ne.useCallback)(()=>{e(Jr())},[e]);return(0,ne.useEffect)(()=>{if(typeof document!==void 0)return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[r]),t};i();var rt=require("react");i();var En=require("react"),An=B(require("bignumber.js"));i();var et=require("react");i();var Sn=require("react");i();var tt=require("react"),nt=({tokens:t,hasMore:e,isLoading:r,observerId:n,loadedCursors:o,currentCursor:s,setPagination:a})=>{(0,tt.useEffect)(()=>{if(!n)return;let m=document.getElementById(n);if(!m)return;let l=new IntersectionObserver(y=>{y[0].isIntersecting&&e&&!r&&s&&!o.has(s)&&a({first:20,after:s})},{threshold:1});return l.observe(m),()=>{l.disconnect()}},[t,n])};var Ye=({skip:t=!1,isPollingEnabled:e=!1})=>{let r=ot.gql` query swapPackageTokenPrices { tokens(enabledSwaps: true) { price identifier } } `,{data:n,isError:o,isLoading:s}=Fe({isPollingEnabled:e,query:r,queryOptions:{skip:t}});return{tokenPrices:n==null?void 0:n.tokens,isTokenPricesError:o,isTokenPricesLoading:s}};var kn=0,Fn=500,bn=!0,Dn=!1,Pn=[],Un={first:20,after:""},Bn="",vn=t=>{var tr,nr;let e=(0,A.useRef)(!0),{client:r,isAuthenticated:n}=v();if(!r)throw new Error("Swap GraphQL client not initialized");let o=(tr=t==null?void 0:t.pricePolling)!=null?tr:Dn,s=t==null?void 0:t.searchInput,[a,m]=(0,A.useState)({first:20,after:""}),[l,y]=(0,A.useState)(!0),[h,d]=(0,A.useState)(),[w,g]=(0,A.useState)(new Set),[S,E]=(0,A.useState)([]),[W,G]=(0,A.useState)(),[Je,ce]=(0,A.useState)(),[er,it]=(0,A.useState)(),De=!1,{tokenPrices:fe}=Ye({isPollingEnabled:o}),st=T=>{var or;if(!T)return;let{wrappingInfo:N,userTokens:K,factory:V,filteredTokens:me}=T,{edges:z,pageInfo:X,pageData:Y}=me;it(Y==null?void 0:Y.count),V&&ce(V);let oe=N&&N.length?N[0].wrappedToken:void 0;if(G(oe),!z)return;d((or=z[z.length-1])==null?void 0:or.cursor);let pt=z.map(Ue=>Q(D({},Ue.node),{balance:"0",valueUSD:"0"})),ct=Ke(pt,K),ft=Xe({tokens:ct,wrappedEgld:oe});E(Ue=>Ke(Ue,ft)),!(X!=null&&X.hasNextPage)&&!De?y(!1):De=!1},{isError:at,isLoading:le,execute:rr}=ue({query:n?Lr:Rr,queryOptions:{client:r,onCompleted:st}}),Pe=(T,N)=>{var V,me,z,X,Y,oe;let K={limit:(V=T==null?void 0:T.limit)!=null?V:Fn,offset:(me=T==null?void 0:T.offset)!=null?me:kn,identifiers:(z=T==null?void 0:T.identifiers)!=null?z:Pn,enabledSwaps:(X=T==null?void 0:T.enabledSwaps)!=null?X:bn,pagination:(Y=T==null?void 0:T.pagination)!=null?Y:Un,searchInput:(oe=T==null?void 0:T.searchInput)!=null?oe:Bn};rr({variables:K}),N&&(De=!0)},ut=(0,A.useMemo)(()=>S.map(T=>{var K;let N=(K=fe==null?void 0:fe.find(({identifier:V})=>V===T.identifier))==null?void 0:K.price;return Q(D({},T),{price:N!=null?N:T.price})}),[S,fe]);return(0,A.useEffect)(()=>{if(e.current){e.current=!1;return}m({first:20,after:""}),g(new Set),y(!0),Pe({pagination:{first:20,after:""},searchInput:s})},[s]),(0,A.useEffect)(()=>{a.after&&(g(T=>new Set(T).add(a.after)),Pe({pagination:a,searchInput:s}))},[a]),nt({tokens:S,hasMore:l,isLoading:le!=null?le:!1,observerId:(nr=t==null?void 0:t.observerId)!=null?nr:"",loadedCursors:w,currentCursor:h!=null?h:"",setPagination:m}),{swapConfig:Je,wrappedEgld:W,isTokensError:at,isTokensLoading:le,tokens:ut,totalTokensCount:er,getTokens:Pe,refetch:rr}};0&&(module.exports={useFilteredTokens}); /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */ //# sourceMappingURL=useFilteredTokens.js.map