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) 35.3 kB
"use strict";var De=Object.create;var K=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames,Mr=Object.getOwnPropertySymbols,Re=Object.getPrototypeOf,Vr=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable;var kr=(t,r,e)=>r in t?K(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,yr=(t,r)=>{for(var e in r||(r={}))Vr.call(r,e)&&kr(t,e,r[e]);if(Mr)for(var e of Mr(r))Ce.call(r,e)&&kr(t,e,r[e]);return t};var Ne=(t,r)=>()=>(t&&(r=t(t=0)),r);var or=(t,r)=>()=>(r||t((r={exports:{}}).exports,r),r.exports),Oe=(t,r)=>{for(var e in r)K(t,e,{get:r[e],enumerable:!0})},Gr=(t,r,e,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Pe(r))!Vr.call(t,i)&&i!==e&&K(t,i,{get:()=>r[i],enumerable:!(n=Ue(r,i))||n.enumerable});return t};var F=(t,r,e)=>(e=t!=null?De(Re(t)):{},Gr(r||!t||!t.__esModule?K(e,"default",{value:t,enumerable:!0}):e,t)),Le=t=>Gr(K({},"__esModule",{value:!0}),t);var Wr=or(ar=>{"use strict";s();ar.byteLength=Me;ar.toByteArray=Ve;ar.fromByteArray=He;var U=[],b=[],_e=typeof Uint8Array!="undefined"?Uint8Array:Array,dr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(k=0,qr=dr.length;k<qr;++k)U[k]=dr[k],b[dr.charCodeAt(k)]=k;var k,qr;b["-".charCodeAt(0)]=62;b["_".charCodeAt(0)]=63;function Hr(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 Me(t){var r=Hr(t),e=r[0],n=r[1];return(e+n)*3/4-n}function ke(t,r,e){return(r+e)*3/4-e}function Ve(t){var r,e=Hr(t),n=e[0],i=e[1],o=new _e(ke(t,n,i)),a=0,p=i>0?n-4:n,m;for(m=0;m<p;m+=4)r=b[t.charCodeAt(m)]<<18|b[t.charCodeAt(m+1)]<<12|b[t.charCodeAt(m+2)]<<6|b[t.charCodeAt(m+3)],o[a++]=r>>16&255,o[a++]=r>>8&255,o[a++]=r&255;return i===2&&(r=b[t.charCodeAt(m)]<<2|b[t.charCodeAt(m+1)]>>4,o[a++]=r&255),i===1&&(r=b[t.charCodeAt(m)]<<10|b[t.charCodeAt(m+1)]<<4|b[t.charCodeAt(m+2)]>>2,o[a++]=r>>8&255,o[a++]=r&255),o}function Ge(t){return U[t>>18&63]+U[t>>12&63]+U[t>>6&63]+U[t&63]}function qe(t,r,e){for(var n,i=[],o=r;o<e;o+=3)n=(t[o]<<16&16711680)+(t[o+1]<<8&65280)+(t[o+2]&255),i.push(Ge(n));return i.join("")}function He(t){for(var r,e=t.length,n=e%3,i=[],o=16383,a=0,p=e-n;a<p;a+=o)i.push(qe(t,a,a+o>p?p:a+o));return n===1?(r=t[e-1],i.push(U[r>>2]+U[r<<4&63]+"==")):n===2&&(r=(t[e-2]<<8)+t[e-1],i.push(U[r>>10]+U[r>>4&63]+U[r<<2&63]+"=")),i.join("")}});var jr=or(gr=>{s();gr.read=function(t,r,e,n,i){var o,a,p=i*8-n-1,m=(1<<p)-1,h=m>>1,d=-7,y=e?i-1:0,E=e?-1:1,w=t[r+y];for(y+=E,o=w&(1<<-d)-1,w>>=-d,d+=p;d>0;o=o*256+t[r+y],y+=E,d-=8);for(a=o&(1<<-d)-1,o>>=-d,d+=n;d>0;a=a*256+t[r+y],y+=E,d-=8);if(o===0)o=1-h;else{if(o===m)return a?NaN:(w?-1:1)*(1/0);a=a+Math.pow(2,n),o=o-h}return(w?-1:1)*a*Math.pow(2,o-n)};gr.write=function(t,r,e,n,i,o){var a,p,m,h=o*8-i-1,d=(1<<h)-1,y=d>>1,E=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,w=n?0:o-1,S=n?1:-1,q=r<0||r===0&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(p=isNaN(r)?1:0,a=d):(a=Math.floor(Math.log(r)/Math.LN2),r*(m=Math.pow(2,-a))<1&&(a--,m*=2),a+y>=1?r+=E/m:r+=E*Math.pow(2,1-y),r*m>=2&&(a++,m/=2),a+y>=d?(p=0,a=d):a+y>=1?(p=(r*m-1)*Math.pow(2,i),a=a+y):(p=r*Math.pow(2,y-1)*Math.pow(2,i),a=0));i>=8;t[e+w]=p&255,w+=S,p/=256,i-=8);for(a=a<<i|p,h+=i;h>0;t[e+w]=a&255,w+=S,a/=256,h-=8);t[e+w-S]|=q*128}});var ie=or(W=>{"use strict";s();var xr=Wr(),H=jr(),Yr=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;W.Buffer=u;W.SlowBuffer=$e;W.INSPECT_MAX_BYTES=50;var sr=2147483647;W.kMaxLength=sr;u.TYPED_ARRAY_SUPPORT=We();!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 We(){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(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 N(t){if(t>sr)throw new RangeError('The value "'+t+'" is invalid for option "size"');var r=new Uint8Array(t);return Object.setPrototypeOf(r,u.prototype),r}function u(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 Ir(t)}return $r(t,r,e)}u.poolSize=8192;function $r(t,r,e){if(typeof t=="string")return Ye(t,r);if(ArrayBuffer.isView(t))return Ze(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(P(t,ArrayBuffer)||t&&P(t.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(P(t,SharedArrayBuffer)||t&&P(t.buffer,SharedArrayBuffer)))return Tr(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 u.from(n,r,e);var i=Xe(t);if(i)return i;if(typeof Symbol!="undefined"&&Symbol.toPrimitive!=null&&typeof t[Symbol.toPrimitive]=="function")return u.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)}u.from=function(t,r,e){return $r(t,r,e)};Object.setPrototypeOf(u.prototype,Uint8Array.prototype);Object.setPrototypeOf(u,Uint8Array);function Kr(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 je(t,r,e){return Kr(t),t<=0?N(t):r!==void 0?typeof e=="string"?N(t).fill(r,e):N(t).fill(r):N(t)}u.alloc=function(t,r,e){return je(t,r,e)};function Ir(t){return Kr(t),N(t<0?0:Fr(t)|0)}u.allocUnsafe=function(t){return Ir(t)};u.allocUnsafeSlow=function(t){return Ir(t)};function Ye(t,r){if((typeof r!="string"||r==="")&&(r="utf8"),!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var e=zr(t,r)|0,n=N(e),i=n.write(t,r);return i!==e&&(n=n.slice(0,i)),n}function wr(t){for(var r=t.length<0?0:Fr(t.length)|0,e=N(r),n=0;n<r;n+=1)e[n]=t[n]&255;return e}function Ze(t){if(P(t,Uint8Array)){var r=new Uint8Array(t);return Tr(r.buffer,r.byteOffset,r.byteLength)}return wr(t)}function Tr(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,u.prototype),n}function Xe(t){if(u.isBuffer(t)){var r=Fr(t.length)|0,e=N(r);return e.length===0||t.copy(e,0,0,r),e}if(t.length!==void 0)return typeof t.length!="number"||Ar(t.length)?N(0):wr(t);if(t.type==="Buffer"&&Array.isArray(t.data))return wr(t.data)}function Fr(t){if(t>=sr)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+sr.toString(16)+" bytes");return t|0}function $e(t){return+t!=t&&(t=0),u.alloc(+t)}u.isBuffer=function(r){return r!=null&&r._isBuffer===!0&&r!==u.prototype};u.compare=function(r,e){if(P(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),P(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(r)||!u.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,i=e.length,o=0,a=Math.min(n,i);o<a;++o)if(r[o]!==e[o]){n=r[o],i=e[o];break}return n<i?-1:i<n?1:0};u.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}};u.concat=function(r,e){if(!Array.isArray(r))throw new TypeError('"list" argument must be an Array of Buffers');if(r.length===0)return u.alloc(0);var n;if(e===void 0)for(e=0,n=0;n<r.length;++n)e+=r[n].length;var i=u.allocUnsafe(e),o=0;for(n=0;n<r.length;++n){var a=r[n];if(P(a,Uint8Array))o+a.length>i.length?u.from(a).copy(i,o):Uint8Array.prototype.set.call(i,a,o);else if(u.isBuffer(a))a.copy(i,o);else throw new TypeError('"list" argument must be an Array of Buffers');o+=a.length}return i};function zr(t,r){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||P(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 i=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return Er(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e*2;case"hex":return e>>>1;case"base64":return ne(t).length;default:if(i)return n?-1:Er(t).length;r=(""+r).toLowerCase(),i=!0}}u.byteLength=zr;function Ke(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 at(this,r,e);case"utf8":case"utf-8":return Qr(this,r,e);case"ascii":return it(this,r,e);case"latin1":case"binary":return ot(this,r,e);case"base64":return tt(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return st(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}u.prototype._isBuffer=!0;function V(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}u.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)V(this,e,e+1);return this};u.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)V(this,e,e+3),V(this,e+1,e+2);return this};u.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)V(this,e,e+7),V(this,e+1,e+6),V(this,e+2,e+5),V(this,e+3,e+4);return this};u.prototype.toString=function(){var r=this.length;return r===0?"":arguments.length===0?Qr(this,0,r):Ke.apply(this,arguments)};u.prototype.toLocaleString=u.prototype.toString;u.prototype.equals=function(r){if(!u.isBuffer(r))throw new TypeError("Argument must be a Buffer");return this===r?!0:u.compare(this,r)===0};u.prototype.inspect=function(){var r="",e=W.INSPECT_MAX_BYTES;return r=this.toString("hex",0,e).replace(/(.{2})/g,"$1 ").trim(),this.length>e&&(r+=" ... "),"<Buffer "+r+">"};Yr&&(u.prototype[Yr]=u.prototype.inspect);u.prototype.compare=function(r,e,n,i,o){if(P(r,Uint8Array)&&(r=u.from(r,r.offset,r.byteLength)),!u.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),i===void 0&&(i=0),o===void 0&&(o=this.length),e<0||n>r.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&e>=n)return 0;if(i>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,i>>>=0,o>>>=0,this===r)return 0;for(var a=o-i,p=n-e,m=Math.min(a,p),h=this.slice(i,o),d=r.slice(e,n),y=0;y<m;++y)if(h[y]!==d[y]){a=h[y],p=d[y];break}return a<p?-1:p<a?1:0};function Jr(t,r,e,n,i){if(t.length===0)return-1;if(typeof e=="string"?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,Ar(e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return-1;e=t.length-1}else if(e<0)if(i)e=0;else return-1;if(typeof r=="string"&&(r=u.from(r,n)),u.isBuffer(r))return r.length===0?-1:Zr(t,r,e,n,i);if(typeof r=="number")return r=r&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):Zr(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function Zr(t,r,e,n,i){var o=1,a=t.length,p=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;o=2,a/=2,p/=2,e/=2}function m(w,S){return o===1?w[S]:w.readUInt16BE(S*o)}var h;if(i){var d=-1;for(h=e;h<a;h++)if(m(t,h)===m(r,d===-1?0:h-d)){if(d===-1&&(d=h),h-d+1===p)return d*o}else d!==-1&&(h-=h-d),d=-1}else for(e+p>a&&(e=a-p),h=e;h>=0;h--){for(var y=!0,E=0;E<p;E++)if(m(t,h+E)!==m(r,E)){y=!1;break}if(y)return h}return-1}u.prototype.includes=function(r,e,n){return this.indexOf(r,e,n)!==-1};u.prototype.indexOf=function(r,e,n){return Jr(this,r,e,n,!0)};u.prototype.lastIndexOf=function(r,e,n){return Jr(this,r,e,n,!1)};function ze(t,r,e,n){e=Number(e)||0;var i=t.length-e;n?(n=Number(n),n>i&&(n=i)):n=i;var o=r.length;n>o/2&&(n=o/2);for(var a=0;a<n;++a){var p=parseInt(r.substr(a*2,2),16);if(Ar(p))return a;t[e+a]=p}return a}function Je(t,r,e,n){return ur(Er(r,t.length-e),t,e,n)}function Qe(t,r,e,n){return ur(ct(r),t,e,n)}function rt(t,r,e,n){return ur(ne(r),t,e,n)}function et(t,r,e,n){return ur(lt(r,t.length-e),t,e,n)}u.prototype.write=function(r,e,n,i){if(e===void 0)i="utf8",n=this.length,e=0;else if(n===void 0&&typeof e=="string")i=e,n=this.length,e=0;else if(isFinite(e))e=e>>>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 o=this.length-e;if((n===void 0||n>o)&&(n=o),r.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var a=!1;;)switch(i){case"hex":return ze(this,r,e,n);case"utf8":case"utf-8":return Je(this,r,e,n);case"ascii":case"latin1":case"binary":return Qe(this,r,e,n);case"base64":return rt(this,r,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return et(this,r,e,n);default:if(a)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),a=!0}};u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function tt(t,r,e){return r===0&&e===t.length?xr.fromByteArray(t):xr.fromByteArray(t.slice(r,e))}function Qr(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i<e;){var o=t[i],a=null,p=o>239?4:o>223?3:o>191?2:1;if(i+p<=e){var m,h,d,y;switch(p){case 1:o<128&&(a=o);break;case 2:m=t[i+1],(m&192)===128&&(y=(o&31)<<6|m&63,y>127&&(a=y));break;case 3:m=t[i+1],h=t[i+2],(m&192)===128&&(h&192)===128&&(y=(o&15)<<12|(m&63)<<6|h&63,y>2047&&(y<55296||y>57343)&&(a=y));break;case 4:m=t[i+1],h=t[i+2],d=t[i+3],(m&192)===128&&(h&192)===128&&(d&192)===128&&(y=(o&15)<<18|(m&63)<<12|(h&63)<<6|d&63,y>65535&&y<1114112&&(a=y))}}a===null?(a=65533,p=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|a&1023),n.push(a),i+=p}return nt(n)}var Xr=4096;function nt(t){var r=t.length;if(r<=Xr)return String.fromCharCode.apply(String,t);for(var e="",n=0;n<r;)e+=String.fromCharCode.apply(String,t.slice(n,n+=Xr));return e}function it(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;i<e;++i)n+=String.fromCharCode(t[i]&127);return n}function ot(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;i<e;++i)n+=String.fromCharCode(t[i]);return n}function at(t,r,e){var n=t.length;(!r||r<0)&&(r=0),(!e||e<0||e>n)&&(e=n);for(var i="",o=r;o<e;++o)i+=mt[t[o]];return i}function st(t,r,e){for(var n=t.slice(r,e),i="",o=0;o<n.length-1;o+=2)i+=String.fromCharCode(n[o]+n[o+1]*256);return i}u.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 i=this.subarray(r,e);return Object.setPrototypeOf(i,u.prototype),i};function T(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")}u.prototype.readUintLE=u.prototype.readUIntLE=function(r,e,n){r=r>>>0,e=e>>>0,n||T(r,e,this.length);for(var i=this[r],o=1,a=0;++a<e&&(o*=256);)i+=this[r+a]*o;return i};u.prototype.readUintBE=u.prototype.readUIntBE=function(r,e,n){r=r>>>0,e=e>>>0,n||T(r,e,this.length);for(var i=this[r+--e],o=1;e>0&&(o*=256);)i+=this[r+--e]*o;return i};u.prototype.readUint8=u.prototype.readUInt8=function(r,e){return r=r>>>0,e||T(r,1,this.length),this[r]};u.prototype.readUint16LE=u.prototype.readUInt16LE=function(r,e){return r=r>>>0,e||T(r,2,this.length),this[r]|this[r+1]<<8};u.prototype.readUint16BE=u.prototype.readUInt16BE=function(r,e){return r=r>>>0,e||T(r,2,this.length),this[r]<<8|this[r+1]};u.prototype.readUint32LE=u.prototype.readUInt32LE=function(r,e){return r=r>>>0,e||T(r,4,this.length),(this[r]|this[r+1]<<8|this[r+2]<<16)+this[r+3]*16777216};u.prototype.readUint32BE=u.prototype.readUInt32BE=function(r,e){return r=r>>>0,e||T(r,4,this.length),this[r]*16777216+(this[r+1]<<16|this[r+2]<<8|this[r+3])};u.prototype.readIntLE=function(r,e,n){r=r>>>0,e=e>>>0,n||T(r,e,this.length);for(var i=this[r],o=1,a=0;++a<e&&(o*=256);)i+=this[r+a]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i};u.prototype.readIntBE=function(r,e,n){r=r>>>0,e=e>>>0,n||T(r,e,this.length);for(var i=e,o=1,a=this[r+--i];i>0&&(o*=256);)a+=this[r+--i]*o;return o*=128,a>=o&&(a-=Math.pow(2,8*e)),a};u.prototype.readInt8=function(r,e){return r=r>>>0,e||T(r,1,this.length),this[r]&128?(255-this[r]+1)*-1:this[r]};u.prototype.readInt16LE=function(r,e){r=r>>>0,e||T(r,2,this.length);var n=this[r]|this[r+1]<<8;return n&32768?n|4294901760:n};u.prototype.readInt16BE=function(r,e){r=r>>>0,e||T(r,2,this.length);var n=this[r+1]|this[r]<<8;return n&32768?n|4294901760:n};u.prototype.readInt32LE=function(r,e){return r=r>>>0,e||T(r,4,this.length),this[r]|this[r+1]<<8|this[r+2]<<16|this[r+3]<<24};u.prototype.readInt32BE=function(r,e){return r=r>>>0,e||T(r,4,this.length),this[r]<<24|this[r+1]<<16|this[r+2]<<8|this[r+3]};u.prototype.readFloatLE=function(r,e){return r=r>>>0,e||T(r,4,this.length),H.read(this,r,!0,23,4)};u.prototype.readFloatBE=function(r,e){return r=r>>>0,e||T(r,4,this.length),H.read(this,r,!1,23,4)};u.prototype.readDoubleLE=function(r,e){return r=r>>>0,e||T(r,8,this.length),H.read(this,r,!0,52,8)};u.prototype.readDoubleBE=function(r,e){return r=r>>>0,e||T(r,8,this.length),H.read(this,r,!1,52,8)};function A(t,r,e,n,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||r<o)throw new RangeError('"value" argument is out of bounds');if(e+n>t.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(r,e,n,i){if(r=+r,e=e>>>0,n=n>>>0,!i){var o=Math.pow(2,8*n)-1;A(this,r,e,n,o,0)}var a=1,p=0;for(this[e]=r&255;++p<n&&(a*=256);)this[e+p]=r/a&255;return e+n};u.prototype.writeUintBE=u.prototype.writeUIntBE=function(r,e,n,i){if(r=+r,e=e>>>0,n=n>>>0,!i){var o=Math.pow(2,8*n)-1;A(this,r,e,n,o,0)}var a=n-1,p=1;for(this[e+a]=r&255;--a>=0&&(p*=256);)this[e+a]=r/p&255;return e+n};u.prototype.writeUint8=u.prototype.writeUInt8=function(r,e,n){return r=+r,e=e>>>0,n||A(this,r,e,1,255,0),this[e]=r&255,e+1};u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(r,e,n){return r=+r,e=e>>>0,n||A(this,r,e,2,65535,0),this[e]=r&255,this[e+1]=r>>>8,e+2};u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(r,e,n){return r=+r,e=e>>>0,n||A(this,r,e,2,65535,0),this[e]=r>>>8,this[e+1]=r&255,e+2};u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(r,e,n){return r=+r,e=e>>>0,n||A(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};u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(r,e,n){return r=+r,e=e>>>0,n||A(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};u.prototype.writeIntLE=function(r,e,n,i){if(r=+r,e=e>>>0,!i){var o=Math.pow(2,8*n-1);A(this,r,e,n,o-1,-o)}var a=0,p=1,m=0;for(this[e]=r&255;++a<n&&(p*=256);)r<0&&m===0&&this[e+a-1]!==0&&(m=1),this[e+a]=(r/p>>0)-m&255;return e+n};u.prototype.writeIntBE=function(r,e,n,i){if(r=+r,e=e>>>0,!i){var o=Math.pow(2,8*n-1);A(this,r,e,n,o-1,-o)}var a=n-1,p=1,m=0;for(this[e+a]=r&255;--a>=0&&(p*=256);)r<0&&m===0&&this[e+a+1]!==0&&(m=1),this[e+a]=(r/p>>0)-m&255;return e+n};u.prototype.writeInt8=function(r,e,n){return r=+r,e=e>>>0,n||A(this,r,e,1,127,-128),r<0&&(r=255+r+1),this[e]=r&255,e+1};u.prototype.writeInt16LE=function(r,e,n){return r=+r,e=e>>>0,n||A(this,r,e,2,32767,-32768),this[e]=r&255,this[e+1]=r>>>8,e+2};u.prototype.writeInt16BE=function(r,e,n){return r=+r,e=e>>>0,n||A(this,r,e,2,32767,-32768),this[e]=r>>>8,this[e+1]=r&255,e+2};u.prototype.writeInt32LE=function(r,e,n){return r=+r,e=e>>>0,n||A(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};u.prototype.writeInt32BE=function(r,e,n){return r=+r,e=e>>>0,n||A(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 re(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function ee(t,r,e,n,i){return r=+r,e=e>>>0,i||re(t,r,e,4,34028234663852886e22,-34028234663852886e22),H.write(t,r,e,n,23,4),e+4}u.prototype.writeFloatLE=function(r,e,n){return ee(this,r,e,!0,n)};u.prototype.writeFloatBE=function(r,e,n){return ee(this,r,e,!1,n)};function te(t,r,e,n,i){return r=+r,e=e>>>0,i||re(t,r,e,8,17976931348623157e292,-17976931348623157e292),H.write(t,r,e,n,52,8),e+8}u.prototype.writeDoubleLE=function(r,e,n){return te(this,r,e,!0,n)};u.prototype.writeDoubleBE=function(r,e,n){return te(this,r,e,!1,n)};u.prototype.copy=function(r,e,n,i){if(!u.isBuffer(r))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),e>=r.length&&(e=r.length),e||(e=0),i>0&&i<n&&(i=n),i===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(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),r.length-e<i-n&&(i=r.length-e+n);var o=i-n;return this===r&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(e,n,i):Uint8Array.prototype.set.call(r,this.subarray(n,i),e),o};u.prototype.fill=function(r,e,n,i){if(typeof r=="string"){if(typeof e=="string"?(i=e,e=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"&&!u.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(r.length===1){var o=r.charCodeAt(0);(i==="utf8"&&o<128||i==="latin1")&&(r=o)}}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 a;if(typeof r=="number")for(a=e;a<n;++a)this[a]=r;else{var p=u.isBuffer(r)?r:u.from(r,i),m=p.length;if(m===0)throw new TypeError('The value "'+r+'" is invalid for argument "value"');for(a=0;a<n-e;++a)this[a+e]=p[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 Er(t,r){r=r||1/0;for(var e,n=t.length,i=null,o=[],a=0;a<n;++a){if(e=t.charCodeAt(a),e>55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}else if(a+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=(i-55296<<10|e-56320)+65536}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,e&63|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,e&63|128)}else if(e<1114112){if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,e&63|128)}else throw new Error("Invalid code point")}return o}function ct(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,i,o=[],a=0;a<t.length&&!((r-=2)<0);++a)e=t.charCodeAt(a),n=e>>8,i=e%256,o.push(i),o.push(n);return o}function ne(t){return xr.toByteArray(pt(t))}function ur(t,r,e,n){for(var i=0;i<n&&!(i+e>=r.length||i>=t.length);++i)r[i+e]=t[i];return i}function P(t,r){return t instanceof r||t!=null&&t.constructor!=null&&t.constructor.name!=null&&t.constructor.name===r.name}function Ar(t){return t!==t}var mt=function(){for(var t="0123456789abcdef",r=new Array(256),e=0;e<16;++e)for(var n=e*16,i=0;i<16;++i)r[n+i]=t[e]+t[i];return r}()});var pe=or((Rt,ue)=>{s();var x=ue.exports={},R,C;function Sr(){throw new Error("setTimeout has not been defined")}function vr(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?R=setTimeout:R=Sr}catch(t){R=Sr}try{typeof clearTimeout=="function"?C=clearTimeout:C=vr}catch(t){C=vr}})();function oe(t){if(R===setTimeout)return setTimeout(t,0);if((R===Sr||!R)&&setTimeout)return R=setTimeout,setTimeout(t,0);try{return R(t,0)}catch(r){try{return R.call(null,t,0)}catch(e){return R.call(this,t,0)}}}function ft(t){if(C===clearTimeout)return clearTimeout(t);if((C===vr||!C)&&clearTimeout)return C=clearTimeout,clearTimeout(t);try{return C(t)}catch(r){try{return C.call(null,t)}catch(e){return C.call(this,t)}}}var O=[],j=!1,G,pr=-1;function ht(){!j||!G||(j=!1,G.length?O=G.concat(O):pr=-1,O.length&&ae())}function ae(){if(!j){var t=oe(ht);j=!0;for(var r=O.length;r;){for(G=O,O=[];++pr<r;)G&&G[pr].run();pr=-1,r=O.length}G=null,j=!1,ft(t)}}x.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];O.push(new se(t,r)),O.length===1&&!j&&oe(ae)};function se(t,r){this.fun=t,this.array=r}se.prototype.run=function(){this.fun.apply(null,this.array)};x.title="browser";x.browser=!0;x.env={};x.argv=[];x.version="";x.versions={};function L(){}x.on=L;x.addListener=L;x.once=L;x.off=L;x.removeListener=L;x.removeAllListeners=L;x.emit=L;x.prependListener=L;x.prependOnceListener=L;x.listeners=function(t){return[]};x.binding=function(t){throw new Error("process.binding is not supported")};x.cwd=function(){return"/"};x.chdir=function(t){throw new Error("process.chdir is not supported")};x.umask=function(){return 0}});var c,l,Ct,s=Ne(()=>{c=F(ie()),l=F(pe()),Ct=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 bt={};Oe(bt,{SwapForm:()=>vt});module.exports=Le(bt);s();var g=F(require("react")),Ie=require("formik");s();s();s();s();s();s();s();s();s();s();s();s();var rr=F(require("bignumber.js"));s();s();s();s();var v=require("@multiversx/sdk-core");s();s();var B=require("@multiversx/sdk-dapp/out/constants/mvx.constants"),yt=require("@multiversx/sdk-dapp/out/constants/network.constants");s();var dt=require("@multiversx/sdk-dapp/out/types/enums.types");s();var ce=require("@multiversx/sdk-dapp/out/utils/decoders/base64Utils");s();var le=require("@multiversx/sdk-dapp/out/store/store"),me=require("@multiversx/sdk-dapp/out/store/selectors/accountSelectors");s();var z=require("@multiversx/sdk-dapp-utils/out/constants"),J=require("@multiversx/sdk-dapp-utils/out/helpers/formatAmount"),cr=require("@multiversx/sdk-dapp-utils/out/helpers/parseAmount"),Q=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsFloat"),br=require("@multiversx/sdk-dapp-utils/out/helpers/stringIsInteger");var fe=(t,r=4)=>{if(!(0,Q.stringIsFloat)(t)||new rr.default(t).isZero())return"0";let n=new rr.default(t).toFormat(r);return n=parseFloat(n)>0?n:new rr.default(t).toFormat(r+4),parseFloat(n)>0?n:new rr.default(t).toFormat(r+9)};s();s();var gt=F(require("bignumber.js"));s();var he=(t,r)=>{var a;if(!(t.indexOf(".")>=0))return!0;let n=r!=null?r:z.DECIMALS;return((a=t.split(".").pop())!=null?a:"").length<=n};s();s();s();s();s();s();var wt=F(require("bignumber.js"));s();s();s();s();s();var Et=F(require("bignumber.js"));s();var It=require("bignumber.js");s();var Z=({amount:t="0",decimals:r=0,digits:e=4,addCommas:n=!1,showLastNonZeroDecimal:i=!1})=>{if(t==null||!(0,br.stringIsInteger)(t))return"0";let o=p=>(0,J.formatAmount)({decimals:r,addCommas:n,input:t,digits:p,showLastNonZeroDecimal:i}),a=o(e);return a=parseFloat(a)>0?a:o(4+4),a=parseFloat(a)>0?a:o(4+9),parseFloat(a)>0?a:o(4+14)};s();var Ft=F(require("bignumber.js"));s();var At=F(require("bignumber.js"));s();var St=F(require("bignumber.js"));s();s();var X=require("yup");s();var de=()=>({name:"isValidNumber",message:"Only digits and one . allowed",test:t=>!t||t===""?!0:Boolean(t&&(0,Q.stringIsFloat)(t))});s();var ge=({minAcceptedAmount:t})=>({name:"minAmount",message:`Minimum amount: ${t}`,test:r=>r&&t?parseFloat(r)>=t:!0});s();var xe=()=>({name:"amount",message:"Amount required",test:t=>Boolean(t)});s();var Br=F(require("bignumber.js"));var we=t=>({name:"funds",message:"Insufficient funds",test:r=>{var e;if(r&&t&&t.balance!=null){let n=(0,cr.parseAmount)(r.toString(),t.decimals),i=new Br.default(n);return new Br.default((e=t.balance)!=null?e:"0").isGreaterThanOrEqualTo(i)}return!0}});s();var Dr=t=>({name:"token",message:"Token required",test:()=>Boolean(t)});s();var Ur=t=>({name:"decimals",message:"Too many decimals or value too small",test:r=>he(String(r),t==null?void 0:t.decimals)});s();s();var lr=(t,r)=>(r.forEach(({name:e,message:n,test:i})=>{t=t.test(e,n,i)}),t);var Te=({firstToken:t,secondToken:r,minAcceptedAmount:e,firstTokenValidations:n=[],secondTokenValidations:i=[]})=>{let o=[xe(),de(),ge({minAcceptedAmount:e})],a=[Dr(t==null?void 0:t.value),we(t==null?void 0:t.token),Ur(t==null?void 0:t.token),...n],p=lr((0,X.string)(),[...o,...a]),m=[Dr(r==null?void 0:r.value),Ur(r==null?void 0:r.token),...i],h=lr((0,X.string)(),[...o,...m]);return(0,X.object)().shape({firstAmount:p,secondAmount:h,activeRoute:(0,X.object)().required("Required")})};s();var er=F(require("react")),Ee=F(require("react-select"));s();s();var M=F(require("react"));var Pr=({value:t,token:r,isDisabled:e,inDropdown:n=!1,handleDisabledOptionClick:i})=>{var p,m,h;return M.default.createElement("div",{className:`dapp-core-swap-select-option ${e?"disabled":""}`,onClick:d=>{}},M.default.createElement("div",{style:{display:"flex",alignItems:"center",flexDirection:"row"}},M.default.createElement("div",{className:"token-image",style:{marginRight:"8px",display:"flex"}},M.default.createElement("img",{alt:t,style:{flexShrink:0,display:"flex",width:"3.25rem",height:"3.25rem",borderRadius:"50%",alignItems:"center",justifyContent:"center",backgroundColor:"#2b2d2e",border:"1px solid #49494d"},className:"token-symbol",src:(p=r==null?void 0:r.assets)==null?void 0:p.svgUrl})),M.default.createElement("div",{style:{display:"flex",flexDirection:"column"}},r.ticker," ",M.default.createElement("small",{style:{color:"#49494d"}},fe((m=r.price)!=null?m:"0")))),n&&M.default.createElement("div",{style:{display:"flex",alignItems:"end",marginLeft:"16px",flexDirection:"column"}},Z({amount:(h=r.balance)!=null?h:"",decimals:r.decimals})))};var Rr=({id:t,name:r,value:e,options:n,defaultValue:i,isSearchable:o,className:a="",disabledOption:p,disabled:m=!1,handleDisabledOptionClick:h,noOptionsMessage:d="No Tokens",onChange:y,onBlur:E,onFocus:w})=>{let S=er.default.useRef(null),q=_=>_.value===(p==null?void 0:p.value),mr=()=>(_,{context:$})=>{let{label:tr,value:D,token:fr}=_,nr=$==="menu",ir=q(_);return er.default.createElement(Pr,yr({},{inDropdown:nr,label:tr,value:D,token:fr,isDisabled:ir,handleDisabledOptionClick:h}))};return er.default.createElement("div",{className:"dapp-core-swap-select-container"},er.default.createElement(Ee.default,{ref:S,placeholder:"Select token",id:t,name:r,value:e,options:n,className:`dapp-core-swap-select ${a}`,isOptionDisabled:q,isDisabled:m,noOptionsMessage:()=>d||"No options",maxMenuHeight:260,onChange:_=>{y(_),S&&S.current!==null&&S.current.blur()},onBlur:E,onFocus:w,isSearchable:o,defaultValue:i,formatOptionLabel:mr()}))};s();var Cr=F(require("react")),Nr=({errors:t,touched:r,fieldName:e,className:n="swap-form-input-validation-error-display"})=>Cr.default.createElement("small",{className:n,style:{display:"flex",flexDirection:"column"}},e in t&&e in r&&Cr.default.createElement("div",{className:"invalid-feedback","data-testid":`invalid-${e}`,style:{display:"flex",marginTop:"8px"}},t[e]));var vt=({tokens:t,swapConfig:r,firstToken:e,firstAmount:n,secondToken:i,secondAmount:o,activeRoute:a,handleOnChangeFirstAmount:p,handleOnChangeSecondAmount:m,handleOnChangeFirstSelect:h,handleOnChangeSecondSelect:d,handleOnFirstMaxBtnChange:y,handleSwitchTokens:E,handleOnSubmit:w})=>{var Lr,_r;let S={firstAmount:"",firstToken:e,secondAmount:"",secondToken:i,activeRoute:a},q=Te({firstToken:e,secondToken:i,minAcceptedAmount:r==null?void 0:r.minSwapAmount}),mr=()=>{w&&w()},{handleSubmit:_,handleBlur:$,handleChange:tr,setFieldValue:D,setTouched:fr,errors:nr,touched:ir}=(0,Ie.useFormik)({onSubmit:mr,initialValues:S,validationSchema:q}),hr=t==null?void 0:t.map(I=>({label:I.identifier,value:I.identifier,token:I})),Or=()=>{fr({},!1),D("firstAmount",""),D("secondAmount",""),D("activeRoute",void 0)},Fe=I=>{D("firstToken",I),Or(),h(I)},Ae=I=>{D("secondToken",I),Or(),d(I)},Se=I=>{tr(I),p(I.currentTarget.value)},ve=I=>{tr(I),m(I.currentTarget.value)},be=e!=null&&e.token?Z({amount:(Lr=e.token.balance)!=null?Lr:"0",decimals:e==null?void 0:e.token.decimals}):0,Be=i!=null&&i.token?Z({amount:(_r=i.token.balance)!=null?_r:"0",decimals:i==null?void 0:i.token.decimals}):0;return(0,g.useEffect)(()=>{D("firstAmount",n,!0)},[n]),(0,g.useEffect)(()=>{D("secondAmount",o,!0)},[o]),(0,g.useEffect)(()=>{D("activeRoute",a,!0)},[a]),g.default.createElement("form",{className:"dapp-core-swap-form",noValidate:!0,onSubmit:_},g.default.createElement("div",null,g.default.createElement(Rr,{id:"firstToken",name:"firstToken",value:e,isSearchable:!1,options:hr,onChange:Fe,onBlur:$,disabledOption:i}),g.default.createElement("div",null,"Balance: ",be),g.default.createElement("input",{type:"number",min:0,step:"0.000001",name:"firstAmount",value:n,onChange:Se,onBlur:$}),g.default.createElement(Nr,{fieldName:"firstAmount",errors:nr,touched:ir}),g.default.createElement("button",{type:"button",onClick:y},"max")),g.default.createElement("br",null),g.default.createElement("button",{type:"button",onClick:E}," ","> reverse <"," "),g.default.createElement("br",null),g.default.createElement("br",null),g.default.createElement("div",null,g.default.createElement(Rr,{id:"secondToken",name:"secondToken",value:i,isSearchable:!1,options:hr,onChange:Ae,disabledOption:e}),g.default.createElement("div",null,"Balance: ",Be),g.default.createElement("input",{type:"number",min:0,step:"0.000001",name:"secondAmount",value:o,onChange:ve,onBlur:$}),g.default.createElement(Nr,{fieldName:"secondAmount",errors:nr,touched:ir})),g.default.createElement("br",null),g.default.createElement("button",{type:"submit"},"Swap"))};0&&(module.exports={SwapForm}); /*! * 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=SwapForm.js.map