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