@multiversx/sdk-dapp-swap
Version:
A library to hold the main logic for swapping between tokens on the MultiversX blockchain
234 lines (228 loc) • 34.5 kB
JavaScript
"use strict";var Rt=Object.create;var H=Object.defineProperty;var Ot=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames,K=Object.getOwnPropertySymbols,Ct=Object.getPrototypeOf,ue=Object.prototype.hasOwnProperty,Oe=Object.prototype.propertyIsEnumerable;var Re=(r,e,t)=>e in r?H(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e)=>{for(var t in e||(e={}))ue.call(e,t)&&Re(r,t,e[t]);if(K)for(var t of K(e))Oe.call(e,t)&&Re(r,t,e[t]);return r};var Le=(r,e)=>{var t={};for(var n in r)ue.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(r!=null&&K)for(var n of K(r))e.indexOf(n)<0&&Oe.call(r,n)&&(t[n]=r[n]);return t};var Nt=(r,e)=>()=>(r&&(e=r(r=0)),e);var Y=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),_t=(r,e)=>{for(var t in e)H(r,t,{get:e[t],enumerable:!0})},Ce=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Lt(e))!ue.call(r,o)&&o!==t&&H(r,o,{get:()=>e[o],enumerable:!(n=Ot(e,o))||n.enumerable});return r};var E=(r,e,t)=>(t=r!=null?Rt(Ct(r)):{},Ce(e||!r||!r.__esModule?H(t,"default",{value:r,enumerable:!0}):t,r)),Mt=r=>Ce(H({},"__esModule",{value:!0}),r);var Me=Y(q=>{"use strict";i();q.byteLength=Gt;q.toByteArray=Qt;q.fromByteArray=Ht;var F=[],k=[],$t=typeof Uint8Array!="undefined"?Uint8Array:Array,ce="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(N=0,Ne=ce.length;N<Ne;++N)F[N]=ce[N],k[ce.charCodeAt(N)]=N;var N,Ne;k["-".charCodeAt(0)]=62;k["_".charCodeAt(0)]=63;function _e(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function Gt(r){var e=_e(r),t=e[0],n=e[1];return(t+n)*3/4-n}function Vt(r,e,t){return(e+t)*3/4-t}function Qt(r){var e,t=_e(r),n=t[0],o=t[1],s=new $t(Vt(r,n,o)),a=0,l=o>0?n-4:n,m;for(m=0;m<l;m+=4)e=k[r.charCodeAt(m)]<<18|k[r.charCodeAt(m+1)]<<12|k[r.charCodeAt(m+2)]<<6|k[r.charCodeAt(m+3)],s[a++]=e>>16&255,s[a++]=e>>8&255,s[a++]=e&255;return o===2&&(e=k[r.charCodeAt(m)]<<2|k[r.charCodeAt(m+1)]>>4,s[a++]=e&255),o===1&&(e=k[r.charCodeAt(m)]<<10|k[r.charCodeAt(m+1)]<<4|k[r.charCodeAt(m+2)]>>2,s[a++]=e>>8&255,s[a++]=e&255),s}function Wt(r){return F[r>>18&63]+F[r>>12&63]+F[r>>6&63]+F[r&63]}function zt(r,e,t){for(var n,o=[],s=e;s<t;s+=3)n=(r[s]<<16&16711680)+(r[s+1]<<8&65280)+(r[s+2]&255),o.push(Wt(n));return o.join("")}function Ht(r){for(var e,t=r.length,n=t%3,o=[],s=16383,a=0,l=t-n;a<l;a+=s)o.push(zt(r,a,a+s>l?l:a+s));return n===1?(e=r[t-1],o.push(F[e>>2]+F[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],o.push(F[e>>10]+F[e>>4&63]+F[e<<2&63]+"=")),o.join("")}});var $e=Y(pe=>{i();pe.read=function(r,e,t,n,o){var s,a,l=o*8-n-1,m=(1<<l)-1,d=m>>1,y=-7,h=t?o-1:0,I=t?-1:1,x=r[e+h];for(h+=I,s=x&(1<<-y)-1,x>>=-y,y+=l;y>0;s=s*256+r[e+h],h+=I,y-=8);for(a=s&(1<<-y)-1,s>>=-y,y+=n;y>0;a=a*256+r[e+h],h+=I,y-=8);if(s===0)s=1-d;else{if(s===m)return a?NaN:(x?-1:1)*(1/0);a=a+Math.pow(2,n),s=s-d}return(x?-1:1)*a*Math.pow(2,s-n)};pe.write=function(r,e,t,n,o,s){var a,l,m,d=s*8-o-1,y=(1<<d)-1,h=y>>1,I=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,x=n?0:s-1,L=n?1:-1,ae=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(l=isNaN(e)?1:0,a=y):(a=Math.floor(Math.log(e)/Math.LN2),e*(m=Math.pow(2,-a))<1&&(a--,m*=2),a+h>=1?e+=I/m:e+=I*Math.pow(2,1-h),e*m>=2&&(a++,m/=2),a+h>=y?(l=0,a=y):a+h>=1?(l=(e*m-1)*Math.pow(2,o),a=a+h):(l=e*Math.pow(2,h-1)*Math.pow(2,o),a=0));o>=8;r[t+x]=l&255,x+=L,l/=256,o-=8);for(a=a<<o|l,d+=o;d>0;r[t+x]=a&255,x+=L,a/=256,d-=8);r[t+x-L]|=ae*128}});var Je=Y(G=>{"use strict";i();var fe=Me(),$=$e(),Ge=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;G.Buffer=u;G.SlowBuffer=qt;G.INSPECT_MAX_BYTES=50;var J=2147483647;G.kMaxLength=J;u.TYPED_ARRAY_SUPPORT=jt();!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 jt(){try{var r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch(t){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 v(r){if(r>J)throw new RangeError('The value "'+r+'" is invalid for option "size"');var e=new Uint8Array(r);return Object.setPrototypeOf(e,u.prototype),e}function u(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return de(r)}return We(r,e,t)}u.poolSize=8192;function We(r,e,t){if(typeof r=="string")return Zt(r,e);if(ArrayBuffer.isView(r))return Kt(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(b(r,ArrayBuffer)||r&&b(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(b(r,SharedArrayBuffer)||r&&b(r.buffer,SharedArrayBuffer)))return le(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return u.from(n,e,t);var o=Yt(r);if(o)return o;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return u.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}u.from=function(r,e,t){return We(r,e,t)};Object.setPrototypeOf(u.prototype,Uint8Array.prototype);Object.setPrototypeOf(u,Uint8Array);function ze(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function Xt(r,e,t){return ze(r),r<=0?v(r):e!==void 0?typeof t=="string"?v(r).fill(e,t):v(r).fill(e):v(r)}u.alloc=function(r,e,t){return Xt(r,e,t)};function de(r){return ze(r),v(r<0?0:ye(r)|0)}u.allocUnsafe=function(r){return de(r)};u.allocUnsafeSlow=function(r){return de(r)};function Zt(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var t=He(r,e)|0,n=v(t),o=n.write(r,e);return o!==t&&(n=n.slice(0,o)),n}function me(r){for(var e=r.length<0?0:ye(r.length)|0,t=v(e),n=0;n<e;n+=1)t[n]=r[n]&255;return t}function Kt(r){if(b(r,Uint8Array)){var e=new Uint8Array(r);return le(e.buffer,e.byteOffset,e.byteLength)}return me(r)}function le(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');var n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,u.prototype),n}function Yt(r){if(u.isBuffer(r)){var e=ye(r.length)|0,t=v(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||ge(r.length)?v(0):me(r);if(r.type==="Buffer"&&Array.isArray(r.data))return me(r.data)}function ye(r){if(r>=J)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+J.toString(16)+" bytes");return r|0}function qt(r){return+r!=r&&(r=0),u.alloc(+r)}u.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==u.prototype};u.compare=function(e,t){if(b(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),b(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(e)||!u.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var n=e.length,o=t.length,s=0,a=Math.min(n,o);s<a;++s)if(e[s]!==t[s]){n=e[s],o=t[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,t){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(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var o=u.allocUnsafe(t),s=0;for(n=0;n<e.length;++n){var a=e[n];if(b(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 He(r,e){if(u.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||b(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);var t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;for(var o=!1;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return he(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return qe(r).length;default:if(o)return n?-1:he(r).length;e=(""+e).toLowerCase(),o=!0}}u.byteLength=He;function Jt(r,e,t){var n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return cr(this,e,t);case"utf8":case"utf-8":return Xe(this,e,t);case"ascii":return ar(this,e,t);case"latin1":case"binary":return ur(this,e,t);case"base64":return ir(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return pr(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}u.prototype._isBuffer=!0;function _(r,e,t){var n=r[e];r[e]=r[t],r[t]=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 t=0;t<e;t+=2)_(this,t,t+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 t=0;t<e;t+=4)_(this,t,t+3),_(this,t+1,t+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 t=0;t<e;t+=8)_(this,t,t+7),_(this,t+1,t+6),_(this,t+2,t+5),_(this,t+3,t+4);return this};u.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?Xe(this,0,e):Jt.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="",t=G.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};Ge&&(u.prototype[Ge]=u.prototype.inspect);u.prototype.compare=function(e,t,n,o,s){if(b(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(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),o===void 0&&(o=0),s===void 0&&(s=this.length),t<0||n>e.length||o<0||s>this.length)throw new RangeError("out of range index");if(o>=s&&t>=n)return 0;if(o>=s)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,o>>>=0,s>>>=0,this===e)return 0;for(var a=s-o,l=n-t,m=Math.min(a,l),d=this.slice(o,s),y=e.slice(t,n),h=0;h<m;++h)if(d[h]!==y[h]){a=d[h],l=y[h];break}return a<l?-1:l<a?1:0};function je(r,e,t,n,o){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,ge(t)&&(t=o?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(o)return-1;t=r.length-1}else if(t<0)if(o)t=0;else return-1;if(typeof e=="string"&&(e=u.from(e,n)),u.isBuffer(e))return e.length===0?-1:Ve(r,e,t,n,o);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):Ve(r,[e],t,n,o);throw new TypeError("val must be string, number or Buffer")}function Ve(r,e,t,n,o){var s=1,a=r.length,l=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;s=2,a/=2,l/=2,t/=2}function m(x,L){return s===1?x[L]:x.readUInt16BE(L*s)}var d;if(o){var y=-1;for(d=t;d<a;d++)if(m(r,d)===m(e,y===-1?0:d-y)){if(y===-1&&(y=d),d-y+1===l)return y*s}else y!==-1&&(d-=d-y),y=-1}else for(t+l>a&&(t=a-l),d=t;d>=0;d--){for(var h=!0,I=0;I<l;I++)if(m(r,d+I)!==m(e,I)){h=!1;break}if(h)return d}return-1}u.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};u.prototype.indexOf=function(e,t,n){return je(this,e,t,n,!0)};u.prototype.lastIndexOf=function(e,t,n){return je(this,e,t,n,!1)};function er(r,e,t,n){t=Number(t)||0;var o=r.length-t;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 l=parseInt(e.substr(a*2,2),16);if(ge(l))return a;r[t+a]=l}return a}function tr(r,e,t,n){return ee(he(e,r.length-t),r,t,n)}function rr(r,e,t,n){return ee(lr(e),r,t,n)}function nr(r,e,t,n){return ee(qe(e),r,t,n)}function or(r,e,t,n){return ee(hr(e,r.length-t),r,t,n)}u.prototype.write=function(e,t,n,o){if(t===void 0)o="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")o=t,n=this.length,t=0;else if(isFinite(t))t=t>>>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-t;if((n===void 0||n>s)&&(n=s),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");for(var a=!1;;)switch(o){case"hex":return er(this,e,t,n);case"utf8":case"utf-8":return tr(this,e,t,n);case"ascii":case"latin1":case"binary":return rr(this,e,t,n);case"base64":return nr(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return or(this,e,t,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 ir(r,e,t){return e===0&&t===r.length?fe.fromByteArray(r):fe.fromByteArray(r.slice(e,t))}function Xe(r,e,t){t=Math.min(r.length,t);for(var n=[],o=e;o<t;){var s=r[o],a=null,l=s>239?4:s>223?3:s>191?2:1;if(o+l<=t){var m,d,y,h;switch(l){case 1:s<128&&(a=s);break;case 2:m=r[o+1],(m&192)===128&&(h=(s&31)<<6|m&63,h>127&&(a=h));break;case 3:m=r[o+1],d=r[o+2],(m&192)===128&&(d&192)===128&&(h=(s&15)<<12|(m&63)<<6|d&63,h>2047&&(h<55296||h>57343)&&(a=h));break;case 4:m=r[o+1],d=r[o+2],y=r[o+3],(m&192)===128&&(d&192)===128&&(y&192)===128&&(h=(s&15)<<18|(m&63)<<12|(d&63)<<6|y&63,h>65535&&h<1114112&&(a=h))}}a===null?(a=65533,l=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|a&1023),n.push(a),o+=l}return sr(n)}var Qe=4096;function sr(r){var e=r.length;if(e<=Qe)return String.fromCharCode.apply(String,r);for(var t="",n=0;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Qe));return t}function ar(r,e,t){var n="";t=Math.min(r.length,t);for(var o=e;o<t;++o)n+=String.fromCharCode(r[o]&127);return n}function ur(r,e,t){var n="";t=Math.min(r.length,t);for(var o=e;o<t;++o)n+=String.fromCharCode(r[o]);return n}function cr(r,e,t){var n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);for(var o="",s=e;s<t;++s)o+=dr[r[s]];return o}function pr(r,e,t){for(var n=r.slice(e,t),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,t){var n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);var o=this.subarray(e,t);return Object.setPrototypeOf(o,u.prototype),o};function T(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var o=this[e],s=1,a=0;++a<t&&(s*=256);)o+=this[e+a]*s;return o};u.prototype.readUintBE=u.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var o=this[e+--t],s=1;t>0&&(s*=256);)o+=this[e+--t]*s;return o};u.prototype.readUint8=u.prototype.readUInt8=function(e,t){return e=e>>>0,t||T(e,1,this.length),this[e]};u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||T(e,2,this.length),this[e]|this[e+1]<<8};u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||T(e,2,this.length),this[e]<<8|this[e+1]};u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||T(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,t){return e=e>>>0,t||T(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var o=this[e],s=1,a=0;++a<t&&(s*=256);)o+=this[e+a]*s;return s*=128,o>=s&&(o-=Math.pow(2,8*t)),o};u.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var o=t,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*t)),a};u.prototype.readInt8=function(e,t){return e=e>>>0,t||T(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};u.prototype.readInt16LE=function(e,t){e=e>>>0,t||T(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};u.prototype.readInt16BE=function(e,t){e=e>>>0,t||T(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};u.prototype.readInt32LE=function(e,t){return e=e>>>0,t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function(e,t){return e=e>>>0,t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readFloatLE=function(e,t){return e=e>>>0,t||T(e,4,this.length),$.read(this,e,!0,23,4)};u.prototype.readFloatBE=function(e,t){return e=e>>>0,t||T(e,4,this.length),$.read(this,e,!1,23,4)};u.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||T(e,8,this.length),$.read(this,e,!0,52,8)};u.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||T(e,8,this.length),$.read(this,e,!1,52,8)};function w(r,e,t,n,o,s){if(!u.isBuffer(r))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(t+n>r.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(e,t,n,o){if(e=+e,t=t>>>0,n=n>>>0,!o){var s=Math.pow(2,8*n)-1;w(this,e,t,n,s,0)}var a=1,l=0;for(this[t]=e&255;++l<n&&(a*=256);)this[t+l]=e/a&255;return t+n};u.prototype.writeUintBE=u.prototype.writeUIntBE=function(e,t,n,o){if(e=+e,t=t>>>0,n=n>>>0,!o){var s=Math.pow(2,8*n)-1;w(this,e,t,n,s,0)}var a=n-1,l=1;for(this[t+a]=e&255;--a>=0&&(l*=256);)this[t+a]=e/l&255;return t+n};u.prototype.writeUint8=u.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,1,255,0),this[t]=e&255,t+1};u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};u.prototype.writeIntLE=function(e,t,n,o){if(e=+e,t=t>>>0,!o){var s=Math.pow(2,8*n-1);w(this,e,t,n,s-1,-s)}var a=0,l=1,m=0;for(this[t]=e&255;++a<n&&(l*=256);)e<0&&m===0&&this[t+a-1]!==0&&(m=1),this[t+a]=(e/l>>0)-m&255;return t+n};u.prototype.writeIntBE=function(e,t,n,o){if(e=+e,t=t>>>0,!o){var s=Math.pow(2,8*n-1);w(this,e,t,n,s-1,-s)}var a=n-1,l=1,m=0;for(this[t+a]=e&255;--a>=0&&(l*=256);)e<0&&m===0&&this[t+a+1]!==0&&(m=1),this[t+a]=(e/l>>0)-m&255;return t+n};u.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};u.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};u.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};u.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};u.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||w(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function Ze(r,e,t,n,o,s){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Ke(r,e,t,n,o){return e=+e,t=t>>>0,o||Ze(r,e,t,4,34028234663852886e22,-34028234663852886e22),$.write(r,e,t,n,23,4),t+4}u.prototype.writeFloatLE=function(e,t,n){return Ke(this,e,t,!0,n)};u.prototype.writeFloatBE=function(e,t,n){return Ke(this,e,t,!1,n)};function Ye(r,e,t,n,o){return e=+e,t=t>>>0,o||Ze(r,e,t,8,17976931348623157e292,-17976931348623157e292),$.write(r,e,t,n,52,8),t+8}u.prototype.writeDoubleLE=function(e,t,n){return Ye(this,e,t,!0,n)};u.prototype.writeDoubleBE=function(e,t,n){return Ye(this,e,t,!1,n)};u.prototype.copy=function(e,t,n,o){if(!u.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!o&&o!==0&&(o=this.length),t>=e.length&&(t=e.length),t||(t=0),o>0&&o<n&&(o=n),o===n||e.length===0||this.length===0)return 0;if(t<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-t<o-n&&(o=e.length-t+n);var s=o-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,o):Uint8Array.prototype.set.call(e,this.subarray(n,o),t),s};u.prototype.fill=function(e,t,n,o){if(typeof e=="string"){if(typeof t=="string"?(o=t,t=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(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);var a;if(typeof e=="number")for(a=t;a<n;++a)this[a]=e;else{var l=u.isBuffer(e)?e:u.from(e,o),m=l.length;if(m===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(a=0;a<n-t;++a)this[a+t]=l[a%m]}return this};var fr=/[^+/0-9A-Za-z-_]/g;function mr(r){if(r=r.split("=")[0],r=r.trim().replace(fr,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function he(r,e){e=e||1/0;for(var t,n=r.length,o=null,s=[],a=0;a<n;++a){if(t=r.charCodeAt(a),t>55295&&t<57344){if(!o){if(t>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=t;continue}if(t<56320){(e-=3)>-1&&s.push(239,191,189),o=t;continue}t=(o-55296<<10|t-56320)+65536}else o&&(e-=3)>-1&&s.push(239,191,189);if(o=null,t<128){if((e-=1)<0)break;s.push(t)}else if(t<2048){if((e-=2)<0)break;s.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;s.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;s.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return s}function lr(r){for(var e=[],t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function hr(r,e){for(var t,n,o,s=[],a=0;a<r.length&&!((e-=2)<0);++a)t=r.charCodeAt(a),n=t>>8,o=t%256,s.push(o),s.push(n);return s}function qe(r){return fe.toByteArray(mr(r))}function ee(r,e,t,n){for(var o=0;o<n&&!(o+t>=e.length||o>=r.length);++o)e[o+t]=r[o];return o}function b(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function ge(r){return r!==r}var dr=function(){for(var r="0123456789abcdef",e=new Array(256),t=0;t<16;++t)for(var n=t*16,o=0;o<16;++o)e[n+o]=r[t]+r[o];return e}()});var ot=Y((sn,nt)=>{i();var g=nt.exports={},D,P;function Te(){throw new Error("setTimeout has not been defined")}function xe(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?D=setTimeout:D=Te}catch(r){D=Te}try{typeof clearTimeout=="function"?P=clearTimeout:P=xe}catch(r){P=xe}})();function et(r){if(D===setTimeout)return setTimeout(r,0);if((D===Te||!D)&&setTimeout)return D=setTimeout,setTimeout(r,0);try{return D(r,0)}catch(e){try{return D.call(null,r,0)}catch(t){return D.call(this,r,0)}}}function yr(r){if(P===clearTimeout)return clearTimeout(r);if((P===xe||!P)&&clearTimeout)return P=clearTimeout,clearTimeout(r);try{return P(r)}catch(e){try{return P.call(null,r)}catch(t){return P.call(this,r)}}}var B=[],V=!1,M,te=-1;function gr(){!V||!M||(V=!1,M.length?B=M.concat(B):te=-1,B.length&&tt())}function tt(){if(!V){var r=et(gr);V=!0;for(var e=B.length;e;){for(M=B,B=[];++te<e;)M&&M[te].run();te=-1,e=B.length}M=null,V=!1,yr(r)}}g.nextTick=function(r){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];B.push(new rt(r,e)),B.length===1&&!V&&et(tt)};function rt(r,e){this.fun=r,this.array=e}rt.prototype.run=function(){this.fun.apply(null,this.array)};g.title="browser";g.browser=!0;g.env={};g.argv=[];g.version="";g.versions={};function R(){}g.on=R;g.addListener=R;g.once=R;g.off=R;g.removeListener=R;g.removeAllListeners=R;g.emit=R;g.prependListener=R;g.prependOnceListener=R;g.listeners=function(r){return[]};g.binding=function(r){throw new Error("process.binding is not supported")};g.cwd=function(){return"/"};g.chdir=function(r){throw new Error("process.chdir is not supported")};g.umask=function(){return 0}});var c,p,an,i=Nt(()=>{c=E(Je()),p=E(ot()),an=function(r){function e(){var n=this||self;return delete r.prototype.__magic__,n}if(typeof globalThis=="object")return globalThis;if(this)return e();r.defineProperty(r.prototype,"__magic__",{configurable:!0,get:e});var t=__magic__;return t}(Object)});var qr={};_t(qr,{useQueryWrapper:()=>Pe});module.exports=Mt(qr);i();var X=require("react"),Ut=require("@apollo/client");i();i();var st=E(require("react")),j=require("@apollo/client"),xr=require("@apollo/client/link/context"),wr=require("@apollo/client/link/error"),Ir=require("@apollo/client/link/ws"),Er=require("@apollo/client/utilities"),Ar=require("graphql");i();i();var re=require("react"),it=(0,re.createContext)({accessToken:"",isAuthenticated:!1}),O=()=>{let r=(0,re.useContext)(it);if(r==null)throw new Error("useAuthorizationContext must be used within a AuthorizationProvider");return r};i();i();i();i();i();i();i();var U=`
balance
decimals
name
identifier
ticker
owner
assets {
website
description
status
pngUrl
svgUrl
}
price
type
previous24hPrice
previous7dPrice
`;i();i();i();var ne=`
assets {
website
description
status
pngUrl
svgUrl
}
decimals
name
collection
ticker
`;var at=`
address
lockedToken {
${ne}
}
lpProxyToken {
${ne}
}
farmProxyToken {
${ne}
}
intermediatedPairs
intermediatedFarms
`;var we=`
address
firstToken {
${U}
}
secondToken {
${U}
}
type
feesAPR
totalFeePercent
specialFeePercent
lockedTokensInfo {
lockingSC {
${at}
}
unlockEpoch
}
`;i();var Q=`
value
receiver
gasPrice
gasLimit
data
chainID
version
`;i();var Ie=`
defaultSlippage
slippageValues
minSlippage
maxSlippage
minSwapAmount
`;i();var kr=`
__typename
valueUSD
`,ut=`
${U}
${kr}
`;i();i();var Ee=require("@apollo/client");var Ae="TRANSACTIONS_PLACEHOLDER",Sr=`
transactions {
${Q}
}
`,ct=`
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 {
${we}
}
smartSwap {
feeAmount
feePercentage
amountOut
tokenOutExchangeRateDenom
tokenInExchangeRateDenom
tokensPriceDeviationPercent
routes {
pairs {
${we}
}
tokenRoute
pricesImpact
intermediaryAmounts
fees
}
}
${Ae}
}
}
`,Fr=Ee.gql`
${ct.replace(Ae,Sr)}
`,br=Ee.gql`
${ct.replace(Ae,"")}
`;i();i();var ke=require("@apollo/client");var Dr=ke.gql`
query swapPackageFilteredTokens ($enabledSwaps: Boolean, $pagination: ConnectionArgs, $searchInput: String, $identifiers: [String!]) {
filteredTokens (pagination: $pagination, filters: {searchToken: $searchInput, enabledSwaps: $enabledSwaps, identifiers: $identifiers}) {
edges {
node {
${U}
}
cursor
}
pageInfo {
hasNextPage
}
pageData {
count
}
}
wrappingInfo {
wrappedToken {
${U}
}
}
factory {
${Ie}
}
}
`,Pr=ke.gql`
query swapPackageFilteredTokensWithBalance ($identifiers: [String!], $pagination: ConnectionArgs, $searchInput: String, $userTokensOffset: Int, $userTokensLimit: Int, $enabledSwaps: Boolean) {
filteredTokens (pagination: $pagination, filters: {searchToken: $searchInput, enabledSwaps: $enabledSwaps, identifiers: $identifiers}) {
edges {
node {
${U}
}
cursor
}
pageInfo {
hasNextPage
}
pageData {
count
}
}
userTokens (offset: $userTokensOffset, limit: $userTokensLimit) {
${ut}
}
wrappingInfo {
wrappedToken {
${U}
}
}
factory {
${Ie}
}
}
`;i();i();var pt=require("@apollo/client");var ft=pt.gql`
query swapPackageWrapEgld ($wrappingAmount: String!) {
wrapEgld(amount: $wrappingAmount) {
${Q}
}
}
`;i();var mt=require("@apollo/client");var lt=mt.gql`
query swapPackageUnwrapEgld ($wrappingAmount: String!) {
unwrapEgld(amount: $wrappingAmount) {
${Q}
}
}
`;i();i();var ht=require("@apollo/client"),Ur=ht.gql`
query swapPackageMaintenance {
factory {
maintenance
}
}
`;i();var vr=require("react");i();var De=require("react"),zr=E(require("bignumber.js"));i();i();var A=require("@multiversx/sdk-core");i();i();var S=require("@multiversx/sdk-dapp/out/constants/mvx.constants"),Br=require("@multiversx/sdk-dapp/out/constants/network.constants");i();var Rr=require("@multiversx/sdk-dapp/out/types/enums.types");i();var yt=require("@multiversx/sdk-dapp/out/utils/decoders/base64Utils");i();var gt=require("@multiversx/sdk-dapp/out/store/store"),Tt=require("@multiversx/sdk-dapp/out/store/selectors/accountSelectors");i();var oe=require("@multiversx/sdk-dapp-utils/out/constants"),W=require("@multiversx/sdk-dapp-utils/out/helpers/formatAmount"),Se=require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount"),Fe=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsFloat"),xt=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsInteger");i();i();var Lr=E(require("bignumber.js"));i();i();var Cr=E(require("bignumber.js"));i();i();i();i();i();i();i();i();i();i();i();i();i();i();i();i();i();var _r=E(require("bignumber.js"));i();i();i();i();i();var Mr=E(require("bignumber.js"));i();var $r=require("bignumber.js");i();i();var Gr=E(require("bignumber.js"));i();var Vr=E(require("bignumber.js"));i();var Qr=E(require("bignumber.js"));i();i();var At=require("react");i();var kt=require("react");i();var ie=require("react"),jr=E(require("bignumber.js"));i();i();var z=require("react"),Ft=()=>typeof document===void 0?!0:document.visibilityState==="visible",bt=()=>{let[r,e]=(0,z.useState)(Ft()),t=(0,z.useCallback)(()=>{e(Ft())},[e]);return(0,z.useEffect)(()=>{if(typeof document!==void 0)return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[t]),r};i();var se=require("react");i();var Xr=require("react");i();var Dt=require("react"),Ue=require("@apollo/client");var Xs=Ue.gql`
subscription swapPackageTokensPriceUpdated {
tokensPriceUpdated {
updates
}
}
`;i();var Pt=require("react");i();var Zr=require("react"),Kr=E(require("bignumber.js"));i();var Yr=require("react");var Pe=({query:r,queryOptions:e,refetchTrigger:t,isPollingEnabled:n=!1,pollingIntervalMiliseconds:o=2e3,isRefetchEnabled:s=!1})=>{let a=bt(),{client:l}=O(),Be=(0,Ut.useQuery)(r,C({client:l,notifyOnNetworkStatusChange:!0,fetchPolicy:"no-cache",nextFetchPolicy:"no-cache"},e)),{error:m,loading:d,previousData:y,data:h=y,refetch:I,stopPolling:x,startPolling:L}=Be,ae=Le(Be,["error","loading","previousData","data","refetch","stopPolling","startPolling"]),Z=(0,X.useCallback)(()=>{x(),a&&n&&!m&&!(e!=null&&e.skip)&&L(o)},[m,a,n,e==null?void 0:e.skip,e==null?void 0:e.variables]),ve=()=>{I(),Z()};(0,X.useEffect)(()=>(Z(),()=>{x()}),[Z]),(0,X.useEffect)(()=>{!s||t===0||(ve(),Z())},[t,s]);let vt=h==null&&d,Bt=Boolean(m);return C({data:h,error:m,isError:Bt,isLoading:vt,isRefetching:d,refetch:ve},ae)};0&&(module.exports={useQueryWrapper});
/*!
* 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=useQueryWrapper.js.map