@multiversx/sdk-dapp-swap
Version:
A library to hold the main logic for swapping between tokens on the MultiversX blockchain
10 lines (9 loc) • 35.1 kB
JavaScript
"use strict";var ve=Object.create;var cr=Object.defineProperty,Ue=Object.defineProperties,Pe=Object.getOwnPropertyDescriptor,be=Object.getOwnPropertyDescriptors,Oe=Object.getOwnPropertyNames,Mr=Object.getOwnPropertySymbols,Ce=Object.getPrototypeOf,Vr=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var Gr=(t,r,e)=>r in t?cr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,L=(t,r)=>{for(var e in r||(r={}))Vr.call(r,e)&&Gr(t,e,r[e]);if(Mr)for(var e of Mr(r))Ne.call(r,e)&&Gr(t,e,r[e]);return t},_=(t,r)=>Ue(t,be(r));var Le=(t,r)=>()=>(t&&(r=t(t=0)),r);var lr=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),_e=(t,r)=>{for(var e in r)cr(t,e,{get:r[e],enumerable:!0})},Hr=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Oe(r))!Vr.call(t,o)&&o!==e&&cr(t,o,{get:()=>r[o],enumerable:!(n=Pe(r,o))||n.enumerable});return t};var R=(t,r,e)=>(e=t!=null?ve(Ce(t)):{},Hr(r||!t||!t.__esModule?cr(e,"default",{value:t,enumerable:!0}):e,t)),Re=t=>Hr(cr({},"__esModule",{value:!0}),t);var jr=lr(hr=>{"use strict";u();hr.byteLength=Ge;hr.toByteArray=He;hr.fromByteArray=je;var M=[],C=[],Me=typeof Uint8Array!="undefined"?Uint8Array:Array,Ir="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(z=0,Wr=Ir.length;z<Wr;++z)M[z]=Ir[z],C[Ir.charCodeAt(z)]=z;var z,Wr;C["-".charCodeAt(0)]=62;C["_".charCodeAt(0)]=63;function qr(t){var r=t.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=t.indexOf("=");e===-1&&(e=r);var n=e===r?0:4-e%4;return[e,n]}function Ge(t){var r=qr(t),e=r[0],n=r[1];return(e+n)*3/4-n}function Ve(t,r,e){return(r+e)*3/4-e}function He(t){var r,e=qr(t),n=e[0],o=e[1],s=new Me(Ve(t,n,o)),i=0,c=o>0?n-4:n,p;for(p=0;p<c;p+=4)r=C[t.charCodeAt(p)]<<18|C[t.charCodeAt(p+1)]<<12|C[t.charCodeAt(p+2)]<<6|C[t.charCodeAt(p+3)],s[i++]=r>>16&255,s[i++]=r>>8&255,s[i++]=r&255;return o===2&&(r=C[t.charCodeAt(p)]<<2|C[t.charCodeAt(p+1)]>>4,s[i++]=r&255),o===1&&(r=C[t.charCodeAt(p)]<<10|C[t.charCodeAt(p+1)]<<4|C[t.charCodeAt(p+2)]>>2,s[i++]=r>>8&255,s[i++]=r&255),s}function We(t){return M[t>>18&63]+M[t>>12&63]+M[t>>6&63]+M[t&63]}function qe(t,r,e){for(var n,o=[],s=r;s<e;s+=3)n=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(t[s+2]&255),o.push(We(n));return o.join("")}function je(t){for(var r,e=t.length,n=e%3,o=[],s=16383,i=0,c=e-n;i<c;i+=s)o.push(qe(t,i,i+s>c?c:i+s));return n===1?(r=t[e-1],o.push(M[r>>2]+M[r<<4&63]+"==")):n===2&&(r=(t[e-2]<<8)+t[e-1],o.push(M[r>>10]+M[r>>4&63]+M[r<<2&63]+"=")),o.join("")}});var Xr=lr(Ar=>{u();Ar.read=function(t,r,e,n,o){var s,i,c=o*8-n-1,p=(1<<c)-1,x=p>>1,d=-7,y=e?o-1:0,v=e?-1:1,S=t[r+y];for(y+=v,s=S&(1<<-d)-1,S>>=-d,d+=c;d>0;s=s*256+t[r+y],y+=v,d-=8);for(i=s&(1<<-d)-1,s>>=-d,d+=n;d>0;i=i*256+t[r+y],y+=v,d-=8);if(s===0)s=1-x;else{if(s===p)return i?NaN:(S?-1:1)*(1/0);i=i+Math.pow(2,n),s=s-x}return(S?-1:1)*i*Math.pow(2,s-n)};Ar.write=function(t,r,e,n,o,s){var i,c,p,x=s*8-o-1,d=(1<<x)-1,y=d>>1,v=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,S=n?0:s-1,W=n?1:-1,q=r<0||r===0&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(c=isNaN(r)?1:0,i=d):(i=Math.floor(Math.log(r)/Math.LN2),r*(p=Math.pow(2,-i))<1&&(i--,p*=2),i+y>=1?r+=v/p:r+=v*Math.pow(2,1-y),r*p>=2&&(i++,p/=2),i+y>=d?(c=0,i=d):i+y>=1?(c=(r*p-1)*Math.pow(2,o),i=i+y):(c=r*Math.pow(2,y-1)*Math.pow(2,o),i=0));o>=8;t[e+S]=c&255,S+=W,c/=256,o-=8);for(i=i<<o|c,x+=o;x>0;t[e+S]=i&255,S+=W,i/=256,x-=8);t[e+S-W]|=q*128}});var ie=lr(nr=>{"use strict";u();var Er=jr(),tr=Xr(),Zr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;nr.Buffer=a;nr.SlowBuffer=$e;nr.INSPECT_MAX_BYTES=50;var yr=2147483647;nr.kMaxLength=yr;a.TYPED_ARRAY_SUPPORT=Xe();!a.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 Xe(){try{var t=new Uint8Array(1),r={foo:function(){return 42}};return Object.setPrototypeOf(r,Uint8Array.prototype),Object.setPrototypeOf(t,r),t.foo()===42}catch(e){return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(!!a.isBuffer(this))return this.buffer}});Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(!!a.isBuffer(this))return this.byteOffset}});function j(t){if(t>yr)throw new RangeError('The value "'+t+'" is invalid for option "size"');var r=new Uint8Array(t);return Object.setPrototypeOf(r,a.prototype),r}function a(t,r,e){if(typeof t=="number"){if(typeof r=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Sr(t)}return zr(t,r,e)}a.poolSize=8192;function zr(t,r,e){if(typeof t=="string")return Ye(t,r);if(ArrayBuffer.isView(t))return Ke(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(G(t,ArrayBuffer)||t&&G(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(G(t,SharedArrayBuffer)||t&&G(t.buffer,SharedArrayBuffer)))return Br(t,r,e);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 a.from(n,r,e);var o=ze(t);if(o)return o;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return a.from(t[Symbol.toPrimitive]("string"),r,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}a.from=function(t,r,e){return zr(t,r,e)};Object.setPrototypeOf(a.prototype,Uint8Array.prototype);Object.setPrototypeOf(a,Uint8Array);function $r(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 Ze(t,r,e){return $r(t),t<=0?j(t):r!==void 0?typeof e=="string"?j(t).fill(r,e):j(t).fill(r):j(t)}a.alloc=function(t,r,e){return Ze(t,r,e)};function Sr(t){return $r(t),j(t<0?0:kr(t)|0)}a.allocUnsafe=function(t){return Sr(t)};a.allocUnsafeSlow=function(t){return Sr(t)};function Ye(t,r){if((typeof r!="string"||r==="")&&(r="utf8"),!a.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var e=Jr(t,r)|0,n=j(e),o=n.write(t,r);return o!==e&&(n=n.slice(0,o)),n}function Fr(t){for(var r=t.length<0?0:kr(t.length)|0,e=j(r),n=0;n<r;n+=1)e[n]=t[n]&255;return e}function Ke(t){if(G(t,Uint8Array)){var r=new Uint8Array(t);return Br(r.buffer,r.byteOffset,r.byteLength)}return Fr(t)}function Br(t,r,e){if(r<0||t.byteLength<r)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<r+(e||0))throw new RangeError('"length" is outside of buffer bounds');var n;return r===void 0&&e===void 0?n=new Uint8Array(t):e===void 0?n=new Uint8Array(t,r):n=new Uint8Array(t,r,e),Object.setPrototypeOf(n,a.prototype),n}function ze(t){if(a.isBuffer(t)){var r=kr(t.length)|0,e=j(r);return e.length===0||t.copy(e,0,0,r),e}if(t.length!==void 0)return typeof t.length!="number"||vr(t.length)?j(0):Fr(t);if(t.type==="Buffer"&&Array.isArray(t.data))return Fr(t.data)}function kr(t){if(t>=yr)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+yr.toString(16)+" bytes");return t|0}function $e(t){return+t!=t&&(t=0),a.alloc(+t)}a.isBuffer=function(r){return r!=null&&r._isBuffer===!0&&r!==a.prototype};a.compare=function(r,e){if(G(r,Uint8Array)&&(r=a.from(r,r.offset,r.byteLength)),G(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(r)||!a.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(r===e)return 0;for(var n=r.length,o=e.length,s=0,i=Math.min(n,o);s<i;++s)if(r[s]!==e[s]){n=r[s],o=e[s];break}return n<o?-1:o<n?1:0};a.isEncoding=function(r){switch(String(r).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}};a.concat=function(r,e){if(!Array.isArray(r))throw new TypeError('"list" argument must be an Array of Buffers');if(r.length===0)return a.alloc(0);var n;if(e===void 0)for(e=0,n=0;n<r.length;++n)e+=r[n].length;var o=a.allocUnsafe(e),s=0;for(n=0;n<r.length;++n){var i=r[n];if(G(i,Uint8Array))s+i.length>o.length?a.from(i).copy(o,s):Uint8Array.prototype.set.call(o,i,s);else if(a.isBuffer(i))i.copy(o,s);else throw new TypeError('"list" argument must be an Array of Buffers');s+=i.length}return o};function Jr(t,r){if(a.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||G(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 e=t.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&e===0)return 0;for(var o=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return Dr(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return oe(t).length;default:if(o)return n?-1:Dr(t).length;r=(""+r).toLowerCase(),o=!0}}a.byteLength=Jr;function Je(t,r,e){var n=!1;if((r===void 0||r<0)&&(r=0),r>this.length||((e===void 0||e>this.length)&&(e=this.length),e<=0)||(e>>>=0,r>>>=0,e<=r))return"";for(t||(t="utf8");;)switch(t){case"hex":return ut(this,r,e);case"utf8":case"utf-8":return re(this,r,e);case"ascii":return st(this,r,e);case"latin1":case"binary":return at(this,r,e);case"base64":return ot(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ct(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}a.prototype._isBuffer=!0;function $(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}a.prototype.swap16=function(){var r=this.length;if(r%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<r;e+=2)$(this,e,e+1);return this};a.prototype.swap32=function(){var r=this.length;if(r%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<r;e+=4)$(this,e,e+3),$(this,e+1,e+2);return this};a.prototype.swap64=function(){var r=this.length;if(r%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<r;e+=8)$(this,e,e+7),$(this,e+1,e+6),$(this,e+2,e+5),$(this,e+3,e+4);return this};a.prototype.toString=function(){var r=this.length;return r===0?"":arguments.length===0?re(this,0,r):Je.apply(this,arguments)};a.prototype.toLocaleString=a.prototype.toString;a.prototype.equals=function(r){if(!a.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r?!0:a.compare(this,r)===0};a.prototype.inspect=function(){var r="",e=nr.INSPECT_MAX_BYTES;return r=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(r+=" ... "),"<Buffer "+r+">"};Zr&&(a.prototype[Zr]=a.prototype.inspect);a.prototype.compare=function(r,e,n,o,s){if(G(r,Uint8Array)&&(r=a.from(r,r.offset,r.byteLength)),!a.isBuffer(r))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof r);if(e===void 0&&(e=0),n===void 0&&(n=r?r.length:0),o===void 0&&(o=0),s===void 0&&(s=this.length),e<0||n>r.length||o<0||s>this.length)throw new RangeError("out of range index");if(o>=s&&e>=n)return 0;if(o>=s)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,o>>>=0,s>>>=0,this===r)return 0;for(var i=s-o,c=n-e,p=Math.min(i,c),x=this.slice(o,s),d=r.slice(e,n),y=0;y<p;++y)if(x[y]!==d[y]){i=x[y],c=d[y];break}return i<c?-1:c<i?1:0};function Qr(t,r,e,n,o){if(t.length===0)return-1;if(typeof e=="string"?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,vr(e)&&(e=o?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(o)return-1;e=t.length-1}else if(e<0)if(o)e=0;else return-1;if(typeof r=="string"&&(r=a.from(r,n)),a.isBuffer(r))return r.length===0?-1:Yr(t,r,e,n,o);if(typeof r=="number")return r=r&255,typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):Yr(t,[r],e,n,o);throw new TypeError("val must be string, number or Buffer")}function Yr(t,r,e,n,o){var s=1,i=t.length,c=r.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(t.length<2||r.length<2)return-1;s=2,i/=2,c/=2,e/=2}function p(S,W){return s===1?S[W]:S.readUInt16BE(W*s)}var x;if(o){var d=-1;for(x=e;x<i;x++)if(p(t,x)===p(r,d===-1?0:x-d)){if(d===-1&&(d=x),x-d+1===c)return d*s}else d!==-1&&(x-=x-d),d=-1}else for(e+c>i&&(e=i-c),x=e;x>=0;x--){for(var y=!0,v=0;v<c;v++)if(p(t,x+v)!==p(r,v)){y=!1;break}if(y)return x}return-1}a.prototype.includes=function(r,e,n){return this.indexOf(r,e,n)!==-1};a.prototype.indexOf=function(r,e,n){return Qr(this,r,e,n,!0)};a.prototype.lastIndexOf=function(r,e,n){return Qr(this,r,e,n,!1)};function Qe(t,r,e,n){e=Number(e)||0;var o=t.length-e;n?(n=Number(n),n>o&&(n=o)):n=o;var s=r.length;n>s/2&&(n=s/2);for(var i=0;i<n;++i){var c=parseInt(r.substr(i*2,2),16);if(vr(c))return i;t[e+i]=c}return i}function rt(t,r,e,n){return dr(Dr(r,t.length-e),t,e,n)}function et(t,r,e,n){return dr(mt(r),t,e,n)}function tt(t,r,e,n){return dr(oe(r),t,e,n)}function nt(t,r,e,n){return dr(lt(r,t.length-e),t,e,n)}a.prototype.write=function(r,e,n,o){if(e===void 0)o="utf8",n=this.length,e=0;else if(n===void 0&&typeof e=="string")o=e,n=this.length,e=0;else if(isFinite(e))e=e>>>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-e;if((n===void 0||n>s)&&(n=s),r.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");for(var i=!1;;)switch(o){case"hex":return Qe(this,r,e,n);case"utf8":case"utf-8":return rt(this,r,e,n);case"ascii":case"latin1":case"binary":return et(this,r,e,n);case"base64":return tt(this,r,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return nt(this,r,e,n);default:if(i)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),i=!0}};a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ot(t,r,e){return r===0&&e===t.length?Er.fromByteArray(t):Er.fromByteArray(t.slice(r,e))}function re(t,r,e){e=Math.min(t.length,e);for(var n=[],o=r;o<e;){var s=t[o],i=null,c=s>239?4:s>223?3:s>191?2:1;if(o+c<=e){var p,x,d,y;switch(c){case 1:s<128&&(i=s);break;case 2:p=t[o+1],(p&192)===128&&(y=(s&31)<<6|p&63,y>127&&(i=y));break;case 3:p=t[o+1],x=t[o+2],(p&192)===128&&(x&192)===128&&(y=(s&15)<<12|(p&63)<<6|x&63,y>2047&&(y<55296||y>57343)&&(i=y));break;case 4:p=t[o+1],x=t[o+2],d=t[o+3],(p&192)===128&&(x&192)===128&&(d&192)===128&&(y=(s&15)<<18|(p&63)<<12|(x&63)<<6|d&63,y>65535&&y<1114112&&(i=y))}}i===null?(i=65533,c=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),o+=c}return it(n)}var Kr=4096;function it(t){var r=t.length;if(r<=Kr)return String.fromCharCode.apply(String,t);for(var e="",n=0;n<r;)e+=String.fromCharCode.apply(String,t.slice(n,n+=Kr));return e}function st(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;o<e;++o)n+=String.fromCharCode(t[o]&127);return n}function at(t,r,e){var n="";e=Math.min(t.length,e);for(var o=r;o<e;++o)n+=String.fromCharCode(t[o]);return n}function ut(t,r,e){var n=t.length;(!r||r<0)&&(r=0),(!e||e<0||e>n)&&(e=n);for(var o="",s=r;s<e;++s)o+=ht[t[s]];return o}function ct(t,r,e){for(var n=t.slice(r,e),o="",s=0;s<n.length-1;s+=2)o+=String.fromCharCode(n[s]+n[s+1]*256);return o}a.prototype.slice=function(r,e){var n=this.length;r=~~r,e=e===void 0?n:~~e,r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),e<r&&(e=r);var o=this.subarray(r,e);return Object.setPrototypeOf(o,a.prototype),o};function D(t,r,e){if(t%1!==0||t<0)throw new RangeError("offset is not uint");if(t+r>e)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(r,e,n){r=r>>>0,e=e>>>0,n||D(r,e,this.length);for(var o=this[r],s=1,i=0;++i<e&&(s*=256);)o+=this[r+i]*s;return o};a.prototype.readUintBE=a.prototype.readUIntBE=function(r,e,n){r=r>>>0,e=e>>>0,n||D(r,e,this.length);for(var o=this[r+--e],s=1;e>0&&(s*=256);)o+=this[r+--e]*s;return o};a.prototype.readUint8=a.prototype.readUInt8=function(r,e){return r=r>>>0,e||D(r,1,this.length),this[r]};a.prototype.readUint16LE=a.prototype.readUInt16LE=function(r,e){return r=r>>>0,e||D(r,2,this.length),this[r]|this[r+1]<<8};a.prototype.readUint16BE=a.prototype.readUInt16BE=function(r,e){return r=r>>>0,e||D(r,2,this.length),this[r]<<8|this[r+1]};a.prototype.readUint32LE=a.prototype.readUInt32LE=function(r,e){return r=r>>>0,e||D(r,4,this.length),(this[r]|this[r+1]<<8|this[r+2]<<16)+this[r+3]*16777216};a.prototype.readUint32BE=a.prototype.readUInt32BE=function(r,e){return r=r>>>0,e||D(r,4,this.length),this[r]*16777216+(this[r+1]<<16|this[r+2]<<8|this[r+3])};a.prototype.readIntLE=function(r,e,n){r=r>>>0,e=e>>>0,n||D(r,e,this.length);for(var o=this[r],s=1,i=0;++i<e&&(s*=256);)o+=this[r+i]*s;return s*=128,o>=s&&(o-=Math.pow(2,8*e)),o};a.prototype.readIntBE=function(r,e,n){r=r>>>0,e=e>>>0,n||D(r,e,this.length);for(var o=e,s=1,i=this[r+--o];o>0&&(s*=256);)i+=this[r+--o]*s;return s*=128,i>=s&&(i-=Math.pow(2,8*e)),i};a.prototype.readInt8=function(r,e){return r=r>>>0,e||D(r,1,this.length),this[r]&128?(255-this[r]+1)*-1:this[r]};a.prototype.readInt16LE=function(r,e){r=r>>>0,e||D(r,2,this.length);var n=this[r]|this[r+1]<<8;return n&32768?n|4294901760:n};a.prototype.readInt16BE=function(r,e){r=r>>>0,e||D(r,2,this.length);var n=this[r+1]|this[r]<<8;return n&32768?n|4294901760:n};a.prototype.readInt32LE=function(r,e){return r=r>>>0,e||D(r,4,this.length),this[r]|this[r+1]<<8|this[r+2]<<16|this[r+3]<<24};a.prototype.readInt32BE=function(r,e){return r=r>>>0,e||D(r,4,this.length),this[r]<<24|this[r+1]<<16|this[r+2]<<8|this[r+3]};a.prototype.readFloatLE=function(r,e){return r=r>>>0,e||D(r,4,this.length),tr.read(this,r,!0,23,4)};a.prototype.readFloatBE=function(r,e){return r=r>>>0,e||D(r,4,this.length),tr.read(this,r,!1,23,4)};a.prototype.readDoubleLE=function(r,e){return r=r>>>0,e||D(r,8,this.length),tr.read(this,r,!0,52,8)};a.prototype.readDoubleBE=function(r,e){return r=r>>>0,e||D(r,8,this.length),tr.read(this,r,!1,52,8)};function P(t,r,e,n,o,s){if(!a.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>o||r<s)throw new RangeError('"value" argument is out of bounds');if(e+n>t.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(r,e,n,o){if(r=+r,e=e>>>0,n=n>>>0,!o){var s=Math.pow(2,8*n)-1;P(this,r,e,n,s,0)}var i=1,c=0;for(this[e]=r&255;++c<n&&(i*=256);)this[e+c]=r/i&255;return e+n};a.prototype.writeUintBE=a.prototype.writeUIntBE=function(r,e,n,o){if(r=+r,e=e>>>0,n=n>>>0,!o){var s=Math.pow(2,8*n)-1;P(this,r,e,n,s,0)}var i=n-1,c=1;for(this[e+i]=r&255;--i>=0&&(c*=256);)this[e+i]=r/c&255;return e+n};a.prototype.writeUint8=a.prototype.writeUInt8=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,1,255,0),this[e]=r&255,e+1};a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,2,65535,0),this[e]=r&255,this[e+1]=r>>>8,e+2};a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,2,65535,0),this[e]=r>>>8,this[e+1]=r&255,e+2};a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,4,4294967295,0),this[e+3]=r>>>24,this[e+2]=r>>>16,this[e+1]=r>>>8,this[e]=r&255,e+4};a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,4,4294967295,0),this[e]=r>>>24,this[e+1]=r>>>16,this[e+2]=r>>>8,this[e+3]=r&255,e+4};a.prototype.writeIntLE=function(r,e,n,o){if(r=+r,e=e>>>0,!o){var s=Math.pow(2,8*n-1);P(this,r,e,n,s-1,-s)}var i=0,c=1,p=0;for(this[e]=r&255;++i<n&&(c*=256);)r<0&&p===0&&this[e+i-1]!==0&&(p=1),this[e+i]=(r/c>>0)-p&255;return e+n};a.prototype.writeIntBE=function(r,e,n,o){if(r=+r,e=e>>>0,!o){var s=Math.pow(2,8*n-1);P(this,r,e,n,s-1,-s)}var i=n-1,c=1,p=0;for(this[e+i]=r&255;--i>=0&&(c*=256);)r<0&&p===0&&this[e+i+1]!==0&&(p=1),this[e+i]=(r/c>>0)-p&255;return e+n};a.prototype.writeInt8=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,1,127,-128),r<0&&(r=255+r+1),this[e]=r&255,e+1};a.prototype.writeInt16LE=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,2,32767,-32768),this[e]=r&255,this[e+1]=r>>>8,e+2};a.prototype.writeInt16BE=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,2,32767,-32768),this[e]=r>>>8,this[e+1]=r&255,e+2};a.prototype.writeInt32LE=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,4,2147483647,-2147483648),this[e]=r&255,this[e+1]=r>>>8,this[e+2]=r>>>16,this[e+3]=r>>>24,e+4};a.prototype.writeInt32BE=function(r,e,n){return r=+r,e=e>>>0,n||P(this,r,e,4,2147483647,-2147483648),r<0&&(r=4294967295+r+1),this[e]=r>>>24,this[e+1]=r>>>16,this[e+2]=r>>>8,this[e+3]=r&255,e+4};function ee(t,r,e,n,o,s){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function te(t,r,e,n,o){return r=+r,e=e>>>0,o||ee(t,r,e,4,34028234663852886e22,-34028234663852886e22),tr.write(t,r,e,n,23,4),e+4}a.prototype.writeFloatLE=function(r,e,n){return te(this,r,e,!0,n)};a.prototype.writeFloatBE=function(r,e,n){return te(this,r,e,!1,n)};function ne(t,r,e,n,o){return r=+r,e=e>>>0,o||ee(t,r,e,8,17976931348623157e292,-17976931348623157e292),tr.write(t,r,e,n,52,8),e+8}a.prototype.writeDoubleLE=function(r,e,n){return ne(this,r,e,!0,n)};a.prototype.writeDoubleBE=function(r,e,n){return ne(this,r,e,!1,n)};a.prototype.copy=function(r,e,n,o){if(!a.isBuffer(r))throw new TypeError("argument should be a Buffer");if(n||(n=0),!o&&o!==0&&(o=this.length),e>=r.length&&(e=r.length),e||(e=0),o>0&&o<n&&(o=n),o===n||r.length===0||this.length===0)return 0;if(e<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),r.length-e<o-n&&(o=r.length-e+n);var s=o-n;return this===r&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,n,o):Uint8Array.prototype.set.call(r,this.subarray(n,o),e),s};a.prototype.fill=function(r,e,n,o){if(typeof r=="string"){if(typeof e=="string"?(o=e,e=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"&&!a.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(r.length===1){var s=r.charCodeAt(0);(o==="utf8"&&s<128||o==="latin1")&&(r=s)}}else typeof r=="number"?r=r&255:typeof r=="boolean"&&(r=Number(r));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;e=e>>>0,n=n===void 0?this.length:n>>>0,r||(r=0);var i;if(typeof r=="number")for(i=e;i<n;++i)this[i]=r;else{var c=a.isBuffer(r)?r:a.from(r,o),p=c.length;if(p===0)throw new TypeError('The value "'+r+'" is invalid for argument "value"');for(i=0;i<n-e;++i)this[i+e]=c[i%p]}return this};var pt=/[^+/0-9A-Za-z-_]/g;function ft(t){if(t=t.split("=")[0],t=t.trim().replace(pt,""),t.length<2)return"";for(;t.length%4!==0;)t=t+"=";return t}function Dr(t,r){r=r||1/0;for(var e,n=t.length,o=null,s=[],i=0;i<n;++i){if(e=t.charCodeAt(i),e>55295&&e<57344){if(!o){if(e>56319){(r-=3)>-1&&s.push(239,191,189);continue}else if(i+1===n){(r-=3)>-1&&s.push(239,191,189);continue}o=e;continue}if(e<56320){(r-=3)>-1&&s.push(239,191,189),o=e;continue}e=(o-55296<<10|e-56320)+65536}else o&&(r-=3)>-1&&s.push(239,191,189);if(o=null,e<128){if((r-=1)<0)break;s.push(e)}else if(e<2048){if((r-=2)<0)break;s.push(e>>6|192,e&63|128)}else if(e<65536){if((r-=3)<0)break;s.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((r-=4)<0)break;s.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return s}function mt(t){for(var r=[],e=0;e<t.length;++e)r.push(t.charCodeAt(e)&255);return r}function lt(t,r){for(var e,n,o,s=[],i=0;i<t.length&&!((r-=2)<0);++i)e=t.charCodeAt(i),n=e>>8,o=e%256,s.push(o),s.push(n);return s}function oe(t){return Er.toByteArray(ft(t))}function dr(t,r,e,n){for(var o=0;o<n&&!(o+e>=r.length||o>=t.length);++o)r[o+e]=t[o];return o}function G(t,r){return t instanceof r||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===r.name}function vr(t){return t!==t}var ht=function(){for(var t="0123456789abcdef",r=new Array(256),e=0;e<16;++e)for(var n=e*16,o=0;o<16;++o)r[n+o]=t[e]+t[o];return r}()});var pe=lr((Ct,ce)=>{u();var E=ce.exports={},V,H;function Ur(){throw new Error("setTimeout has not been defined")}function Pr(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?V=setTimeout:V=Ur}catch(t){V=Ur}try{typeof clearTimeout=="function"?H=clearTimeout:H=Pr}catch(t){H=Pr}})();function se(t){if(V===setTimeout)return setTimeout(t,0);if((V===Ur||!V)&&setTimeout)return V=setTimeout,setTimeout(t,0);try{return V(t,0)}catch(r){try{return V.call(null,t,0)}catch(e){return V.call(this,t,0)}}}function yt(t){if(H===clearTimeout)return clearTimeout(t);if((H===Pr||!H)&&clearTimeout)return H=clearTimeout,clearTimeout(t);try{return H(t)}catch(r){try{return H.call(null,t)}catch(e){return H.call(this,t)}}}var X=[],or=!1,J,xr=-1;function dt(){!or||!J||(or=!1,J.length?X=J.concat(X):xr=-1,X.length&&ae())}function ae(){if(!or){var t=se(dt);or=!0;for(var r=X.length;r;){for(J=X,X=[];++xr<r;)J&&J[xr].run();xr=-1,r=X.length}J=null,or=!1,yt(t)}}E.nextTick=function(t){var r=new Array(arguments.length-1);if(arguments.length>1)for(var e=1;e<arguments.length;e++)r[e-1]=arguments[e];X.push(new ue(t,r)),X.length===1&&!or&&se(ae)};function ue(t,r){this.fun=t,this.array=r}ue.prototype.run=function(){this.fun.apply(null,this.array)};E.title="browser";E.browser=!0;E.env={};E.argv=[];E.version="";E.versions={};function Z(){}E.on=Z;E.addListener=Z;E.once=Z;E.off=Z;E.removeListener=Z;E.removeAllListeners=Z;E.emit=Z;E.prependListener=Z;E.prependOnceListener=Z;E.listeners=function(t){return[]};E.binding=function(t){throw new Error("process.binding is not supported")};E.cwd=function(){return"/"};E.chdir=function(t){throw new Error("process.chdir is not supported")};E.umask=function(){return 0}});var m,l,Nt,u=Le(()=>{m=R(ie()),l=R(pe()),Nt=function(t){function r(){var n=this||self;return delete t.prototype.__magic__,n}if(typeof globalThis=="object")return globalThis;if(this)return r();t.defineProperty(t.prototype,"__magic__",{configurable:!0,get:r});var e=__magic__;return e}(Object)});var vt={};_e(vt,{useSwapFormHandlers:()=>kt});module.exports=Re(vt);u();var ar=require("react");u();var Q="EGLD";var fe="10000000000000000";u();u();var b=require("@multiversx/sdk-core");u();u();var N=require("@multiversx/sdk-dapp/out/constants/mvx.constants"),xt=require("@multiversx/sdk-dapp/out/constants/network.constants");u();var gt=require("@multiversx/sdk-dapp/out/types/enums.types");u();var me=require("@multiversx/sdk-dapp/out/utils/decoders/base64Utils");u();var le=require("@multiversx/sdk-dapp/out/store/store"),he=require("@multiversx/sdk-dapp/out/store/selectors/accountSelectors");u();var pr=require("@multiversx/sdk-dapp-utils/out/constants"),rr=require("@multiversx/sdk-dapp-utils/out/helpers/formatAmount"),Y=require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount"),ir=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsFloat"),br=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsInteger");u();u();var fr=R(require("bignumber.js"));u();var ye=(t,r=4)=>{if(!(0,ir.stringIsFloat)(t)||new fr.default(t).isZero())return"0";let n=new fr.default(t).toFormat(r);return n=parseFloat(n)>0?n:new fr.default(t).toFormat(r+4),parseFloat(n)>0?n:new fr.default(t).toFormat(r+9)};u();u();var Tt=R(require("bignumber.js"));u();u();u();u();u();u();u();u();u();u();u();u();u();u();u();u();var gr=({pairs:t,identifier:r})=>{var o;if(r===Q||r.startsWith(`W${Q}-`))return pr.DECIMALS;let n;return t.forEach(({firstToken:s,secondToken:i})=>{if(s.identifier===r){n=s;return}if(i.identifier===r){n=i;return}}),(o=n==null?void 0:n.decimals)!=null?o:0};u();var It=R(require("bignumber.js"));u();u();u();u();u();var Or=R(require("bignumber.js"));var de=t=>{let r=new Or.default(t!=null?t:"0"),e=new Or.default(fe),n=r.minus(e);return n.isGreaterThan(0)?n.toString(10):"0"};u();var Et=require("bignumber.js");u();var er=({amount:t="0",decimals:r=0,digits:e=4,addCommas:n=!1,showLastNonZeroDecimal:o=!1})=>{if(t==null||!(0,br.stringIsInteger)(t))return"0";let s=c=>(0,rr.formatAmount)({decimals:r,addCommas:n,input:t,digits:c,showLastNonZeroDecimal:o}),i=s(e);return i=parseFloat(i)>0?i:s(4+4),i=parseFloat(i)>0?i:s(4+9),parseFloat(i)>0?i:s(4+14)};u();var Ft=R(require("bignumber.js"));u();var Bt=R(require("bignumber.js"));u();var Dt=R(require("bignumber.js"));u();var Cr=({newToken:t,firstToken:r,secondToken:e,activeRoute:n,needsParsing:o})=>{if(!n||!t)return{amountIn:void 0,amountOut:void 0};let s=(n==null?void 0:n.swapType)===0,i=s?n==null?void 0:n.amountIn:n==null?void 0:n.amountOut,p=(s?n==null?void 0:n.tokenInID:n==null?void 0:n.tokenOutID)===(r==null?void 0:r.identifier)?r==null?void 0:r.decimals:e==null?void 0:e.decimals,x=er({amount:i,showLastNonZeroDecimal:!0,decimals:p}),d=o?(0,Y.parseAmount)(x,t==null?void 0:t.decimals):i;return{amountIn:s?d:void 0,amountOut:s?void 0:d}};u();var xe=require("react"),Nr=R(require("bignumber.js"));var ge=({swapRoute:t,firstToken:r,firstAmount:e,secondToken:n,secondAmount:o})=>(0,xe.useMemo)(()=>{var F;if(!t)return{firstAmountUsdValue:void 0,secondAmountUsdValue:void 0};let{swapType:s,amountIn:i,tokenInID:c,tokenOutID:p,tokenInPriceUSD:x,tokenOutPriceUSD:d,smartSwap:y}=t,v=(F=y==null?void 0:y.amountOut)!=null?F:t.amountOut,S=s===0,q=Boolean(s===1&&o&&(r==null?void 0:r.value)===c),mr=Boolean(S&&e&&(n==null?void 0:n.value)===p);if(!q&&!mr)return{firstAmountUsdValue:void 0,secondAmountUsdValue:void 0};let f=q?i:v,g=q?r==null?void 0:r.token.decimals:n==null?void 0:n.token.decimals,I=q?x:d,B=(0,rr.formatAmount)({input:f,decimals:g,showLastNonZeroDecimal:!0}).replace(/,/g,""),A=new Nr.default(B).times(new Nr.default(I)).toString(10),T=ye(A,2);return{firstAmountUsdValue:q?T:void 0,secondAmountUsdValue:mr?T:void 0}},[t,o,e,r,n]);u();var wr=require("react"),Te=t=>{let r=(0,wr.useRef)(void 0);return(0,wr.useEffect)(()=>{r.current=t},[t]),r.current};var kt=({getSwapRoute:t,tolerancePercentage:r})=>{let[e,n]=(0,ar.useState)({firstAmount:"",secondAmount:""}),[o,s]=(0,ar.useState)(),i=(0,ar.useRef)(),c=(0,ar.useRef)(),p=Te(e.secondToken),x=ge({swapRoute:o,firstToken:e.firstToken,firstAmount:e.firstAmount,secondToken:e.secondToken,secondAmount:e.secondAmount}),d=f=>{var _r,Rr;if(!f){s(void 0);return}let{swapType:g,tokenInID:I,tokenOutID:w,amountIn:B,pairs:A,smartSwap:T}=f,F=(_r=T==null?void 0:T.amountOut)!=null?_r:f.amountOut,U=(Rr=T==null?void 0:T.tokensPriceDeviationPercent)!=null?Rr:f.tokensPriceDeviationPercent;s(_(L({},f),{tokensPriceDeviationPercent:U}));let k=g===0,O=k?F:B,we=gr({identifier:k?w:I,pairs:A}),Lr=er({amount:O,decimals:we}),Ie=k&&Boolean(e.firstAmount),Ae=!k&&Boolean(e.secondAmount);if(i.current){let ur=gr({identifier:f.tokenInID,pairs:A}),Ee=gr({identifier:f.tokenOutID,pairs:A}),Fe=er({amount:f.amountIn,decimals:ur}),Be=er({amount:f.amountOut,decimals:Ee}),De=Fe,Se=Be;n(ke=>_(L({},ke),{firstAmount:De,secondAmount:Se})),i.current=!1}else n(ur=>_(L({},ur),{firstAmount:Ae?Lr:ur.firstAmount,secondAmount:Ie?Lr:ur.secondAmount}))},y=f=>{i.current||n(g=>{var A,T,F;let I=(A=g.firstToken)==null?void 0:A.value,w=(T=g.secondToken)==null?void 0:T.value;if(I!=null&&w!=null){c.current="first";let U=(F=g.firstToken)==null?void 0:F.token.decimals,k=(0,ir.stringIsFloat)(f)?(0,Y.parseAmount)(f,U):"";t({amountIn:k,tokenInID:I,tokenOutID:w,tolerancePercentage:r})}return _(L({},g),{firstAmount:f,secondAmount:Boolean(f)?g.secondAmount:""})})},v=f=>{i.current||n(g=>{var A,T,F;let I=(A=g.firstToken)==null?void 0:A.value,w=(T=g.secondToken)==null?void 0:T.value;if(I!=null&&w!=null){c.current="second";let U=(F=g.secondToken)==null?void 0:F.token.decimals,k=(0,ir.stringIsFloat)(f)?(0,Y.parseAmount)(f,U):"";t({amountOut:k,tokenInID:I,tokenOutID:w,tolerancePercentage:r})}return _(L({},g),{secondAmount:f,firstAmount:Boolean(f)?g.firstAmount:""})})},S=f=>{i.current||n(g=>{var A,T,F;let I=f==null?void 0:f.value,w=(A=g.secondToken)==null?void 0:A.value;if(I!=null&&w!=null){let U=(o==null?void 0:o.swapType)===0,{amountIn:k,amountOut:O}=Cr({activeRoute:o,newToken:f==null?void 0:f.token,needsParsing:U,firstToken:(T=g.firstToken)==null?void 0:T.token,secondToken:(F=g.secondToken)==null?void 0:F.token});t({amountIn:k,amountOut:O,tokenInID:I,tokenOutID:w,tolerancePercentage:r})}return _(L({},g),{firstToken:f})})},W=f=>{i.current||(n(g=>{var A,T,F;let I=f==null?void 0:f.value,w=(A=g.firstToken)==null?void 0:A.value;if(w!=null&&I!=null){let U=(o==null?void 0:o.swapType)===1,{amountIn:k,amountOut:O}=Cr({activeRoute:o,newToken:f==null?void 0:f.token,needsParsing:U,firstToken:(T=g.firstToken)==null?void 0:T.token,secondToken:(F=g.secondToken)==null?void 0:F.token});t({amountIn:k,amountOut:O,tokenInID:w,tokenOutID:I,tolerancePercentage:r})}return _(L({},g),{secondToken:f})}),!p&&e.firstAmount&&y(e.firstAmount))},q=()=>{n(f=>{var F,U,k,O,K;let g=(F=f.firstToken)==null?void 0:F.value,I=(U=f.secondToken)==null?void 0:U.value,w=(O=(k=f.firstToken)==null?void 0:k.token.balance)!=null?O:"0",B=g===Q?de(w):w;if(!(g!=null&&I!=null))return f;let T=er({amount:B,decimals:(K=f.firstToken)==null?void 0:K.token.decimals});return t({amountIn:B,tokenInID:g,tokenOutID:I,tolerancePercentage:r}),_(L({},f),{firstAmount:T})})},mr=()=>{n(f=>{let g=f.secondAmount,I=f.firstAmount,w=f.secondToken,B=f.firstToken,A=w==null?void 0:w.value,T=B==null?void 0:B.value;if(!(A!=null&&T!=null))return f;i.current=c.current!==void 0&&g!==""&&I!=="";let U=c.current==="first"&&I!=="",k=c.current==="second"&&g!=="";if(U){c.current="second";let O=B==null?void 0:B.token.decimals,K=(0,Y.parseAmount)(I,O);t({amountOut:K,tokenInID:A,tokenOutID:T,tolerancePercentage:r})}if(k){c.current="first";let O=w==null?void 0:w.token.decimals,K=(0,Y.parseAmount)(g,O);t({amountIn:K,tokenInID:A,tokenOutID:T,tolerancePercentage:r})}return{firstAmount:g,secondAmount:I,firstToken:w,secondToken:B}})};return{firstToken:e.firstToken,firstAmount:e.firstAmount,secondToken:e.secondToken,secondAmount:e.secondAmount,activeRoute:o,inputAmountsUsdValue:x,handleOnChangeFirstAmount:y,handleOnChangeSecondAmount:v,handleOnChangeFirstSelect:S,handleOnChangeSecondSelect:W,handleOnChangeSwapRoute:d,handleOnFirstMaxBtnChange:q,handleSwitchTokens:mr}};0&&(module.exports={useSwapFormHandlers});
/*!
* 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=useSwapFormHandlers.js.map