@ultrade/ultrade-js-sdk
Version:
This package contains the original js/ts SDK.
1 lines • 57.5 kB
JavaScript
function te(){throw new Error("setTimeout has not been defined")}function re(){throw new Error("clearTimeout has not been defined")}var w=te,S=re;typeof globalThis.setTimeout=="function"&&(w=setTimeout);typeof globalThis.clearTimeout=="function"&&(S=clearTimeout);function ie(i){if(w===setTimeout)return setTimeout(i,0);if((w===te||!w)&&setTimeout)return w=setTimeout,setTimeout(i,0);try{return w(i,0)}catch{try{return w.call(null,i,0)}catch{return w.call(this,i,0)}}}function De(i){if(S===clearTimeout)return clearTimeout(i);if((S===re||!S)&&clearTimeout)return S=clearTimeout,clearTimeout(i);try{return S(i)}catch{try{return S.call(null,i)}catch{return S.call(this,i)}}}var _=[],N=!1,P,O=-1;function We(){!N||!P||(N=!1,P.length?_=P.concat(_):O=-1,_.length&&ne())}function ne(){if(!N){var i=ie(We);N=!0;for(var e=_.length;e;){for(P=_,_=[];++O<e;)P&&P[O].run();O=-1,e=_.length}P=null,N=!1,De(i)}}function Ne(i){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];_.push(new se(i,e)),_.length===1&&!N&&ie(ne)}function se(i,e){this.fun=i,this.array=e}se.prototype.run=function(){this.fun.apply(null,this.array)};var Ue="browser",ve="browser",Fe=!0,Ge={},Oe=[],Ce="",Le={},Ve={},Ye={};function k(){}var $e=k,Be=k,Xe=k,qe=k,Ze=k,ze=k,Qe=k;function Je(i){throw new Error("process.binding is not supported")}function je(){return"/"}function Ke(i){throw new Error("process.chdir is not supported")}function He(){return 0}var W=globalThis.performance||{},et=W.now||W.mozNow||W.msNow||W.oNow||W.webkitNow||function(){return new Date().getTime()};function tt(i){var e=et.call(W)*.001,t=Math.floor(e),r=Math.floor(e%1*1e9);return i&&(t=t-i[0],r=r-i[1],r<0&&(t--,r+=1e9)),[t,r]}var rt=new Date;function it(){var i=new Date,e=i-rt;return e/1e3}var g={nextTick:Ne,title:Ue,browser:Fe,env:Ge,argv:Oe,version:Ce,versions:Le,on:$e,addListener:Be,once:Xe,off:qe,removeListener:Ze,removeAllListeners:ze,emit:Qe,binding:Je,cwd:je,chdir:Ke,umask:He,hrtime:tt,platform:ve,release:Ve,config:Ye,uptime:it},ee={};Object.keys(ee).forEach(i=>{let e=i.split("."),t=g;for(let r=0;r<e.length;r++){let n=e[r];r===e.length-1?t[n]=ee[i]:t=t[n]||(t[n]={})}});var A=[],b=[],nt=typeof Uint8Array<"u"?Uint8Array:Array,Z=!1;function ce(){Z=!0;for(var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,t=i.length;e<t;++e)A[e]=i[e],b[i.charCodeAt(e)]=e;b[45]=62,b[95]=63}function st(i){Z||ce();var e,t,r,n,s,o,c=i.length;if(c%4>0)throw new Error("Invalid string. Length must be a multiple of 4");s=i[c-2]==="="?2:i[c-1]==="="?1:0,o=new nt(c*3/4-s),r=s>0?c-4:c;var u=0;for(e=0,t=0;e<r;e+=4,t+=3)n=b[i.charCodeAt(e)]<<18|b[i.charCodeAt(e+1)]<<12|b[i.charCodeAt(e+2)]<<6|b[i.charCodeAt(e+3)],o[u++]=n>>16&255,o[u++]=n>>8&255,o[u++]=n&255;return s===2?(n=b[i.charCodeAt(e)]<<2|b[i.charCodeAt(e+1)]>>4,o[u++]=n&255):s===1&&(n=b[i.charCodeAt(e)]<<10|b[i.charCodeAt(e+1)]<<4|b[i.charCodeAt(e+2)]>>2,o[u++]=n>>8&255,o[u++]=n&255),o}function at(i){return A[i>>18&63]+A[i>>12&63]+A[i>>6&63]+A[i&63]}function ot(i,e,t){for(var r,n=[],s=e;s<t;s+=3)r=(i[s]<<16)+(i[s+1]<<8)+i[s+2],n.push(at(r));return n.join("")}function ae(i){Z||ce();for(var e,t=i.length,r=t%3,n="",s=[],o=16383,c=0,u=t-r;c<u;c+=o)s.push(ot(i,c,c+o>u?u:c+o));return r===1?(e=i[t-1],n+=A[e>>2],n+=A[e<<4&63],n+="=="):r===2&&(e=(i[t-2]<<8)+i[t-1],n+=A[e>>10],n+=A[e>>4&63],n+=A[e<<2&63],n+="="),s.push(n),s.join("")}l.TYPED_ARRAY_SUPPORT=globalThis.TYPED_ARRAY_SUPPORT!==void 0?globalThis.TYPED_ARRAY_SUPPORT:!0;function C(){return l.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function y(i,e){if(C()<e)throw new RangeError("Invalid typed array length");return l.TYPED_ARRAY_SUPPORT?(i=new Uint8Array(e),i.__proto__=l.prototype):(i===null&&(i=new l(e)),i.length=e),i}function l(i,e,t){if(!l.TYPED_ARRAY_SUPPORT&&!(this instanceof l))return new l(i,e,t);if(typeof i=="number"){if(typeof e=="string")throw new Error("If encoding is specified then the first argument must be a string");return z(this,i)}return ue(this,i,e,t)}l.poolSize=8192;l._augment=function(i){return i.__proto__=l.prototype,i};function ue(i,e,t,r){if(typeof e=="number")throw new TypeError('"value" argument must not be a number');return typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer?ut(i,e,t,r):typeof e=="string"?ct(i,e,t):dt(i,e)}l.from=function(i,e,t){return ue(null,i,e,t)};l.kMaxLength=C();l.TYPED_ARRAY_SUPPORT&&(l.prototype.__proto__=Uint8Array.prototype,l.__proto__=Uint8Array,typeof Symbol<"u"&&Symbol.species&&l[Symbol.species]);function de(i){if(typeof i!="number")throw new TypeError('"size" argument must be a number');if(i<0)throw new RangeError('"size" argument must not be negative')}function lt(i,e,t,r){return de(e),e<=0?y(i,e):t!==void 0?typeof r=="string"?y(i,e).fill(t,r):y(i,e).fill(t):y(i,e)}l.alloc=function(i,e,t){return lt(null,i,e,t)};function z(i,e){if(de(e),i=y(i,e<0?0:Q(e)|0),!l.TYPED_ARRAY_SUPPORT)for(var t=0;t<e;++t)i[t]=0;return i}l.allocUnsafe=function(i){return z(null,i)};l.allocUnsafeSlow=function(i){return z(null,i)};function ct(i,e,t){if((typeof t!="string"||t==="")&&(t="utf8"),!l.isEncoding(t))throw new TypeError('"encoding" must be a valid string encoding');var r=me(e,t)|0;i=y(i,r);var n=i.write(e,t);return n!==r&&(i=i.slice(0,n)),i}function q(i,e){var t=e.length<0?0:Q(e.length)|0;i=y(i,t);for(var r=0;r<t;r+=1)i[r]=e[r]&255;return i}function ut(i,e,t,r){if(e.byteLength,t<0||e.byteLength<t)throw new RangeError("'offset' is out of bounds");if(e.byteLength<t+(r||0))throw new RangeError("'length' is out of bounds");return t===void 0&&r===void 0?e=new Uint8Array(e):r===void 0?e=new Uint8Array(e,t):e=new Uint8Array(e,t,r),l.TYPED_ARRAY_SUPPORT?(i=e,i.__proto__=l.prototype):i=q(i,e),i}function dt(i,e){if(x(e)){var t=Q(e.length)|0;return i=y(i,t),i.length===0||e.copy(i,0,0,t),i}if(e){if(typeof ArrayBuffer<"u"&&e.buffer instanceof ArrayBuffer||"length"in e)return typeof e.length!="number"||Mt(e.length)?y(i,0):q(i,e);if(e.type==="Buffer"&&Array.isArray(e.data))return q(i,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function Q(i){if(i>=C())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+C().toString(16)+" bytes");return i|0}l.isBuffer=Dt;function x(i){return!!(i!=null&&i._isBuffer)}l.compare=function(e,t){if(!x(e)||!x(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,s=0,o=Math.min(r,n);s<o;++s)if(e[s]!==t[s]){r=e[s],n=t[s];break}return r<n?-1:n<r?1:0};l.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};l.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return l.alloc(0);var r;if(t===void 0)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=l.allocUnsafe(t),s=0;for(r=0;r<e.length;++r){var o=e[r];if(!x(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(n,s),s+=o.length}return n};function me(i,e){if(x(i))return i.length;if(typeof ArrayBuffer<"u"&&typeof ArrayBuffer.isView=="function"&&(ArrayBuffer.isView(i)||i instanceof ArrayBuffer))return i.byteLength;typeof i!="string"&&(i=""+i);var t=i.length;if(t===0)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":case void 0:return L(i).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return be(i).length;default:if(r)return L(i).length;e=(""+e).toLowerCase(),r=!0}}l.byteLength=me;function mt(i,e,t){var r=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(i||(i="utf8");;)switch(i){case"hex":return xt(this,e,t);case"utf8":case"utf-8":return fe(this,e,t);case"ascii":return It(this,e,t);case"latin1":case"binary":return At(this,e,t);case"base64":return Et(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _t(this,e,t);default:if(r)throw new TypeError("Unknown encoding: "+i);i=(i+"").toLowerCase(),r=!0}}l.prototype._isBuffer=!0;function R(i,e,t){var r=i[e];i[e]=i[t],i[t]=r}l.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)R(this,t,t+1);return this};l.prototype.swap32=function(){var e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)R(this,t,t+3),R(this,t+1,t+2);return this};l.prototype.swap64=function(){var e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)R(this,t,t+7),R(this,t+1,t+6),R(this,t+2,t+5),R(this,t+3,t+4);return this};l.prototype.toString=function(){var e=this.length|0;return e===0?"":arguments.length===0?fe(this,0,e):mt.apply(this,arguments)};l.prototype.equals=function(e){if(!x(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:l.compare(this,e)===0};l.prototype.compare=function(e,t,r,n,s){if(!x(e))throw new TypeError("Argument must be a Buffer");if(t===void 0&&(t=0),r===void 0&&(r=e?e.length:0),n===void 0&&(n=0),s===void 0&&(s=this.length),t<0||r>e.length||n<0||s>this.length)throw new RangeError("out of range index");if(n>=s&&t>=r)return 0;if(n>=s)return-1;if(t>=r)return 1;if(t>>>=0,r>>>=0,n>>>=0,s>>>=0,this===e)return 0;for(var o=s-n,c=r-t,u=Math.min(o,c),d=this.slice(n,s),m=e.slice(t,r),p=0;p<u;++p)if(d[p]!==m[p]){o=d[p],c=m[p];break}return o<c?-1:c<o?1:0};function ge(i,e,t,r,n){if(i.length===0)return-1;if(typeof t=="string"?(r=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,isNaN(t)&&(t=n?0:i.length-1),t<0&&(t=i.length+t),t>=i.length){if(n)return-1;t=i.length-1}else if(t<0)if(n)t=0;else return-1;if(typeof e=="string"&&(e=l.from(e,r)),x(e))return e.length===0?-1:oe(i,e,t,r,n);if(typeof e=="number")return e=e&255,l.TYPED_ARRAY_SUPPORT&&typeof Uint8Array.prototype.indexOf=="function"?n?Uint8Array.prototype.indexOf.call(i,e,t):Uint8Array.prototype.lastIndexOf.call(i,e,t):oe(i,[e],t,r,n);throw new TypeError("val must be string, number or Buffer")}function oe(i,e,t,r,n){var s=1,o=i.length,c=e.length;if(r!==void 0&&(r=String(r).toLowerCase(),r==="ucs2"||r==="ucs-2"||r==="utf16le"||r==="utf-16le")){if(i.length<2||e.length<2)return-1;s=2,o/=2,c/=2,t/=2}function u(E,D){return s===1?E[D]:E.readUInt16BE(D*s)}var d;if(n){var m=-1;for(d=t;d<o;d++)if(u(i,d)===u(e,m===-1?0:d-m)){if(m===-1&&(m=d),d-m+1===c)return m*s}else m!==-1&&(d-=d-m),m=-1}else for(t+c>o&&(t=o-c),d=t;d>=0;d--){for(var p=!0,I=0;I<c;I++)if(u(i,d+I)!==u(e,I)){p=!1;break}if(p)return d}return-1}l.prototype.includes=function(e,t,r){return this.indexOf(e,t,r)!==-1};l.prototype.indexOf=function(e,t,r){return ge(this,e,t,r,!0)};l.prototype.lastIndexOf=function(e,t,r){return ge(this,e,t,r,!1)};function gt(i,e,t,r){t=Number(t)||0;var n=i.length-t;r?(r=Number(r),r>n&&(r=n)):r=n;var s=e.length;if(s%2!==0)throw new TypeError("Invalid hex string");r>s/2&&(r=s/2);for(var o=0;o<r;++o){var c=parseInt(e.substr(o*2,2),16);if(isNaN(c))return o;i[t+o]=c}return o}function pt(i,e,t,r){return $(L(e,i.length-t),i,t,r)}function pe(i,e,t,r){return $(kt(e),i,t,r)}function ft(i,e,t,r){return pe(i,e,t,r)}function ht(i,e,t,r){return $(be(e),i,t,r)}function Tt(i,e,t,r){return $(Rt(e,i.length-t),i,t,r)}l.prototype.write=function(e,t,r,n){if(t===void 0)n="utf8",r=this.length,t=0;else if(r===void 0&&typeof t=="string")n=t,r=this.length,t=0;else if(isFinite(t))t=t|0,isFinite(r)?(r=r|0,n===void 0&&(n="utf8")):(n=r,r=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var s=this.length-t;if((r===void 0||r>s)&&(r=s),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return gt(this,e,t,r);case"utf8":case"utf-8":return pt(this,e,t,r);case"ascii":return pe(this,e,t,r);case"latin1":case"binary":return ft(this,e,t,r);case"base64":return ht(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Tt(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}};l.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Et(i,e,t){return e===0&&t===i.length?ae(i):ae(i.slice(e,t))}function fe(i,e,t){t=Math.min(i.length,t);for(var r=[],n=e;n<t;){var s=i[n],o=null,c=s>239?4:s>223?3:s>191?2:1;if(n+c<=t){var u,d,m,p;switch(c){case 1:s<128&&(o=s);break;case 2:u=i[n+1],(u&192)===128&&(p=(s&31)<<6|u&63,p>127&&(o=p));break;case 3:u=i[n+1],d=i[n+2],(u&192)===128&&(d&192)===128&&(p=(s&15)<<12|(u&63)<<6|d&63,p>2047&&(p<55296||p>57343)&&(o=p));break;case 4:u=i[n+1],d=i[n+2],m=i[n+3],(u&192)===128&&(d&192)===128&&(m&192)===128&&(p=(s&15)<<18|(u&63)<<12|(d&63)<<6|m&63,p>65535&&p<1114112&&(o=p))}}o===null?(o=65533,c=1):o>65535&&(o-=65536,r.push(o>>>10&1023|55296),o=56320|o&1023),r.push(o),n+=c}return bt(r)}var le=4096;function bt(i){var e=i.length;if(e<=le)return String.fromCharCode.apply(String,i);for(var t="",r=0;r<e;)t+=String.fromCharCode.apply(String,i.slice(r,r+=le));return t}function It(i,e,t){var r="";t=Math.min(i.length,t);for(var n=e;n<t;++n)r+=String.fromCharCode(i[n]&127);return r}function At(i,e,t){var r="";t=Math.min(i.length,t);for(var n=e;n<t;++n)r+=String.fromCharCode(i[n]);return r}function xt(i,e,t){var r=i.length;(!e||e<0)&&(e=0),(!t||t<0||t>r)&&(t=r);for(var n="",s=e;s<t;++s)n+=Pt(i[s]);return n}function _t(i,e,t){for(var r=i.slice(e,t),n="",s=0;s<r.length;s+=2)n+=String.fromCharCode(r[s]+r[s+1]*256);return n}l.prototype.slice=function(e,t){var r=this.length;e=~~e,t=t===void 0?r:~~t,e<0?(e+=r,e<0&&(e=0)):e>r&&(e=r),t<0?(t+=r,t<0&&(t=0)):t>r&&(t=r),t<e&&(t=e);var n;if(l.TYPED_ARRAY_SUPPORT)n=this.subarray(e,t),n.__proto__=l.prototype;else{var s=t-e;n=new l(s,void 0);for(var o=0;o<s;++o)n[o]=this[o+e]}return n};function h(i,e,t){if(i%1!==0||i<0)throw new RangeError("offset is not uint");if(i+e>t)throw new RangeError("Trying to access beyond buffer length")}l.prototype.readUIntLE=function(e,t,r){e=e|0,t=t|0,r||h(e,t,this.length);for(var n=this[e],s=1,o=0;++o<t&&(s*=256);)n+=this[e+o]*s;return n};l.prototype.readUIntBE=function(e,t,r){e=e|0,t=t|0,r||h(e,t,this.length);for(var n=this[e+--t],s=1;t>0&&(s*=256);)n+=this[e+--t]*s;return n};l.prototype.readUInt8=function(e,t){return t||h(e,1,this.length),this[e]};l.prototype.readUInt16LE=function(e,t){return t||h(e,2,this.length),this[e]|this[e+1]<<8};l.prototype.readUInt16BE=function(e,t){return t||h(e,2,this.length),this[e]<<8|this[e+1]};l.prototype.readUInt32LE=function(e,t){return t||h(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};l.prototype.readUInt32BE=function(e,t){return t||h(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};l.prototype.readIntLE=function(e,t,r){e=e|0,t=t|0,r||h(e,t,this.length);for(var n=this[e],s=1,o=0;++o<t&&(s*=256);)n+=this[e+o]*s;return s*=128,n>=s&&(n-=Math.pow(2,8*t)),n};l.prototype.readIntBE=function(e,t,r){e=e|0,t=t|0,r||h(e,t,this.length);for(var n=t,s=1,o=this[e+--n];n>0&&(s*=256);)o+=this[e+--n]*s;return s*=128,o>=s&&(o-=Math.pow(2,8*t)),o};l.prototype.readInt8=function(e,t){return t||h(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};l.prototype.readInt16LE=function(e,t){t||h(e,2,this.length);var r=this[e]|this[e+1]<<8;return r&32768?r|4294901760:r};l.prototype.readInt16BE=function(e,t){t||h(e,2,this.length);var r=this[e+1]|this[e]<<8;return r&32768?r|4294901760:r};l.prototype.readInt32LE=function(e,t){return t||h(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};l.prototype.readInt32BE=function(e,t){return t||h(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};l.prototype.readFloatLE=function(e,t){return t||h(e,4,this.length),B(this,e,!0,23,4)};l.prototype.readFloatBE=function(e,t){return t||h(e,4,this.length),B(this,e,!1,23,4)};l.prototype.readDoubleLE=function(e,t){return t||h(e,8,this.length),B(this,e,!0,52,8)};l.prototype.readDoubleBE=function(e,t){return t||h(e,8,this.length),B(this,e,!1,52,8)};function T(i,e,t,r,n,s){if(!x(i))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>n||e<s)throw new RangeError('"value" argument is out of bounds');if(t+r>i.length)throw new RangeError("Index out of range")}l.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t=t|0,r=r|0,!n){var s=Math.pow(2,8*r)-1;T(this,e,t,r,s,0)}var o=1,c=0;for(this[t]=e&255;++c<r&&(o*=256);)this[t+c]=e/o&255;return t+r};l.prototype.writeUIntBE=function(e,t,r,n){if(e=+e,t=t|0,r=r|0,!n){var s=Math.pow(2,8*r)-1;T(this,e,t,r,s,0)}var o=r-1,c=1;for(this[t+o]=e&255;--o>=0&&(c*=256);)this[t+o]=e/c&255;return t+r};l.prototype.writeUInt8=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,1,255,0),l.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=e&255,t+1};function V(i,e,t,r){e<0&&(e=65535+e+1);for(var n=0,s=Math.min(i.length-t,2);n<s;++n)i[t+n]=(e&255<<8*(r?n:1-n))>>>(r?n:1-n)*8}l.prototype.writeUInt16LE=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,2,65535,0),l.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8):V(this,e,t,!0),t+2};l.prototype.writeUInt16BE=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,2,65535,0),l.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e&255):V(this,e,t,!1),t+2};function Y(i,e,t,r){e<0&&(e=4294967295+e+1);for(var n=0,s=Math.min(i.length-t,4);n<s;++n)i[t+n]=e>>>(r?n:3-n)*8&255}l.prototype.writeUInt32LE=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,4,4294967295,0),l.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255):Y(this,e,t,!0),t+4};l.prototype.writeUInt32BE=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,4,4294967295,0),l.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255):Y(this,e,t,!1),t+4};l.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t=t|0,!n){var s=Math.pow(2,8*r-1);T(this,e,t,r,s-1,-s)}var o=0,c=1,u=0;for(this[t]=e&255;++o<r&&(c*=256);)e<0&&u===0&&this[t+o-1]!==0&&(u=1),this[t+o]=(e/c>>0)-u&255;return t+r};l.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t=t|0,!n){var s=Math.pow(2,8*r-1);T(this,e,t,r,s-1,-s)}var o=r-1,c=1,u=0;for(this[t+o]=e&255;--o>=0&&(c*=256);)e<0&&u===0&&this[t+o+1]!==0&&(u=1),this[t+o]=(e/c>>0)-u&255;return t+r};l.prototype.writeInt8=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,1,127,-128),l.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=e&255,t+1};l.prototype.writeInt16LE=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,2,32767,-32768),l.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8):V(this,e,t,!0),t+2};l.prototype.writeInt16BE=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,2,32767,-32768),l.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e&255):V(this,e,t,!1),t+2};l.prototype.writeInt32LE=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,4,2147483647,-2147483648),l.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):Y(this,e,t,!0),t+4};l.prototype.writeInt32BE=function(e,t,r){return e=+e,t=t|0,r||T(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),l.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255):Y(this,e,t,!1),t+4};function he(i,e,t,r,n,s){if(t+r>i.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Te(i,e,t,r,n){return n||he(i,e,t,4,34028234663852886e22,-34028234663852886e22),Ae(i,e,t,r,23,4),t+4}l.prototype.writeFloatLE=function(e,t,r){return Te(this,e,t,!0,r)};l.prototype.writeFloatBE=function(e,t,r){return Te(this,e,t,!1,r)};function Ee(i,e,t,r,n){return n||he(i,e,t,8,17976931348623157e292,-17976931348623157e292),Ae(i,e,t,r,52,8),t+8}l.prototype.writeDoubleLE=function(e,t,r){return Ee(this,e,t,!0,r)};l.prototype.writeDoubleBE=function(e,t,r){return Ee(this,e,t,!1,r)};l.prototype.copy=function(e,t,r,n){if(r||(r=0),!n&&n!==0&&(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var s=n-r,o;if(this===e&&r<t&&t<n)for(o=s-1;o>=0;--o)e[o+t]=this[o+r];else if(s<1e3||!l.TYPED_ARRAY_SUPPORT)for(o=0;o<s;++o)e[o+t]=this[o+r];else Uint8Array.prototype.set.call(e,this.subarray(r,r+s),t);return s};l.prototype.fill=function(e,t,r,n){if(typeof e=="string"){if(typeof t=="string"?(n=t,t=0,r=this.length):typeof r=="string"&&(n=r,r=this.length),e.length===1){var s=e.charCodeAt(0);s<256&&(e=s)}if(n!==void 0&&typeof n!="string")throw new TypeError("encoding must be a string");if(typeof n=="string"&&!l.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else typeof e=="number"&&(e=e&255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;t=t>>>0,r=r===void 0?this.length:r>>>0,e||(e=0);var o;if(typeof e=="number")for(o=t;o<r;++o)this[o]=e;else{var c=x(e)?e:L(new l(e,n).toString()),u=c.length;for(o=0;o<r-t;++o)this[o+t]=c[o%u]}return this};var yt=/[^+\/0-9A-Za-z-_]/g;function wt(i){if(i=St(i).replace(yt,""),i.length<2)return"";for(;i.length%4!==0;)i=i+"=";return i}function St(i){return i.trim?i.trim():i.replace(/^\s+|\s+$/g,"")}function Pt(i){return i<16?"0"+i.toString(16):i.toString(16)}function L(i,e){e=e||1/0;for(var t,r=i.length,n=null,s=[],o=0;o<r;++o){if(t=i.charCodeAt(o),t>55295&&t<57344){if(!n){if(t>56319){(e-=3)>-1&&s.push(239,191,189);continue}else if(o+1===r){(e-=3)>-1&&s.push(239,191,189);continue}n=t;continue}if(t<56320){(e-=3)>-1&&s.push(239,191,189),n=t;continue}t=(n-55296<<10|t-56320)+65536}else n&&(e-=3)>-1&&s.push(239,191,189);if(n=null,t<128){if((e-=1)<0)break;s.push(t)}else if(t<2048){if((e-=2)<0)break;s.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;s.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;s.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return s}function kt(i){for(var e=[],t=0;t<i.length;++t)e.push(i.charCodeAt(t)&255);return e}function Rt(i,e){for(var t,r,n,s=[],o=0;o<i.length&&!((e-=2)<0);++o)t=i.charCodeAt(o),r=t>>8,n=t%256,s.push(n),s.push(r);return s}function be(i){return st(wt(i))}function $(i,e,t,r){for(var n=0;n<r&&!(n+t>=e.length||n>=i.length);++n)e[n+t]=i[n];return n}function Mt(i){return i!==i}function Dt(i){return i!=null&&(!!i._isBuffer||Ie(i)||Wt(i))}function Ie(i){return!!i.constructor&&typeof i.constructor.isBuffer=="function"&&i.constructor.isBuffer(i)}function Wt(i){return typeof i.readFloatLE=="function"&&typeof i.slice=="function"&&Ie(i.slice(0,0))}function B(i,e,t,r,n){var s,o,c=n*8-r-1,u=(1<<c)-1,d=u>>1,m=-7,p=t?n-1:0,I=t?-1:1,E=i[e+p];for(p+=I,s=E&(1<<-m)-1,E>>=-m,m+=c;m>0;s=s*256+i[e+p],p+=I,m-=8);for(o=s&(1<<-m)-1,s>>=-m,m+=r;m>0;o=o*256+i[e+p],p+=I,m-=8);if(s===0)s=1-d;else{if(s===u)return o?NaN:(E?-1:1)*(1/0);o=o+Math.pow(2,r),s=s-d}return(E?-1:1)*o*Math.pow(2,s-r)}function Ae(i,e,t,r,n,s){var o,c,u,d=s*8-n-1,m=(1<<d)-1,p=m>>1,I=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,E=r?0:s-1,D=r?1:-1,Me=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,o=m):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),o+p>=1?e+=I/u:e+=I*Math.pow(2,1-p),e*u>=2&&(o++,u/=2),o+p>=m?(c=0,o=m):o+p>=1?(c=(e*u-1)*Math.pow(2,n),o=o+p):(c=e*Math.pow(2,p-1)*Math.pow(2,n),o=0));n>=8;i[t+E]=c&255,E+=D,c/=256,n-=8);for(o=o<<n|c,d+=n;d>0;i[t+E]=o&255,E+=D,o/=256,d-=8);i[t+E-D]|=Me*128}import{io as nr}from"socket.io-client";import sr from"axios";import{DEFAULT_ORDER_EXPIRATION_DAYS as ar,ORDER_MSG_VERSION as or}from"@ultrade/shared/browser/constants";import{getRandomInt as H}from"@ultrade/shared/browser/common";import{getCancelOrderDataJsonBytes as lr,makeLoginMsg as cr,makeTradingKeyMsg as ke,makeCreateOrderMsg as ur}from"@ultrade/shared/browser/helpers/codex.helper";import{makeWithdrawMsg as dr}from"@ultrade/shared/browser/helpers/withdraw.helper";import{TradingKeyType as mr}from"@ultrade/shared/browser/interfaces";import{PROVIDERS as M}from"@ultrade/shared/browser/interfaces";import{OrderStatus as G}from"@ultrade/shared/browser/enums";import{makeDtwMsg as gr,makeTransferMsg as pr}from"@ultrade/shared/browser/helpers/codex";var U=class{constructor(e,t,r,n){this.onDisconnect=r;this.onConnectError=n;this.socket=null;this.socketPool={};this.streamCounters=new Map;this.callbacks=new Map;this.onAnyRegistered=!1;this.handlerIdCounter=0;this.websocketUrl=e,this.socketIOFactory=t,this.initializeSocket()}initializeSocket(){this.socket===null&&(this.socket=this.socketIOFactory(this.websocketUrl,{reconnection:!0,reconnectionDelay:1e3,reconnectionAttempts:9999,transports:["websocket"]}),this.onDisconnect&&this.socket.on("disconnect",()=>{this.onDisconnect(this.socket.id)}),this.onConnectError&&this.socket.on("connect_error",e=>{this.onConnectError(e)}),this.setupReconnectHandler())}getSocket(){return this.socket}subscribe(e,t){let r=Date.now()+ ++this.handlerIdCounter;this.socket===null&&this.initializeSocket(),this.callbacks.set(r,t),this.onAnyRegistered||(this.socket.onAny((s,...o)=>{this.callbacks.forEach(c=>{c(s,o)})}),this.onAnyRegistered=!0),e.streams.forEach(s=>{let o=String(s);if(!this.streamCounters.has(o)){this.streamCounters.set(o,1),console.log(`[SocketManager] Stream counter created: stream=${o}, count=1`);return}let c=this.streamCounters.get(o);this.streamCounters.set(o,c+1),console.log(`[SocketManager] Stream counter increased: stream=${o}, count=${c+1}`)});let n=()=>{this.socket&&(this.socket.emit("subscribe",e),console.log(`[SocketManager] SUBSCRIBE: handlerId=${r}, options=`,e,`connected=${this.socket.connected}, streamCounters=`,Object.fromEntries(this.streamCounters)))};return n(),this.socket.connected||(this.socket.once("connect",n),console.log(`[SocketManager] SUBSCRIBE (also waiting for connect): handlerId=${r}, options=`,e)),this.socketPool[r]=e,r}setupReconnectHandler(){this.socket&&(this.socket.io.off("reconnect"),this.socket.io.on("reconnect",()=>{Object.entries(this.socketPool).forEach(([e,t])=>{this.socket?.emit("subscribe",t),console.log(`[SocketManager] RECONNECT re-subscribe: handlerId=${e}, options=`,t)})}))}unsubscribe(e){this.callbacks.delete(e);let t=this.socketPool[e];if(!t){console.log(`[SocketManager] UNSUBSCRIBE: handlerId=${e} not found in socketPool`);return}let r=[];if(t.streams.forEach(n=>{let s=String(n);if(!this.streamCounters.has(s)){console.log(`[SocketManager] Stream counter not found: stream=${s}, skipping unsubscribe (no subscription was made)`);return}let o=this.streamCounters.get(s);if(o===1)this.streamCounters.set(s,0),r.push(n),console.log(`[SocketManager] Stream counter <= 1, will unsubscribe: stream=${s}, count=${o}`);else if(o>1){let c=o-1;this.streamCounters.set(s,c),console.log(`[SocketManager] Stream counter decreased (no unsubscribe): stream=${s}, count=${c}`)}}),r.length>0&&this.socket){let n={...t,streams:r};this.socket.emit("unsubscribe",n),console.log(`[SocketManager] UNSUBSCRIBE: handlerId=${e}, unsubscribeSentForStreams=[${r.join(", ")}], streamCounters=`,Object.fromEntries(this.streamCounters),`remainingSubscriptions=${Object.keys(this.socketPool).length}`)}else console.log(`[SocketManager] UNSUBSCRIBE: handlerId=${e}, no streams to unsubscribe (all counters > 1), streamCounters=`,Object.fromEntries(this.streamCounters),`remainingSubscriptions=${Object.keys(this.socketPool).length}`);delete this.socketPool[e],Object.keys(this.socketPool).length===0&&this.socket&&(console.log("[SocketManager] UNSUBSCRIBE: No more subscriptions, disconnecting socket"),this.disconnect())}disconnect(){this.socket&&(this.socket.disconnect(),this.socket=null),this.streamCounters.clear(),this.callbacks.clear(),this.onAnyRegistered=!1,console.log("[SocketManager] DISCONNECT: All stream counters and callbacks cleared")}isConnected(){return this.socket!==null&&this.socket.connected}on(e,t){this.socket&&this.socket.on(e,t)}off(e,t){this.socket&&(t?this.socket.off(e,t):this.socket.off(e))}emit(e,...t){this.socket&&this.socket.emit(e,...t)}emitCurrentPair(e){this.emit("currentPair",e)}emitOrderFilter(e){this.emit("orderFilter",e)}onReconnect(e){return this.socket?(this.socket.io.off("reconnect"),this.socket.io.on("reconnect",e),()=>{this.socket&&this.socket.io.off("reconnect",e)}):()=>{}}offReconnect(e){this.socket&&(e?this.socket.io.off("reconnect",e):this.socket.io.off("reconnect"))}};import Nt from"react-secure-storage";var Ut=new URL(window.location!==window.parent.location?document.referrer:document.location.href).host,xe=i=>`${i}_${Ut}`,vt=new Proxy(Nt,{get(i,e,t){return typeof e=="string"&&typeof i[e]=="function"?function(...r){return typeof e=="string"&&["setItem","getItem","removeItem"].includes(e)&&(r[0]=xe(r[0])),i[e].apply(i,r)}:Reflect.get(i,e,t)}}),J=new Proxy(localStorage,{get(i,e,t){return typeof e=="string"&&typeof i[e]=="function"?function(...r){return typeof e=="string"&&["setItem","getItem","removeItem","key"].includes(e)&&(r[0]=xe(r[0])),i[e].apply(i,r)}:Reflect.get(i,e,t)}}),X=class{constructor(){this.keys={mainWallet:"main-wallet",tradingKey:"trading-key"};this.isBrowser=typeof window<"u",this.isBrowser||(this.clearMainWallet=()=>{},this.getMainWallet=()=>null,this.setMainWallet=()=>{})}setMainWallet(e){J.setItem(this.keys.mainWallet,JSON.stringify(e))}getMainWallet(){let e=J.getItem(this.keys.mainWallet);if(!e)return null;let t=JSON.parse(e),r=vt.getItem(`${this.keys.tradingKey}-${t.address}`);return r&&(r.expiredAt===0||Number(new Date(r.expiredAt))-Date.now()>1)&&(t.tradingKey=r.address),t}clearMainWallet(){J.removeItem(this.keys.mainWallet)}};var Ft=(t=>(t.YES="Y",t.NO="N",t))(Ft||{}),Gt=(d=>(d.MFT_AUDIO_LINK="mft.audioLink",d.MFT_TITLE="mft.title",d.VIEW_BASE_COIN_ICON_LINK="view.baseCoinIconLink",d.VIEW_BASE_COIN_MARKET_LINK="view.baseCoinMarketLink",d.VIEW_PRICE_COIN_ICON_LINK="view.priceCoinIconLink",d.VIEW_PRICE_COIN_MARKET_LINK="view.priceCoinMarketLink",d.MAKER_FEE="makerFee",d.TAKER_FEE="takerFee",d.MODE_PRE_SALE="mode.preSale",d))(Gt||{});var Ot=(n=>(n[n.OPEN_ORDER=1]="OPEN_ORDER",n[n.CANCELLED=2]="CANCELLED",n[n.MATCHED=3]="MATCHED",n[n.SELF_MATCHED=4]="SELF_MATCHED",n))(Ot||{}),Ct=(t=>(t.open="open",t.close="close",t))(Ct||{}),Lt=(s=>(s[s.Open=1]="Open",s[s.Canceled=2]="Canceled",s[s.Completed=3]="Completed",s[s.SelfMatch=4]="SelfMatch",s[s.Expired=5]="Expired",s))(Lt||{}),Vt=(t=>(t[t.open=1]="open",t[t.close=2]="close",t))(Vt||{}),Yt=(n=>(n[n.Limit=0]="Limit",n[n.IOC=1]="IOC",n[n.POST=2]="POST",n[n.Market=3]="Market",n))(Yt||{}),$t=(r=>(r[r.created=1]="created",r[r.partially_filled=2]="partially_filled",r[r.removed=3]="removed",r))($t||{}),Bt=(a=>(a.ALGORAND="Algorand",a.SOLANA="Solana",a["5IRECHAIN_THUNDER_TESTNET"]="5ireChain Thunder Testnet",a.ACALA="Acala",a.ALFAJORES="Alfajores",a.APOTHEM_NETWORK="Apothem Network",a.ARBITRUM_GOERLI="Arbitrum Goerli",a.ARBITRUM_NOVA="Arbitrum Nova",a.ARBITRUM_ONE="Arbitrum",a.ARBITRUM_SEPOLIA="Arbitrum Sepolia",a.ASTAR="Astar",a.ASTAR_ZKEVM_TESTNET_ZKATANA="Astar zkEVM Testnet zKatana",a.AURORA="Aurora",a.AURORA_TESTNET="Aurora Testnet",a.AVALANCHE="Avalanche",a.AVALANCHE_FUJI="Avalanche Fuji",a.BAHAMUT="Bahamut",a.BASE="Base",a.BASE_GOERLI="Base Goerli",a.BASE_SEPOLIA="Base Sepolia",a.BEAR_NETWORK_CHAIN_MAINNET="Bear Network Chain Mainnet",a.BEAR_NETWORK_CHAIN_TESTNET="Bear Network Chain Testnet",a.BERACHAIN_ARTIO="Berachain Artio",a.BERESHEET_BEREEVM_TESTNET="Beresheet BereEVM Testnet",a.BINANCE_SMART_CHAIN_TESTNET="BNB Chain Testnet",a.BITTORRENT="BitTorrent",a.BITTORRENT_CHAIN_TESTNET="BitTorrent Chain Testnet",a.BLACKFORT_EXCHANGE_NETWORK="BlackFort Exchange Network",a.BLACKFORT_EXCHANGE_NETWORK_TESTNET="BlackFort Exchange Network Testnet",a.BLAST_SEPOLIA="Blast Sepolia",a.BNB_SMART_CHAIN="BNB Chain",a.BOBA_NETWORK="Boba Network",a.BRONOS="Bronos",a.BRONOS_TESTNET="Bronos Testnet",a.CANTO="Canto",a.CELO="Celo",a.CHILIZ_CHAIN="Chiliz Chain",a.CHILIZ_SPICY_TESTNET="Chiliz Spicy Testnet",a.CONFLUX_ESPACE="Conflux eSpace",a.CONFLUX_ESPACE_TESTNET="Conflux eSpace Testnet",a.CORE_DAO="Core Dao",a.COSTON="Coston",a.COSTON2="Coston2",a.CRONOS_MAINNET="Cronos Mainnet",a.CRONOS_TESTNET="Cronos Testnet",a.CROSSBELL="Crossbell",a.DEFICHAIN_EVM_MAINNET="DeFiChain EVM Mainnet",a.DEFICHAIN_EVM_TESTNET="DeFiChain EVM Testnet",a.DFK_CHAIN="DFK Chain",a.DOGECHAIN="Dogechain",a.EDGEWARE_EDGEEVM_MAINNET="Edgeware EdgeEVM Mainnet",a.EKTA="Ekta",a.EKTA_TESTNET="Ekta Testnet",a.EOS_EVM="EOS EVM",a.EOS_EVM_TESTNET="EOS EVM Testnet",a.ETHEREUM="Ethereum",a.ETHEREUM_CLASSIC="Ethereum Classic",a.EVMOS="Evmos",a.EVMOS_TESTNET="Evmos Testnet",a.FANTOM="Fantom",a.FANTOM_SONIC_OPEN_TESTNET="Fantom Sonic Open Testnet",a.FANTOM_TESTNET="Fantom Testnet",a.FIBO_CHAIN="Fibo Chain",a.FILECOIN_CALIBRATION="Filecoin Calibration",a.FILECOIN_HYPERSPACE="Filecoin Hyperspace",a.FILECOIN_MAINNET="Filecoin Mainnet",a.FLARE_MAINNET="Flare Mainnet",a.FOUNDRY="Foundry",a.FUSE="Fuse",a.FUSE_SPARKNET="Fuse Sparknet",a.GNOSIS="Gnosis",a.GNOSIS_CHIADO="Gnosis Chiado",a.GOERLI="Goerli",a.HAQQ_MAINNET="HAQQ Mainnet",a.HAQQ_TESTEDGE_2="HAQQ Testedge 2",a.HARDHAT="Hardhat",a.HARMONY_ONE="Harmony One",a.HEDERA_MAINNET="Hedera Mainnet",a.HEDERA_PREVIEWNET="Hedera Previewnet",a.HEDERA_TESTNET="Hedera Testnet",a.HOLESKY="Holesky",a.HORIZEN_GOBI_TESTNET="Horizen Gobi Testnet",a.IOTEX="IoTeX",a.IOTEX_TESTNET="IoTeX Testnet",a.JIBCHAIN_L1="JIBCHAIN L1",a.KARURA="Karura",a.KAVA_EVM="Kava EVM",a.KAVA_EVM_TESTNET="Kava EVM Testnet",a.KCC_MAINNET="KCC Mainnet",a.KLAYTN="Klaytn",a.KLAYTN_BAOBAB_TESTNET="Klaytn Baobab Testnet",a.KROMA="Kroma",a.KROMA_SEPOLIA="Kroma Sepolia",a.LIGHTLINK_PEGASUS_TESTNET="LightLink Pegasus Testnet",a.LIGHTLINK_PHOENIX="LightLink Phoenix",a.LINEA_GOERLI_TESTNET="Linea Goerli Testnet",a.LINEA_MAINNET="Linea Mainnet",a.LOCALHOST="Localhost",a.LUKSO="LUKSO",a.MANDALA_TC9="Mandala TC9",a.MANTA_PACIFIC_MAINNET="Manta Pacific Mainnet",a.MANTA_PACIFIC_TESTNET="Manta Pacific Testnet",a.MANTLE="Mantle",a.MANTLE_TESTNET="Mantle Testnet",a.METACHAIN_MAINNET="MetaChain Mainnet",a.METER="Meter",a.METER_TESTNET="Meter Testnet",a.METIS="Metis",a.METIS_GOERLI="Metis Goerli",a.MEVERSE_CHAIN_MAINNET="MEVerse Chain Mainnet",a.MEVERSE_CHAIN_TESTNET="MEVerse Chain Testnet",a.MODE_TESTNET="Mode Testnet",a.MOONBASE_ALPHA="Moonbase Alpha",a.MOONBEAM="Moonbeam",a.MOONBEAM_DEVELOPMENT_NODE="Moonbeam Development Node",a.MOONRIVER="Moonriver",a.NEON_EVM_DEVNET="Neon EVM DevNet",a.NEON_EVM_MAINNET="Neon EVM MainNet",a.NEXI="Nexi",a.NEXILIX_SMART_CHAIN="Nexilix Smart Chain",a.OASIS_SAPPHIRE="Oasis Sapphire",a.OASIS_SAPPHIRE_TESTNET="Oasis Sapphire Testnet",a.OASIS_TESTNET="Oasis Testnet",a.OASYS="Oasys",a.OKC="OKC",a.OORT_MAINNETDEV="OORT MainnetDev",a.OPBNB="opBNB",a.OPBNB_TESTNET="opBNB Testnet",a.OPTIMISM_GOERLI="Optimism Goerli",a.OP_MAINNET="Optimism",a.OP_SEPOLIA="Optimism Sepolia",a.PALM="Palm",a.PALM_TESTNET="Palm Testnet",a.PGN="PGN",a.PGN_="PGN ",a.PLINGA="Plinga",a.POLYGON="Polygon",a.POLYGON_AMOY="Polygon Amoy",a.POLYGON_MUMBAI="Polygon Mumbai",a.POLYGON_ZKEVM="Polygon zkEVM",a.POLYGON_ZKEVM_TESTNET="Polygon zkEVM Testnet",a.PULSECHAIN="PulseChain",a.PULSECHAIN_V4="PulseChain V4",a.Q_MAINNET="Q Mainnet",a.Q_TESTNET="Q Testnet",a.ROLLUX_MAINNET="Rollux Mainnet",a.ROLLUX_TESTNET="Rollux Testnet",a.RONIN="Ronin",a.ROOTSTOCK_MAINNET="Rootstock Mainnet",a.SAIGON_TESTNET="Saigon Testnet",a.SCROLL="Scroll",a.SCROLL_SEPOLIA="Scroll Sepolia",a.SCROLL_TESTNET="Scroll Testnet",a.SEPOLIA="Ethereum Sepolia",a.SHARDEUM_SPHINX="Shardeum Sphinx",a.SHIBARIUM="Shibarium",a.SHIMMER="Shimmer",a.SHIMMER_TESTNET="Shimmer Testnet",a["SKALE_|_BLOCK_BRAWLERS"]="SKALE | Block Brawlers",a["SKALE_|_CALYPSO_NFT_HUB"]="SKALE | Calypso NFT Hub",a["SKALE_|_CALYPSO_NFT_HUB_TESTNET"]="SKALE | Calypso NFT Hub Testnet",a["SKALE_|_CHAOS_TESTNET"]="SKALE | Chaos Testnet",a["SKALE_|_CRYPTOBLADES"]="SKALE | CryptoBlades",a["SKALE_|_CRYPTO_COLOSSEUM"]="SKALE | Crypto Colosseum",a["SKALE_|_EUROPA_LIQUIDITY_HUB"]="SKALE | Europa Liquidity Hub",a["SKALE_|_EUROPA_LIQUIDITY_HUB_TESTNET"]="SKALE | Europa Liquidity Hub Testnet",a["SKALE_|_EXORDE"]="SKALE | Exorde",a["SKALE_|_HUMAN_PROTOCOL"]="SKALE | Human Protocol",a["SKALE_|_NEBULA_GAMING_HUB"]="SKALE | Nebula Gaming Hub",a["SKALE_|_NEBULA_GAMING_HUB_TESTNET"]="SKALE | Nebula Gaming Hub Testnet",a["SKALE_|_RAZOR_NETWORK"]="SKALE | Razor Network",a["SKALE_|_TITAN_COMMUNITY_HUB"]="SKALE | Titan Community Hub",a["SKALE_|_TITAN_COMMUNITY_HUB_TESTNET"]="SKALE | Titan Community Hub Testnet",a.SONGBIRD_MAINNET="Songbird Mainnet",a.SYSCOIN_MAINNET="Syscoin Mainnet",a.SYSCOIN_TANENBAUM_TESTNET="Syscoin Tanenbaum Testnet",a["TAIKO_(ALPHA-3_TESTNET)"]="Taiko (Alpha-3 Testnet)",a["TAIKO_JOLNIR_(ALPHA-5_TESTNET)"]="Taiko Jolnir (Alpha-5 Testnet)",a["TAIKO_KATLA_(ALPHA-6_TESTNET)"]="Taiko Katla (Alpha-6 Testnet)",a.TARAXA_MAINNET="Taraxa Mainnet",a.TARAXA_TESTNET="Taraxa Testnet",a.TELOS="Telos",a.TENET="Tenet",a.VECHAIN="Vechain",a.WANCHAIN="Wanchain",a.WANCHAIN_TESTNET="Wanchain Testnet",a.WEMIX="WEMIX",a.WEMIX_TESTNET="WEMIX Testnet",a.X1_TESTNET="X1 Testnet",a.XINFIN_NETWORK="XinFin Network",a.ZETACHAIN_ATHENS_TESTNET="ZetaChain Athens Testnet",a.ZHEJIANG="Zhejiang",a.ZILLIQA="Zilliqa",a.ZILLIQA_TESTNET="Zilliqa Testnet",a.ZKFAIR_MAINNET="ZKFair Mainnet",a.ZKFAIR_TESTNET="ZKFair Testnet",a.ZKSYNC_ERA="zkSync Era",a.ZKSYNC_ERA_TESTNET="zkSync Era Testnet",a.ZKSYNC_SEPOLIA_TESTNET="zkSync Sepolia Testnet",a.ZORA="Zora",a.ZORA_GOERLI_TESTNET="Zora Goerli Testnet",a.ZORA_SEPOLIA="Zora Sepolia",a))(Bt||{}),Xt=(m=>(m.Pending="pending",m.Completed="completed",m.Failed="failed",m.Received="received",m.Success="success",m.Failure="failure",m.Dropped="dropped",m.Replaced="replaced",m.Stuck="stuck",m.Confirmed="confirmed",m))(Xt||{}),qt=(s=>(s.USER_TO_TMC="user_to_tmc",s.TMC_TO_USER="tmc_to_user",s.RELAYER_TO_TMC="relayer_to_tmc",s.RELAYER_TO_CODEX="relayer_to_codex",s.RELAYER_TO_CIRCLE="relayer_to_circle",s))(qt||{}),Zt=(n=>(n.D="deposit",n.W="withdraw",n.F="fast_deposit",n.T="transfer",n))(Zt||{});var zt=(n=>(n.COMPANY="COMPANY",n.TWITTER="TWITTER",n.DISCORD="DISCORD",n.TELEGRAM="TELEGRAM",n))(zt||{});import{STREAMS as _e,PRIVATE_STREAMS as j}from"@ultrade/shared/browser/enums";var Qt=(r=>(r.OFF="disable",r.ULTRADE="ultrade",r.ALL="all",r))(Qt||{}),Jt=(f=>(f.ENABLED="company.enabled",f.APP_TITLE="company.appTitle",f.DOMAIN="company.domain",f.DIRECT_SETTLE="company.directSettlement",f.KYC="markets.kycTradeRequirementEnabled",f.GEOBLOCK="company.geoblock",f.LOGO="appearance.logo",f.THEMES="appearance.themes",f.NEW_TAB="appearance.newTab",f.TARGET="appearance.target",f.REPORT_BUTTONS="appearance.reportButtons",f.CUSTOM_MENU_ITEMS="appearance.customMenuItems",f.APPEARANCE_CHART_TYPE="appearance.chartType",f.APPEARANCE_CHART_INT="appearance.chartInt",f.AMM="product.amm",f.OBDEX="product.obdex",f.POINTS="product.pointSystem",f.AFFILIATE_DASHBOARD_THRESHOLD="product.affiliateDashboardThreshold",f.AFFILIATE_DEFAULT_FEE_SHARE="product.affiliateDefaultFeeShare",f.AFFILIATE_DASHBOARD_VISIBILITY="product.affiliateDashboardVisibility",f.AMM_FEE="company.ammFee",f.FEE_SHARE="company.feeShare",f.MIN_FEE="company.minFee",f.MAKER_FEE="company.makerFee",f.TAKER_FEE="company.takerFee",f.PINNED_PAIRS="markets.pinnedPairs",f.TWITTER_ENABLED="point-system.twitterEnabled",f.TWITTER_JOB_ENABLED="point-system.twitterJobEnabled",f.TWITTER_HASHTAGS="point-system.twitterHashtags",f.TWITTER_ACCOUNT_NAME="point-system.twitterAccountName",f.DISCORD_ENABLED="point-system.discordEnabled",f.TELEGRAM_ENABLED="point-system.telegramEnabled",f.TELEGRAM_GROUP_NAME="point-system.telegramGroupName",f.TELEGRAM_BOT_NAME="point-system.telegramBotName",f.GUIDE_LINK="point-system.guideLink",f))(Jt||{});var jt=(r=>(r.DISABLED="disabled",r.ENABLED_FOR_ALL="enabled for all",r.ENABLED_FOR_AFFILIATES="enabled for affiliates",r))(jt||{});import{decodeStateArray as Kt,getTxnParams as Ht}from"@ultrade/shared/browser/helpers/algo.helper";import v from"algosdk";import er from"axios";var F=class{constructor(e,t,r){this.client=e,this.authCredentials=t,this.indexerDomain=r}isAppOptedIn(e,t){return!!e?.find(r=>r.id===t)}isAssetOptedIn(e,t){return Object.keys(e).includes(t.toString())}async optInAsset(e,t){let r=await this.getTxnParams();return v.makeAssetTransferTxnWithSuggestedParamsFromObject({suggestedParams:{...r},from:e,to:e,assetIndex:t,amount:0})}async makeAppCallTransaction(e,t,r,n,s){let o=[],c=[],u=[e];return v.makeApplicationNoOpTxn(t,s||await this.getTxnParams(),r,n,o,c,u)}makeTransferTransaction(e,t,r,n,s){if(r<=0)return null;let o={suggestedParams:{...e},from:n,to:s,amount:r};return t===0?v.makePaymentTxnWithSuggestedParamsFromObject(o):(o.assetIndex=t,v.makeAssetTransferTxnWithSuggestedParamsFromObject(o))}get signer(){return this.authCredentials.signer}set signer(e){this.authCredentials.signer=e}async signAndSend(e){Array.isArray(e)||(e=[e]);let t=this.getCurrentAccount();if(t){let r=e.map(n=>n.signTxn(t.sk));return this.client.sendRawTransaction(r).do()}return this.authCredentials.signer.signAndSend(e)}async signAndSendData(e,t,r,n){let s=typeof e=="string"?e:JSON.stringify(e),o=typeof e=="string"?{message:s}:{...e},c=await t(s,n);return r({...o,signature:c})}async getTxnParams(){return await Ht(this.client)}getCurrentAccount(){return this.authCredentials.mnemonic?v.mnemonicToSecretKey(this.authCredentials.mnemonic):null}async getAccountInfo(e){return this.client.accountInformation(e).do()}constructArgsForAppCall(...e){let t=[];return e.forEach(r=>{t.push(new Uint8Array(r.toBuffer?r.toBuffer():l.from(r.toString())))}),t}validateCredentials(){if(!this.authCredentials.mnemonic&&!this.authCredentials.signer)throw"You need specify mnemonic or signer to execute the method"}async getAppState(e){try{let t=await this.client.getApplicationByID(e).do();return Kt(t.params["global-state"])}catch(t){console.log(`Attempt to load app by id ${e}`),console.log(t.message)}}async getSuperAppId(e){return(await this.getAppState(e))?.UL_SUPERADMIN_APP||0}async getPairBalances(e,t){let{data:r}=await er.get(`${this.indexerDomain}/v2/accounts/${t}?include-all=true`);if(r.account.hasOwnProperty("apps-local-state")){let n=r.account["apps-local-state"].find(c=>c.id===e&&c.deleted===!1);if(!n)return null;let s=n["key-value"].find(c=>c.key==="YWNjb3VudEluZm8="),o=l.from(s.value.bytes,"base64");return ye(o)}}async calculateTransferAmount(e,t,r,n,s,o){let c=await this.getPairBalances(e,t),u=(r==="B"?c?.priceCoin_available:c?.baseCoin_available)??0;r==="B"&&(n=n/10**o*s);let d=Math.ceil(n-u);return d<0?0:d}};import we,{encodeAddress as tr}from"algosdk";var rr={priceCoin_locked:{type:"uint"},priceCoin_available:{type:"uint"},baseCoin_locked:{type:"uint"},baseCoin_available:{type:"uint"},companyId:{type:"uint"},WLFeeShare:{type:"uint"},WLCustomFee:{type:"uint"},slotMap:{type:"uint"}},ye=i=>{let e=new Map,t=0;for(let[r,n]of Object.entries(rr)){if(t>=i.length)throw new Error("Array index out of bounds");let s;switch(n.type){case"address":s=tr(i.slice(t,t+32)),t+=32;break;case"bytes":s=i.slice(t,t+n.size),s=we.decodeUint64(s,"mixed"),t+=n.size;break;case"uint":s=we.decodeUint64(i.slice(t,t+8),"mixed"),t+=8;break;case"string":s=ir(i.slice(t,t+n.size)),t+=n.size;break}e.set(r,s)}return Object.fromEntries(e)},ir=i=>l.from(i).toString("utf-8");var Se="By signing this message you are logging into your trading account and agreeing to all terms and conditions of the platform.";var Pe={mainnet:{algodNode:"https://mainnet-api.algonode.cloud",apiUrl:"https://mainnet-api.algonode.cloud",algodIndexer:"https://mainnet-idx.algonode.cloud"},testnet:{algodNode:"https://testnet-api.algonode.cloud",apiUrl:"https://testnet-apigw.ultradedev.net",algodIndexer:"https://testnet-idx.algonode.cloud"},local:{algodNode:"http://localhost:4001",apiUrl:"http://localhost:5001",algodIndexer:"http://localhost:8980"}},K=["/market/balances","/market/order","/market/orders","/market/account/kyc/status","/market/account/kyc/init","/market/withdrawal-fee","/market/operation-details","/wallet/key","/wallet/transactions","/wallet/transfer","/wallet/withdraw","/wallet/whitelist","/wallet/withdrawal-wallets"];var Re=class{constructor(e,t){this.axiosInterceptor=e=>{let t=c=>c.withWalletCredentials||(c.url?K.some(u=>c.url.includes(u)):!1),r=c=>{let u=["/market/order"];return c.withWalletCredentials||(c.url?u.some(d=>c.url.includes(d)):!1)},n=c=>{let u=["/wallet/signin","/market/account/kyc/init","/notifications"];return c.url?u.some(d=>c.url.includes(d)):!1},s=c=>{let u=["/social/"];return c.url?u.some(d=>c.url.includes(d)):!1},o=c=>c.url?K.some(u=>c.url.includes(u)):!1;return e.interceptors.request.use(c=>{if(this.wallet&&t(c)&&(c.headers["X-Wallet-Address"]=this.wallet.address,c.headers["X-Wallet-Token"]=this.wallet.token),this.wallet&&o(c)&&(c.headers.CompanyId=this.companyId),this.wallet&&r(c)){let u=this.localStorageService.getMainWallet()?.tradingKey;u&&(c.headers["X-Trading-Key"]=u)}return n(c)&&(c.headers.CompanyId=this.companyId),s(c)&&!c.headers.CompanyId&&(c.headers.CompanyId=this.isUltradeID?1:this.companyId),c},c=>Promise.reject(c)),e.interceptors.response.use(c=>c.data,async c=>(console.log("Request was failed",c),[401].includes(c?.response?.status)&&c.config&&t(c.config)&&(this.wallet=null,this.localStorageService.clearMainWallet()),Promise.reject(c))),e};let r=Pe[e.network];this.algodNode=r.algodNode,this.apiUrl=r.apiUrl,this.algodIndexer=r.algodIndexer,e.apiUrl!==void 0&&(this.apiUrl=e.apiUrl),e.companyId!==void 0&&(this.companyId=e.companyId),this.websocketUrl=e.websocketUrl,this.client=new F(e.algoSdkClient,t||{},this.algodIndexer),this._axios=this.axiosInterceptor(sr.create({baseURL:this.apiUrl})),this.localStorageService=new X,this.wallet=this.localStorageService.getMainWallet(),this.isUltradeID=!1,this.socketManager=new U(this.websocketUrl,nr,n=>{console.log(`Socket ${n} disconnected at`,new Date)},n=>{console.log(`Socket connect_error due to ${n}`)}),console.log("SDK Wallet",this.wallet)}get useUltradeID(){return this.isUltradeID}set useUltradeID(e){this.isUltradeID=e}get isLogged(){return!!this.wallet?.token}get mainWallet(){return this.wallet}set mainWallet(e){this.wallet=e,e?this.localStorageService.setMainWallet(e):this.localStorageService.clearMainWallet()}setSigner(e){this.client.signer=e}subscribe(e,t){let r=e.streams.some(n=>n===_e.TRADES&&e.options?.address?!0:j.includes(n));return r&&!this.mainWallet?.token&&!this.mainWallet?.tradingKey?(e.streams=e.streams.filter(n=>!j.includes(n)),this.socketManager.subscribe(e,t)):r?(e.options={...e.options,token:this.mainWallet?.token,tradingKey:this.mainWallet?.tradingKey},this.socketManager.subscribe(e,t)):this.socketManager.subscribe(e,t)}unsubscribe(e){this.socketManager.unsubscribe(e)}getPairList(e){let t=e?`&companyId=${e}`:"";return this._axios.get(`/market/markets?includeAllOrders=false${t}`)}getPair(e){return this._axios.get(`/market/market?symbol=${e}`)}getPrice(e){return this._axios.get(`/market/price?symbol=${e}`)}getDepth(e,t){return this._axios.get(`/market/depth?symbol=${e}&depth=${t}`)}getSymbols(e){return this._axios.get(`/market/symbols${e?"?mask="+e:""}`)}getLastTrades(e){return this._axios.get(`/market/last-trades?symbol=${e}`)}getHistory(e,t,r,n,s=500,o=1){return this._axios.get(`/market/history?symbol=${e}&interval=${t}&startTime=${r??""}&endTime=${n??""}&limit=${s}&page=${o}`)}getOrders(e,t,r=50,n,s){let o=t?t===1?G.Open:[G.Canceled,G.Matched,G.SelfMatched,G.Expired].join(","):"",c=e?`&symbol=${e}`:"",u=o?`&status=${o}`:"",d=s?`&startTime=${s}`:"",m=n?`&endTime=${n}`:"";return this._axios.get(`/market/orders?limit=${r}${c}${u}${d}${m}`)}getOrderById(e){return this._axios.get(`/market/order/${e}`)}getSettings(){let e=new URL(window.location!==window.parent.location?document.referrer:document.location.href).host;return this._axios.get("/market/settings",{headers:{"wl-domain":e}})}getBalances(){return this._axios.get("/market/balances")}getChains(){return this._axios.get("/market/chains")}getCodexAssets(){return this._axios.get("/market/assets")}getCCTPAssets(){return this._axios.get("/market/cctp-assets")}getCCTPUnifiedAssets(){return this._axios.get("/market/cctp-unified-assets")}getWithdrawalFee(e,t){return this._axios.get(`/market/withdrawal-fee?assetAddress=${e}&chainId=${t}`)}getKycStatus(){return this._axios.get("/market/account/kyc/status")}getKycInitLink(e){return this._axios.post("/market/account/kyc/init",{embeddedAppUrl:e})}getDollarValues(e=[]){return this._axios.get(`/market/dollar-price?assetIds=${JSON.stringify(e)}`)}getTransactionDetalis(e){return this._axios.get(`/market/operation-details?operationId=${e}`)}getWalletTransactions(e,t,r=100){return this._axios.get(`/wallet/transactions?type=${e}&limit=${r}&page=${t}`,{withWalletCredentials:!0})}getTradingKeys(){return this._axios.get("/wallet/keys",{withWalletCredentials:!0})}getTransfers(e,t=100){return this._axios.get(`/wallet/transfers?limit=${t}&page=${e}`,{withWalletCredentials:!0})}getPendingTransactions(){return this._axios.get("/wallet/transactions/pending",{withWalletCredentials:!0})}getWhitelist(){return this._axios.get("/wallet/whitelist",{withWalletCredentials:!0})}async addWhitelist(e){e={...e,expiredDate:e.expiredDate&&Math.round(e.expiredDate/1e3)};let r=l.from(gr(e)).toString("hex");return await this.client.signAndSendData(r,this.client.signer.signMessage,({signature:n})=>this._axios.post("/wallet/whitelist",{message:r,signature:n}),"hex")}deleteWhitelist(e){let t={whitelistId:e};return this.client.signAndSendData(t,this.client.signer.signMessage,({signature:r})=>this._axios.delete("/wallet/whitelist",{data:{data:t,signature:r}}))}getAllWithdrawalWallets(){return this._axios.get("/wallet/withdrawal-wallets")}getWithdrawalWalletByAdd