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) 34.6 kB
"use strict";var Ur=Object.create;var q=Object.defineProperty;var Br=Object.getOwnPropertyDescriptor;var vr=Object.getOwnPropertyNames,X=Object.getOwnPropertySymbols,Or=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable;var Ce=(t,e,r)=>e in t?q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L=(t,e)=>{for(var r in e||(e={}))ce.call(e,r)&&Ce(t,r,e[r]);if(X)for(var r of X(e))Re.call(e,r)&&Ce(t,r,e[r]);return t};var Le=(t,e)=>{var r={};for(var n in t)ce.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&X)for(var n of X(t))e.indexOf(n)<0&&Re.call(t,n)&&(r[n]=t[n]);return r};var Cr=(t,e)=>()=>(t&&(e=t(t=0)),e);var Y=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Rr=(t,e)=>{for(var r in e)q(t,r,{get:e[r],enumerable:!0})},Ne=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of vr(e))!ce.call(t,o)&&o!==r&&q(t,o,{get:()=>e[o],enumerable:!(n=Br(e,o))||n.enumerable});return t};var F=(t,e,r)=>(r=t!=null?Ur(Or(t)):{},Ne(e||!t||!t.__esModule?q(r,"default",{value:t,enumerable:!0}):r,t)),Lr=t=>Ne(q({},"__esModule",{value:!0}),t);var Me=Y(Z=>{"use strict";i();Z.byteLength=_r;Z.toByteArray=Mr;Z.fromByteArray=Wr;var b=[],S=[],Nr=typeof Uint8Array!="undefined"?Uint8Array:Array,fe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(N=0,_e=fe.length;N<_e;++N)b[N]=fe[N],S[fe.charCodeAt(N)]=N;var N,_e;S["-".charCodeAt(0)]=62;S["_".charCodeAt(0)]=63;function $e(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 _r(t){var e=$e(t),r=e[0],n=e[1];return(r+n)*3/4-n}function $r(t,e,r){return(e+r)*3/4-r}function Mr(t){var e,r=$e(t),n=r[0],o=r[1],s=new Nr($r(t,n,o)),a=0,l=o>0?n-4:n,m;for(m=0;m<l;m+=4)e=S[t.charCodeAt(m)]<<18|S[t.charCodeAt(m+1)]<<12|S[t.charCodeAt(m+2)]<<6|S[t.charCodeAt(m+3)],s[a++]=e>>16&255,s[a++]=e>>8&255,s[a++]=e&255;return o===2&&(e=S[t.charCodeAt(m)]<<2|S[t.charCodeAt(m+1)]>>4,s[a++]=e&255),o===1&&(e=S[t.charCodeAt(m)]<<10|S[t.charCodeAt(m+1)]<<4|S[t.charCodeAt(m+2)]>>2,s[a++]=e>>8&255,s[a++]=e&255),s}function Gr(t){return b[t>>18&63]+b[t>>12&63]+b[t>>6&63]+b[t&63]}function Qr(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(Gr(n));return o.join("")}function Wr(t){for(var e,r=t.length,n=r%3,o=[],s=16383,a=0,l=r-n;a<l;a+=s)o.push(Qr(t,a,a+s>l?l:a+s));return n===1?(e=t[r-1],o.push(b[e>>2]+b[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],o.push(b[e>>10]+b[e>>4&63]+b[e<<2&63]+"=")),o.join("")}});var Ge=Y(le=>{i();le.read=function(t,e,r,n,o){var s,a,l=o*8-n-1,m=(1<<l)-1,y=m>>1,d=-7,h=r?o-1:0,w=r?-1:1,x=t[e+h];for(h+=w,s=x&(1<<-d)-1,x>>=-d,d+=l;d>0;s=s*256+t[e+h],h+=w,d-=8);for(a=s&(1<<-d)-1,s>>=-d,d+=n;d>0;a=a*256+t[e+h],h+=w,d-=8);if(s===0)s=1-y;else{if(s===m)return a?NaN:(x?-1:1)*(1/0);a=a+Math.pow(2,n),s=s-y}return(x?-1:1)*a*Math.pow(2,s-n)};le.write=function(t,e,r,n,o,s){var a,l,m,y=s*8-o-1,d=(1<<y)-1,h=d>>1,w=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,x=n?0:s-1,R=n?1:-1,z=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=d):(a=Math.floor(Math.log(e)/Math.LN2),e*(m=Math.pow(2,-a))<1&&(a--,m*=2),a+h>=1?e+=w/m:e+=w*Math.pow(2,1-h),e*m>=2&&(a++,m/=2),a+h>=d?(l=0,a=d):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;t[r+x]=l&255,x+=R,l/=256,o-=8);for(a=a<<o|l,y+=o;y>0;t[r+x]=a&255,x+=R,a/=256,y-=8);t[r+x-R]|=z*128}});var er=Y(G=>{"use strict";i();var me=Me(),M=Ge(),Qe=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;G.Buffer=u;G.SlowBuffer=Kr;G.INSPECT_MAX_BYTES=50;var J=2147483647;G.kMaxLength=J;u.TYPED_ARRAY_SUPPORT=Vr();!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 Vr(){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 B(t){if(t>J)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 Te(t)}return ze(t,e,r)}u.poolSize=8192;function ze(t,e,r){if(typeof t=="string")return qr(t,e);if(ArrayBuffer.isView(t))return Hr(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(D(t,ArrayBuffer)||t&&D(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(D(t,SharedArrayBuffer)||t&&D(t.buffer,SharedArrayBuffer)))return de(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=jr(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 ze(t,e,r)};Object.setPrototypeOf(u.prototype,Uint8Array.prototype);Object.setPrototypeOf(u,Uint8Array);function qe(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 zr(t,e,r){return qe(t),t<=0?B(t):e!==void 0?typeof r=="string"?B(t).fill(e,r):B(t).fill(e):B(t)}u.alloc=function(t,e,r){return zr(t,e,r)};function Te(t){return qe(t),B(t<0?0:ge(t)|0)}u.allocUnsafe=function(t){return Te(t)};u.allocUnsafeSlow=function(t){return Te(t)};function qr(t,e){if((typeof e!="string"||e==="")&&(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=He(t,e)|0,n=B(r),o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}function he(t){for(var e=t.length<0?0:ge(t.length)|0,r=B(e),n=0;n<e;n+=1)r[n]=t[n]&255;return r}function Hr(t){if(D(t,Uint8Array)){var e=new Uint8Array(t);return de(e.buffer,e.byteOffset,e.byteLength)}return he(t)}function de(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 jr(t){if(u.isBuffer(t)){var e=ge(t.length)|0,r=B(e);return r.length===0||t.copy(r,0,0,e),r}if(t.length!==void 0)return typeof t.length!="number"||xe(t.length)?B(0):he(t);if(t.type==="Buffer"&&Array.isArray(t.data))return he(t.data)}function ge(t){if(t>=J)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+J.toString(16)+" bytes");return t|0}function Kr(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(D(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),D(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(D(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(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||D(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 ye(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Je(t).length;default:if(o)return n?-1:ye(t).length;e=(""+e).toLowerCase(),o=!0}}u.byteLength=He;function Xr(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 st(this,e,r);case"utf8":case"utf-8":return Ke(this,e,r);case"ascii":return ot(this,e,r);case"latin1":case"binary":return it(this,e,r);case"base64":return tt(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return at(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}u.prototype._isBuffer=!0;function _(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)_(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)_(this,r,r+3),_(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)_(this,r,r+7),_(this,r+1,r+6),_(this,r+2,r+5),_(this,r+3,r+4);return this};u.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?Ke(this,0,e):Xr.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=G.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"};Qe&&(u.prototype[Qe]=u.prototype.inspect);u.prototype.compare=function(e,r,n,o,s){if(D(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,l=n-r,m=Math.min(a,l),y=this.slice(o,s),d=e.slice(r,n),h=0;h<m;++h)if(y[h]!==d[h]){a=y[h],l=d[h];break}return a<l?-1:l<a?1:0};function je(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,xe(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:We(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):We(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function We(t,e,r,n,o){var s=1,a=t.length,l=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,l/=2,r/=2}function m(x,R){return s===1?x[R]:x.readUInt16BE(R*s)}var y;if(o){var d=-1;for(y=r;y<a;y++)if(m(t,y)===m(e,d===-1?0:y-d)){if(d===-1&&(d=y),y-d+1===l)return d*s}else d!==-1&&(y-=y-d),d=-1}else for(r+l>a&&(r=a-l),y=r;y>=0;y--){for(var h=!0,w=0;w<l;w++)if(m(t,y+w)!==m(e,w)){h=!1;break}if(h)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 je(this,e,r,n,!0)};u.prototype.lastIndexOf=function(e,r,n){return je(this,e,r,n,!1)};function Yr(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 l=parseInt(e.substr(a*2,2),16);if(xe(l))return a;t[r+a]=l}return a}function Zr(t,e,r,n){return ee(ye(e,t.length-r),t,r,n)}function Jr(t,e,r,n){return ee(ct(e),t,r,n)}function et(t,e,r,n){return ee(Je(e),t,r,n)}function rt(t,e,r,n){return ee(ft(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 Yr(this,e,r,n);case"utf8":case"utf-8":return Zr(this,e,r,n);case"ascii":case"latin1":case"binary":return Jr(this,e,r,n);case"base64":return et(this,e,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return rt(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 tt(t,e,r){return e===0&&r===t.length?me.fromByteArray(t):me.fromByteArray(t.slice(e,r))}function Ke(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var s=t[o],a=null,l=s>239?4:s>223?3:s>191?2:1;if(o+l<=r){var m,y,d,h;switch(l){case 1:s<128&&(a=s);break;case 2:m=t[o+1],(m&192)===128&&(h=(s&31)<<6|m&63,h>127&&(a=h));break;case 3:m=t[o+1],y=t[o+2],(m&192)===128&&(y&192)===128&&(h=(s&15)<<12|(m&63)<<6|y&63,h>2047&&(h<55296||h>57343)&&(a=h));break;case 4:m=t[o+1],y=t[o+2],d=t[o+3],(m&192)===128&&(y&192)===128&&(d&192)===128&&(h=(s&15)<<18|(m&63)<<12|(y&63)<<6|d&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 nt(n)}var Ve=4096;function nt(t){var e=t.length;if(e<=Ve)return String.fromCharCode.apply(String,t);for(var r="",n=0;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Ve));return r}function ot(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 it(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 st(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+=lt[t[s]];return o}function at(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 g(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||g(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||g(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||g(e,1,this.length),this[e]};u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,r){return e=e>>>0,r||g(e,2,this.length),this[e]|this[e+1]<<8};u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,r){return e=e>>>0,r||g(e,2,this.length),this[e]<<8|this[e+1]};u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,r){return e=e>>>0,r||g(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||g(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||g(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||g(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||g(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};u.prototype.readInt16LE=function(e,r){e=e>>>0,r||g(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||g(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||g(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||g(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||g(e,4,this.length),M.read(this,e,!0,23,4)};u.prototype.readFloatBE=function(e,r){return e=e>>>0,r||g(e,4,this.length),M.read(this,e,!1,23,4)};u.prototype.readDoubleLE=function(e,r){return e=e>>>0,r||g(e,8,this.length),M.read(this,e,!0,52,8)};u.prototype.readDoubleBE=function(e,r){return e=e>>>0,r||g(e,8,this.length),M.read(this,e,!1,52,8)};function I(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;I(this,e,r,n,s,0)}var a=1,l=0;for(this[r]=e&255;++l<n&&(a*=256);)this[r+l]=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;I(this,e,r,n,s,0)}var a=n-1,l=1;for(this[r+a]=e&255;--a>=0&&(l*=256);)this[r+a]=e/l&255;return r+n};u.prototype.writeUint8=u.prototype.writeUInt8=function(e,r,n){return e=+e,r=r>>>0,n||I(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||I(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||I(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||I(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||I(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);I(this,e,r,n,s-1,-s)}var a=0,l=1,m=0;for(this[r]=e&255;++a<n&&(l*=256);)e<0&&m===0&&this[r+a-1]!==0&&(m=1),this[r+a]=(e/l>>0)-m&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);I(this,e,r,n,s-1,-s)}var a=n-1,l=1,m=0;for(this[r+a]=e&255;--a>=0&&(l*=256);)e<0&&m===0&&this[r+a+1]!==0&&(m=1),this[r+a]=(e/l>>0)-m&255;return r+n};u.prototype.writeInt8=function(e,r,n){return e=+e,r=r>>>0,n||I(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||I(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||I(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||I(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||I(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 Xe(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 Ye(t,e,r,n,o){return e=+e,r=r>>>0,o||Xe(t,e,r,4,34028234663852886e22,-34028234663852886e22),M.write(t,e,r,n,23,4),r+4}u.prototype.writeFloatLE=function(e,r,n){return Ye(this,e,r,!0,n)};u.prototype.writeFloatBE=function(e,r,n){return Ye(this,e,r,!1,n)};function Ze(t,e,r,n,o){return e=+e,r=r>>>0,o||Xe(t,e,r,8,17976931348623157e292,-17976931348623157e292),M.write(t,e,r,n,52,8),r+8}u.prototype.writeDoubleLE=function(e,r,n){return Ze(this,e,r,!0,n)};u.prototype.writeDoubleBE=function(e,r,n){return Ze(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 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-r;++a)this[a+r]=l[a%m]}return this};var ut=/[^+/0-9A-Za-z-_]/g;function pt(t){if(t=t.split("=")[0],t=t.trim().replace(ut,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function ye(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 ct(t){for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r)&255);return e}function ft(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 Je(t){return me.toByteArray(pt(t))}function ee(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 D(t,e){return t instanceof e||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===e.name}function xe(t){return t!==t}var lt=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 ir=Y((en,or)=>{i();var T=or.exports={},P,U;function we(){throw new Error("setTimeout has not been defined")}function Ie(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?P=setTimeout:P=we}catch(t){P=we}try{typeof clearTimeout=="function"?U=clearTimeout:U=Ie}catch(t){U=Ie}})();function rr(t){if(P===setTimeout)return setTimeout(t,0);if((P===we||!P)&&setTimeout)return P=setTimeout,setTimeout(t,0);try{return P(t,0)}catch(e){try{return P.call(null,t,0)}catch(r){return P.call(this,t,0)}}}function mt(t){if(U===clearTimeout)return clearTimeout(t);if((U===Ie||!U)&&clearTimeout)return U=clearTimeout,clearTimeout(t);try{return U(t)}catch(e){try{return U.call(null,t)}catch(r){return U.call(this,t)}}}var v=[],Q=!1,$,re=-1;function ht(){!Q||!$||(Q=!1,$.length?v=$.concat(v):re=-1,v.length&&tr())}function tr(){if(!Q){var t=rr(ht);Q=!0;for(var e=v.length;e;){for($=v,v=[];++re<e;)$&&$[re].run();re=-1,e=v.length}$=null,Q=!1,mt(t)}}T.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];v.push(new nr(t,e)),v.length===1&&!Q&&rr(tr)};function nr(t,e){this.fun=t,this.array=e}nr.prototype.run=function(){this.fun.apply(null,this.array)};T.title="browser";T.browser=!0;T.env={};T.argv=[];T.version="";T.versions={};function O(){}T.on=O;T.addListener=O;T.once=O;T.off=O;T.removeListener=O;T.removeAllListeners=O;T.emit=O;T.prependListener=O;T.prependOnceListener=O;T.listeners=function(t){return[]};T.binding=function(t){throw new Error("process.binding is not supported")};T.cwd=function(){return"/"};T.chdir=function(t){throw new Error("process.chdir is not supported")};T.umask=function(){return 0}});var p,c,rn,i=Cr(()=>{p=F(er()),c=F(ir()),rn=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 Ht={};Rr(Ht,{useFetchTokenPrices:()=>Ue});module.exports=Lr(Ht);i();var Dr=require("@apollo/client");i();i();var Ir=require("react");i();i();var yt=F(require("react")),ne=require("@apollo/client"),Tt=require("@apollo/client/link/context"),gt=require("@apollo/client/link/error"),xt=require("graphql");i();i();var te=require("react"),sr=(0,te.createContext)({accessToken:"",isAuthenticated:!1}),C=()=>{let t=(0,te.useContext)(sr);if(t==null)throw new Error("useAuthorizationContext must be used within a AuthorizationProvider");return t};i();i();i();var E=` balance decimals name identifier ticker owner assets { website description status pngUrl svgUrl } price type previous24hPrice previous7dPrice `;i();i();i();var oe=` assets { website description status pngUrl svgUrl } decimals name collection ticker `;var ar=` address lockedToken { ${oe} } lpProxyToken { ${oe} } farmProxyToken { ${oe} } intermediatedPairs intermediatedFarms `;var ur=` address firstToken { ${E} } secondToken { ${E} } type feesAPR totalFeePercent specialFeePercent lockedTokensInfo { lockingSC { ${ar} } unlockEpoch } `;i();var W=` value receiver gasPrice gasLimit data chainID version `;i();var H=` defaultSlippage slippageValues minSlippage maxSlippage minSwapAmount `;i();var wt=` __typename valueUSD `,Ee=` ${E} ${wt} `;i();i();var Ae=require("@apollo/client");var Se="TRANSACTIONS_PLACEHOLDER",It=` transactions { ${W} } `,pr=` 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 { ${ur} } ${Se} } } `,Et=Ae.gql` ${pr.replace(Se,It)} `,At=Ae.gql` ${pr.replace(Se,"")} `;i();i();var j=require("@apollo/client");var St=j.gql` query swapPackageTokens ($identifiers: [String!], $enabledSwaps: Boolean) { tokens(identifiers: $identifiers, enabledSwaps: $enabledSwaps) { ${E} } wrappingInfo { wrappedToken { ${E} } } factory { ${H} } } `,kt=j.gql` query swapPackageFilteredTokens ($enabledSwaps: Boolean, $pagination: ConnectionArgs, $searchInput: String, $identifiers: [String!]) { filteredTokens (pagination: $pagination, filters: {searchToken: $searchInput, enabledSwaps: $enabledSwaps, identifiers: $identifiers}) { edges { node { ${E} } cursor } pageInfo { hasNextPage } pageData { count } } wrappingInfo { wrappedToken { ${E} } } factory { ${H} } } `,Ft=j.gql` query swapPackageTokensWithBalance ($identifiers: [String!], $offset: Int, $limit: Int, $enabledSwaps: Boolean) { tokens(identifiers: $identifiers, enabledSwaps: $enabledSwaps) { ${E} } userTokens (offset: $offset, limit: $limit) { ${Ee} } wrappingInfo { wrappedToken { ${E} } } factory { ${H} } } `,bt=j.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 { ${E} } cursor } pageInfo { hasNextPage } pageData { count } } userTokens (offset: $offset, limit: $limit) { ${Ee} } wrappingInfo { wrappedToken { ${E} } } factory { ${H} } } `;i();i();var cr=require("@apollo/client");var fr=cr.gql` query swapPackageWrapEgld ($wrappingAmount: String!) { wrapEgld(amount: $wrappingAmount) { ${W} } } `;i();var lr=require("@apollo/client");var mr=lr.gql` query swapPackageUnwrapEgld ($wrappingAmount: String!) { unwrapEgld(amount: $wrappingAmount) { ${W} } } `;i();i();var hr=require("@apollo/client"),Dt=hr.gql` query swapPackageMaintenance { factory { maintenance } } `;i();i();var Bt=F(require("bignumber.js"));i();i();i();i();var A=require("@multiversx/sdk-core");i();i();var k=require("@multiversx/sdk-dapp/out/constants");i();var Pt=require("@multiversx/sdk-dapp/out/types/enums.types");i();var dr=require("@multiversx/sdk-dapp/out/utils/decoders/base64Utils");i();var yr=require("@multiversx/sdk-dapp/out/store/store"),Tr=require("@multiversx/sdk-dapp/out/store/selectors/accountSelectors");i();var ke=require("@multiversx/sdk-dapp-utils/out/constants"),ie=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"),gr=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsInteger");i();i();i();i();i();var vt=F(require("bignumber.js"));i();i();i();i();i();i();i();i();i();i();i();i();i();i();i();var Ot=F(require("bignumber.js"));i();i();var Ct=F(require("bignumber.js"));i();var Rt=F(require("bignumber.js"));i();var Lt=F(require("bignumber.js"));i();i();var _t=require("react");i();i();var Be=require("react"),Mt=F(require("bignumber.js"));i();var Er=require("react");i();var ue=require("react");i();var K=require("react"),Ar=require("@apollo/client");var ae=({query:t,queryOptions:e,refetchTrigger:r,isPollingEnabled:n=!1,isRefetchEnabled:o=!1})=>{let s=Sr(),{client:a}=C(),Oe=(0,Ar.useQuery)(t,L({client:a,notifyOnNetworkStatusChange:!0,fetchPolicy:"no-cache",nextFetchPolicy:"no-cache"},e)),{error:l,loading:m,previousData:y,data:d=y,refetch:h,stopPolling:w,startPolling:x}=Oe,R=Le(Oe,["error","loading","previousData","data","refetch","stopPolling","startPolling"]),z=(0,K.useCallback)(()=>{s&&n&&!l?x(6e3):w()},[s,n,l,e]);(0,K.useEffect)(()=>(z(),()=>{w()}),[z]),(0,K.useEffect)(()=>{!o||r===0||(h(),z())},[r,o]);let Pr=d==null&&m,ve=Boolean(l);return L({data:ve?void 0:d,error:l,isError:ve,isLoading:Pr,isRefetching:m,refetch:h},R)};i();i();var V=require("react"),kr=()=>typeof document===void 0?!0:document.visibilityState==="visible",Sr=()=>{let[t,e]=(0,V.useState)(kr()),r=(0,V.useCallback)(()=>{e(kr())},[e]);return(0,V.useEffect)(()=>{if(typeof document!==void 0)return document.addEventListener("visibilitychange",r),()=>document.removeEventListener("visibilitychange",r)},[r]),t};i();var pe=require("react");i();var Wt=require("react");i();var br=require("react");i();var Vt=require("react"),zt=F(require("bignumber.js"));i();var Fr=require("react");i();var qt=require("react");var Ue=({skip:t=!1,isPollingEnabled:e=!1})=>{let r=Dr.gql` query swapPackageTokenPrices { tokens(enabledSwaps: true) { price identifier } } `,{data:n,isError:o,isLoading:s}=ae({isPollingEnabled:e,query:r,queryOptions:{skip:t}});return{tokenPrices:n==null?void 0:n.tokens,isTokenPricesError:o,isTokenPricesLoading:s}};0&&(module.exports={useFetchTokenPrices}); /*! * 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=useFetchTokenPrices.js.map