UNPKG

@multiversx/sdk-dapp-swap

Version:

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

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