@orderly.network/core 0.0.78 → 0.0.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- var pn=Object.create;var Ne=Object.defineProperty;var yn=Object.getOwnPropertyDescriptor;var hn=Object.getOwnPropertyNames;var gn=Object.getPrototypeOf,fn=Object.prototype.hasOwnProperty;var ye=(c,n)=>()=>(c&&(n=c(c=0)),n);var pt=(c,n)=>()=>(n||c((n={exports:{}}).exports,n),n.exports),mn=(c,n)=>{for(var s in n)Ne(c,s,{get:n[s],enumerable:!0})},wn=(c,n,s,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let l of hn(n))!fn.call(c,l)&&l!==s&&Ne(c,l,{get:()=>n[l],enumerable:!(o=yn(n,l))||o.enumerable});return c};var bn=(c,n,s)=>(s=c!=null?pn(gn(c)):{},wn(n||!c||!c.__esModule?Ne(s,"default",{value:c,enumerable:!0}):s,c));var E=ye(()=>{"use strict"});function An(c,n){this.fun=c,this.array=n}function yt(c){var n=Math.floor((Date.now()-te.now())*.001),s=te.now()*.001,o=Math.floor(s)+n,l=Math.floor(s%1*1e9);return c&&(o=o-c[0],l=l-c[1],l<0&&(o--,l+=Re)),[o,l]}var Zn,te,Oe,Re,ht=ye(()=>{"use strict";E();T();v();An.prototype.run=function(){this.fun.apply(null,this.array)};Zn={PATH:"/usr/bin",LANG:navigator.language+".UTF-8",PWD:"/",HOME:"/home",TMP:"/tmp"},te={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0};te.now===void 0&&(Oe=Date.now(),te.timing&&te.timing.navigationStart&&(Oe=te.timing.navigationStart),te.now=()=>Date.now()-Oe);Re=1e9;yt.bigint=function(c){var n=yt(c);return typeof BigInt>"u"?n[0]*Re+n[1]:BigInt(n[0]*Re)+BigInt(n[1])}});var v=ye(()=>{"use strict";ht()});function In(){if(gt)return he;gt=!0,he.byteLength=g,he.toByteArray=I,he.fromByteArray=_;for(var c=[],n=[],s=typeof Uint8Array<"u"?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,p=o.length;l<p;++l)c[l]=o[l],n[o.charCodeAt(l)]=l;n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63;function a(h){var w=h.length;if(w%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var B=h.indexOf("=");B===-1&&(B=w);var x=B===w?0:4-B%4;return[B,x]}function g(h){var w=a(h),B=w[0],x=w[1];return(B+x)*3/4-x}function m(h,w,B){return(w+B)*3/4-B}function I(h){var w,B=a(h),x=B[0],k=B[1],C=new s(m(h,x,k)),U=0,M=k>0?x-4:x,K;for(K=0;K<M;K+=4)w=n[h.charCodeAt(K)]<<18|n[h.charCodeAt(K+1)]<<12|n[h.charCodeAt(K+2)]<<6|n[h.charCodeAt(K+3)],C[U++]=w>>16&255,C[U++]=w>>8&255,C[U++]=w&255;return k===2&&(w=n[h.charCodeAt(K)]<<2|n[h.charCodeAt(K+1)]>>4,C[U++]=w&255),k===1&&(w=n[h.charCodeAt(K)]<<10|n[h.charCodeAt(K+1)]<<4|n[h.charCodeAt(K+2)]>>2,C[U++]=w>>8&255,C[U++]=w&255),C}function f(h){return c[h>>18&63]+c[h>>12&63]+c[h>>6&63]+c[h&63]}function A(h,w,B){for(var x,k=[],C=w;C<B;C+=3)x=(h[C]<<16&16711680)+(h[C+1]<<8&65280)+(h[C+2]&255),k.push(f(x));return k.join("")}function _(h){for(var w,B=h.length,x=B%3,k=[],C=16383,U=0,M=B-x;U<M;U+=C)k.push(A(h,U,U+C>M?M:U+C));return x===1?(w=h[B-1],k.push(c[w>>2]+c[w<<4&63]+"==")):x===2&&(w=(h[B-2]<<8)+h[B-1],k.push(c[w>>10]+c[w>>4&63]+c[w<<2&63]+"=")),k.join("")}return he}function En(){if(ft)return Ae;ft=!0;return Ae.read=function(c,n,s,o,l){var p,a,g=l*8-o-1,m=(1<<g)-1,I=m>>1,f=-7,A=s?l-1:0,_=s?-1:1,h=c[n+A];for(A+=_,p=h&(1<<-f)-1,h>>=-f,f+=g;f>0;p=p*256+c[n+A],A+=_,f-=8);for(a=p&(1<<-f)-1,p>>=-f,f+=o;f>0;a=a*256+c[n+A],A+=_,f-=8);if(p===0)p=1-I;else{if(p===m)return a?NaN:(h?-1:1)*(1/0);a=a+Math.pow(2,o),p=p-I}return(h?-1:1)*a*Math.pow(2,p-o)},Ae.write=function(c,n,s,o,l,p){var a,g,m,I=p*8-l-1,f=(1<<I)-1,A=f>>1,_=l===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=o?0:p-1,w=o?1:-1,B=n<0||n===0&&1/n<0?1:0;for(n=Math.abs(n),isNaN(n)||n===1/0?(g=isNaN(n)?1:0,a=f):(a=Math.floor(Math.log(n)/Math.LN2),n*(m=Math.pow(2,-a))<1&&(a--,m*=2),a+A>=1?n+=_/m:n+=_*Math.pow(2,1-A),n*m>=2&&(a++,m/=2),a+A>=f?(g=0,a=f):a+A>=1?(g=(n*m-1)*Math.pow(2,l),a=a+A):(g=n*Math.pow(2,A-1)*Math.pow(2,l),a=0));l>=8;c[s+h]=g&255,h+=w,g/=256,l-=8);for(a=a<<l|g,I+=l;I>0;c[s+h]=a&255,h+=w,a/=256,I-=8);c[s+h-w]|=B*128},Ae}function vn(){if(mt)return ne;mt=!0;let c=In(),n=En(),s=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ne.Buffer=a,ne.SlowBuffer=k,ne.INSPECT_MAX_BYTES=50;let o=2147483647;ne.kMaxLength=o,a.TYPED_ARRAY_SUPPORT=l(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&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 l(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{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 p(r){if(r>o)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,a.prototype),e}function a(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return f(r)}return g(r,e,t)}a.poolSize=8192;function g(r,e,t){if(typeof r=="string")return A(r,e);if(ArrayBuffer.isView(r))return h(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(G(r,ArrayBuffer)||r&&G(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(G(r,SharedArrayBuffer)||r&&G(r.buffer,SharedArrayBuffer)))return w(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=r.valueOf&&r.valueOf();if(i!=null&&i!==r)return a.from(i,e,t);let u=B(r);if(u)return u;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return a.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}a.from=function(r,e,t){return g(r,e,t)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function m(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function I(r,e,t){return m(r),r<=0?p(r):e!==void 0?typeof t=="string"?p(r).fill(e,t):p(r).fill(e):p(r)}a.alloc=function(r,e,t){return I(r,e,t)};function f(r){return m(r),p(r<0?0:x(r)|0)}a.allocUnsafe=function(r){return f(r)},a.allocUnsafeSlow=function(r){return f(r)};function A(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!a.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=C(r,e)|0,i=p(t),u=i.write(r,e);return u!==t&&(i=i.slice(0,u)),i}function _(r){let e=r.length<0?0:x(r.length)|0,t=p(e);for(let i=0;i<e;i+=1)t[i]=r[i]&255;return t}function h(r){if(G(r,Uint8Array)){let e=new Uint8Array(r);return w(e.buffer,e.byteOffset,e.byteLength)}return _(r)}function w(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let i;return e===void 0&&t===void 0?i=new Uint8Array(r):t===void 0?i=new Uint8Array(r,e):i=new Uint8Array(r,e,t),Object.setPrototypeOf(i,a.prototype),i}function B(r){if(a.isBuffer(r)){let e=x(r.length)|0,t=p(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Ke(r.length)?p(0):_(r);if(r.type==="Buffer"&&Array.isArray(r.data))return _(r.data)}function x(r){if(r>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return r|0}function k(r){return+r!=r&&(r=0),a.alloc(+r)}a.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==a.prototype},a.compare=function(e,t){if(G(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),G(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(e)||!a.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,u=t.length;for(let d=0,y=Math.min(i,u);d<y;++d)if(e[d]!==t[d]){i=e[d],u=t[d];break}return i<u?-1:u<i?1:0},a.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}},a.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return a.alloc(0);let i;if(t===void 0)for(t=0,i=0;i<e.length;++i)t+=e[i].length;let u=a.allocUnsafe(t),d=0;for(i=0;i<e.length;++i){let y=e[i];if(G(y,Uint8Array))d+y.length>u.length?(a.isBuffer(y)||(y=a.from(y)),y.copy(u,d)):Uint8Array.prototype.set.call(u,y,d);else if(a.isBuffer(y))y.copy(u,d);else throw new TypeError('"list" argument must be an Array of Buffers');d+=y.length}return u};function C(r,e){if(a.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||G(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&t===0)return 0;let u=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Me(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return dt(r).length;default:if(u)return i?-1:Me(r).length;e=(""+e).toLowerCase(),u=!0}}a.byteLength=C;function U(r,e,t){let i=!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(r||(r="utf8");;)switch(r){case"hex":return nn(this,e,t);case"utf8":case"utf-8":return nt(this,e,t);case"ascii":return en(this,e,t);case"latin1":case"binary":return tn(this,e,t);case"base64":return Jt(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return rn(this,e,t);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),i=!0}}a.prototype._isBuffer=!0;function M(r,e,t){let i=r[e];r[e]=r[t],r[t]=i}a.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)M(this,t,t+1);return this},a.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)M(this,t,t+3),M(this,t+1,t+2);return this},a.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)M(this,t,t+7),M(this,t+1,t+6),M(this,t+2,t+5),M(this,t+3,t+4);return this},a.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?nt(this,0,e):U.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(e){if(!a.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:a.compare(this,e)===0},a.prototype.inspect=function(){let e="",t=ne.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},s&&(a.prototype[s]=a.prototype.inspect),a.prototype.compare=function(e,t,i,u,d){if(G(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),i===void 0&&(i=e?e.length:0),u===void 0&&(u=0),d===void 0&&(d=this.length),t<0||i>e.length||u<0||d>this.length)throw new RangeError("out of range index");if(u>=d&&t>=i)return 0;if(u>=d)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,u>>>=0,d>>>=0,this===e)return 0;let y=d-u,S=i-t,R=Math.min(y,S),N=this.slice(u,d),D=e.slice(t,i);for(let P=0;P<R;++P)if(N[P]!==D[P]){y=N[P],S=D[P];break}return y<S?-1:S<y?1:0};function K(r,e,t,i,u){if(r.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Ke(t)&&(t=u?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(u)return-1;t=r.length-1}else if(t<0)if(u)t=0;else return-1;if(typeof e=="string"&&(e=a.from(e,i)),a.isBuffer(e))return e.length===0?-1:H(r,e,t,i,u);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?u?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):H(r,[e],t,i,u);throw new TypeError("val must be string, number or Buffer")}function H(r,e,t,i,u){let d=1,y=r.length,S=e.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(r.length<2||e.length<2)return-1;d=2,y/=2,S/=2,t/=2}function R(D,P){return d===1?D[P]:D.readUInt16BE(P*d)}let N;if(u){let D=-1;for(N=t;N<y;N++)if(R(r,N)===R(e,D===-1?0:N-D)){if(D===-1&&(D=N),N-D+1===S)return D*d}else D!==-1&&(N-=N-D),D=-1}else for(t+S>y&&(t=y-S),N=t;N>=0;N--){let D=!0;for(let P=0;P<S;P++)if(R(r,N+P)!==R(e,P)){D=!1;break}if(D)return N}return-1}a.prototype.includes=function(e,t,i){return this.indexOf(e,t,i)!==-1},a.prototype.indexOf=function(e,t,i){return K(this,e,t,i,!0)},a.prototype.lastIndexOf=function(e,t,i){return K(this,e,t,i,!1)};function z(r,e,t,i){t=Number(t)||0;let u=r.length-t;i?(i=Number(i),i>u&&(i=u)):i=u;let d=e.length;i>d/2&&(i=d/2);let y;for(y=0;y<i;++y){let S=parseInt(e.substr(y*2,2),16);if(Ke(S))return y;r[t+y]=S}return y}function ae(r,e,t,i){return be(Me(e,r.length-t),r,t,i)}function Yt(r,e,t,i){return be(cn(e),r,t,i)}function Xt(r,e,t,i){return be(dt(e),r,t,i)}function Zt(r,e,t,i){return be(un(e,r.length-t),r,t,i)}a.prototype.write=function(e,t,i,u){if(t===void 0)u="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")u=t,i=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(i)?(i=i>>>0,u===void 0&&(u="utf8")):(u=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let d=this.length-t;if((i===void 0||i>d)&&(i=d),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");u||(u="utf8");let y=!1;for(;;)switch(u){case"hex":return z(this,e,t,i);case"utf8":case"utf-8":return ae(this,e,t,i);case"ascii":case"latin1":case"binary":return Yt(this,e,t,i);case"base64":return Xt(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Zt(this,e,t,i);default:if(y)throw new TypeError("Unknown encoding: "+u);u=(""+u).toLowerCase(),y=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Jt(r,e,t){return e===0&&t===r.length?c.fromByteArray(r):c.fromByteArray(r.slice(e,t))}function nt(r,e,t){t=Math.min(r.length,t);let i=[],u=e;for(;u<t;){let d=r[u],y=null,S=d>239?4:d>223?3:d>191?2:1;if(u+S<=t){let R,N,D,P;switch(S){case 1:d<128&&(y=d);break;case 2:R=r[u+1],(R&192)===128&&(P=(d&31)<<6|R&63,P>127&&(y=P));break;case 3:R=r[u+1],N=r[u+2],(R&192)===128&&(N&192)===128&&(P=(d&15)<<12|(R&63)<<6|N&63,P>2047&&(P<55296||P>57343)&&(y=P));break;case 4:R=r[u+1],N=r[u+2],D=r[u+3],(R&192)===128&&(N&192)===128&&(D&192)===128&&(P=(d&15)<<18|(R&63)<<12|(N&63)<<6|D&63,P>65535&&P<1114112&&(y=P))}}y===null?(y=65533,S=1):y>65535&&(y-=65536,i.push(y>>>10&1023|55296),y=56320|y&1023),i.push(y),u+=S}return Qt(i)}let rt=4096;function Qt(r){let e=r.length;if(e<=rt)return String.fromCharCode.apply(String,r);let t="",i=0;for(;i<e;)t+=String.fromCharCode.apply(String,r.slice(i,i+=rt));return t}function en(r,e,t){let i="";t=Math.min(r.length,t);for(let u=e;u<t;++u)i+=String.fromCharCode(r[u]&127);return i}function tn(r,e,t){let i="";t=Math.min(r.length,t);for(let u=e;u<t;++u)i+=String.fromCharCode(r[u]);return i}function nn(r,e,t){let i=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>i)&&(t=i);let u="";for(let d=e;d<t;++d)u+=ln[r[d]];return u}function rn(r,e,t){let i=r.slice(e,t),u="";for(let d=0;d<i.length-1;d+=2)u+=String.fromCharCode(i[d]+i[d+1]*256);return u}a.prototype.slice=function(e,t){let i=this.length;e=~~e,t=t===void 0?i:~~t,e<0?(e+=i,e<0&&(e=0)):e>i&&(e=i),t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),t<e&&(t=e);let u=this.subarray(e,t);return Object.setPrototypeOf(u,a.prototype),u};function L(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||L(e,t,this.length);let u=this[e],d=1,y=0;for(;++y<t&&(d*=256);)u+=this[e+y]*d;return u},a.prototype.readUintBE=a.prototype.readUIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||L(e,t,this.length);let u=this[e+--t],d=1;for(;t>0&&(d*=256);)u+=this[e+--t]*d;return u},a.prototype.readUint8=a.prototype.readUInt8=function(e,t){return e=e>>>0,t||L(e,1,this.length),this[e]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||L(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||L(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||L(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||L(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readBigUInt64LE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&pe(e,this.length-8);let u=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,d=this[++e]+this[++e]*2**8+this[++e]*2**16+i*2**24;return BigInt(u)+(BigInt(d)<<BigInt(32))}),a.prototype.readBigUInt64BE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&pe(e,this.length-8);let u=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],d=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i;return(BigInt(u)<<BigInt(32))+BigInt(d)}),a.prototype.readIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||L(e,t,this.length);let u=this[e],d=1,y=0;for(;++y<t&&(d*=256);)u+=this[e+y]*d;return d*=128,u>=d&&(u-=Math.pow(2,8*t)),u},a.prototype.readIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||L(e,t,this.length);let u=t,d=1,y=this[e+--u];for(;u>0&&(d*=256);)y+=this[e+--u]*d;return d*=128,y>=d&&(y-=Math.pow(2,8*t)),y},a.prototype.readInt8=function(e,t){return e=e>>>0,t||L(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},a.prototype.readInt16LE=function(e,t){e=e>>>0,t||L(e,2,this.length);let i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i},a.prototype.readInt16BE=function(e,t){e=e>>>0,t||L(e,2,this.length);let i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i},a.prototype.readInt32LE=function(e,t){return e=e>>>0,t||L(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e=e>>>0,t||L(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readBigInt64LE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&pe(e,this.length-8);let u=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(i<<24);return(BigInt(u)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),a.prototype.readBigInt64BE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&pe(e,this.length-8);let u=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(u)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i)}),a.prototype.readFloatLE=function(e,t){return e=e>>>0,t||L(e,4,this.length),n.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e=e>>>0,t||L(e,4,this.length),n.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||L(e,8,this.length),n.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||L(e,8,this.length),n.read(this,e,!1,52,8)};function q(r,e,t,i,u,d){if(!a.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>u||e<d)throw new RangeError('"value" argument is out of bounds');if(t+i>r.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(e,t,i,u){if(e=+e,t=t>>>0,i=i>>>0,!u){let S=Math.pow(2,8*i)-1;q(this,e,t,i,S,0)}let d=1,y=0;for(this[t]=e&255;++y<i&&(d*=256);)this[t+y]=e/d&255;return t+i},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(e,t,i,u){if(e=+e,t=t>>>0,i=i>>>0,!u){let S=Math.pow(2,8*i)-1;q(this,e,t,i,S,0)}let d=i-1,y=1;for(this[t+d]=e&255;--d>=0&&(y*=256);)this[t+d]=e/y&255;return t+i},a.prototype.writeUint8=a.prototype.writeUInt8=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,1,255,0),this[t]=e&255,t+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function it(r,e,t,i,u){lt(e,i,u,r,t,7);let d=Number(e&BigInt(4294967295));r[t++]=d,d=d>>8,r[t++]=d,d=d>>8,r[t++]=d,d=d>>8,r[t++]=d;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,t}function st(r,e,t,i,u){lt(e,i,u,r,t,7);let d=Number(e&BigInt(4294967295));r[t+7]=d,d=d>>8,r[t+6]=d,d=d>>8,r[t+5]=d,d=d>>8,r[t+4]=d;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=y,y=y>>8,r[t+2]=y,y=y>>8,r[t+1]=y,y=y>>8,r[t]=y,t+8}a.prototype.writeBigUInt64LE=Z(function(e,t=0){return it(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Z(function(e,t=0){return st(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(e,t,i,u){if(e=+e,t=t>>>0,!u){let R=Math.pow(2,8*i-1);q(this,e,t,i,R-1,-R)}let d=0,y=1,S=0;for(this[t]=e&255;++d<i&&(y*=256);)e<0&&S===0&&this[t+d-1]!==0&&(S=1),this[t+d]=(e/y>>0)-S&255;return t+i},a.prototype.writeIntBE=function(e,t,i,u){if(e=+e,t=t>>>0,!u){let R=Math.pow(2,8*i-1);q(this,e,t,i,R-1,-R)}let d=i-1,y=1,S=0;for(this[t+d]=e&255;--d>=0&&(y*=256);)e<0&&S===0&&this[t+d+1]!==0&&(S=1),this[t+d]=(e/y>>0)-S&255;return t+i},a.prototype.writeInt8=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},a.prototype.writeInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},a.prototype.writeInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},a.prototype.writeBigInt64LE=Z(function(e,t=0){return it(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Z(function(e,t=0){return st(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function at(r,e,t,i,u,d){if(t+i>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function ot(r,e,t,i,u){return e=+e,t=t>>>0,u||at(r,e,t,4),n.write(r,e,t,i,23,4),t+4}a.prototype.writeFloatLE=function(e,t,i){return ot(this,e,t,!0,i)},a.prototype.writeFloatBE=function(e,t,i){return ot(this,e,t,!1,i)};function ct(r,e,t,i,u){return e=+e,t=t>>>0,u||at(r,e,t,8),n.write(r,e,t,i,52,8),t+8}a.prototype.writeDoubleLE=function(e,t,i){return ct(this,e,t,!0,i)},a.prototype.writeDoubleBE=function(e,t,i){return ct(this,e,t,!1,i)},a.prototype.copy=function(e,t,i,u){if(!a.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),!u&&u!==0&&(u=this.length),t>=e.length&&(t=e.length),t||(t=0),u>0&&u<i&&(u=i),u===i||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("sourceEnd out of bounds");u>this.length&&(u=this.length),e.length-t<u-i&&(u=e.length-t+i);let d=u-i;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,i,u):Uint8Array.prototype.set.call(e,this.subarray(i,u),t),d},a.prototype.fill=function(e,t,i,u){if(typeof e=="string"){if(typeof t=="string"?(u=t,t=0,i=this.length):typeof i=="string"&&(u=i,i=this.length),u!==void 0&&typeof u!="string")throw new TypeError("encoding must be a string");if(typeof u=="string"&&!a.isEncoding(u))throw new TypeError("Unknown encoding: "+u);if(e.length===1){let y=e.charCodeAt(0);(u==="utf8"&&y<128||u==="latin1")&&(e=y)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;t=t>>>0,i=i===void 0?this.length:i>>>0,e||(e=0);let d;if(typeof e=="number")for(d=t;d<i;++d)this[d]=e;else{let y=a.isBuffer(e)?e:a.from(e,u),S=y.length;if(S===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(d=0;d<i-t;++d)this[d+t]=y[d%S]}return this};let oe={};function Pe(r,e,t){oe[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(u){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:u,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Pe("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Pe("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),Pe("ERR_OUT_OF_RANGE",function(r,e,t){let i=`The value of "${r}" is out of range.`,u=t;return Number.isInteger(t)&&Math.abs(t)>2**32?u=ut(String(t)):typeof t=="bigint"&&(u=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(u=ut(u)),u+="n"),i+=` It must be ${e}. Received ${u}`,i},RangeError);function ut(r){let e="",t=r.length,i=r[0]==="-"?1:0;for(;t>=i+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function sn(r,e,t){ce(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&pe(e,r.length-(t+1))}function lt(r,e,t,i,u,d){if(r>t||r<e){let y=typeof e=="bigint"?"n":"",S;throw d>3?e===0||e===BigInt(0)?S=`>= 0${y} and < 2${y} ** ${(d+1)*8}${y}`:S=`>= -(2${y} ** ${(d+1)*8-1}${y}) and < 2 ** ${(d+1)*8-1}${y}`:S=`>= ${e}${y} and <= ${t}${y}`,new oe.ERR_OUT_OF_RANGE("value",S,r)}sn(i,u,d)}function ce(r,e){if(typeof r!="number")throw new oe.ERR_INVALID_ARG_TYPE(e,"number",r)}function pe(r,e,t){throw Math.floor(r)!==r?(ce(r,t),new oe.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new oe.ERR_BUFFER_OUT_OF_BOUNDS:new oe.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let an=/[^+/0-9A-Za-z-_]/g;function on(r){if(r=r.split("=")[0],r=r.trim().replace(an,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Me(r,e){e=e||1/0;let t,i=r.length,u=null,d=[];for(let y=0;y<i;++y){if(t=r.charCodeAt(y),t>55295&&t<57344){if(!u){if(t>56319){(e-=3)>-1&&d.push(239,191,189);continue}else if(y+1===i){(e-=3)>-1&&d.push(239,191,189);continue}u=t;continue}if(t<56320){(e-=3)>-1&&d.push(239,191,189),u=t;continue}t=(u-55296<<10|t-56320)+65536}else u&&(e-=3)>-1&&d.push(239,191,189);if(u=null,t<128){if((e-=1)<0)break;d.push(t)}else if(t<2048){if((e-=2)<0)break;d.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;d.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;d.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return d}function cn(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function un(r,e){let t,i,u,d=[];for(let y=0;y<r.length&&!((e-=2)<0);++y)t=r.charCodeAt(y),i=t>>8,u=t%256,d.push(u),d.push(i);return d}function dt(r){return c.toByteArray(on(r))}function be(r,e,t,i){let u;for(u=0;u<i&&!(u+t>=e.length||u>=r.length);++u)e[u+t]=r[u];return u}function G(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Ke(r){return r!==r}let ln=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let i=t*16;for(let u=0;u<16;++u)e[i+u]=r[t]+r[u]}return e}();function Z(r){return typeof BigInt>"u"?dn:r}function dn(){throw new Error("BigInt not supported")}return ne}var he,gt,Ae,ft,ne,mt,re,O,rr,ir,De=ye(()=>{"use strict";E();T();v();he={},gt=!1;Ae={},ft=!1;ne={},mt=!1;re=vn();re.Buffer;re.SlowBuffer;re.INSPECT_MAX_BYTES;re.kMaxLength;O=re.Buffer,rr=re.INSPECT_MAX_BYTES,ir=re.kMaxLength});var T=ye(()=>{"use strict";De()});var bt=pt((dr,wt)=>{"use strict";E();T();v();function Tn(c){if(c.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<c.length;o++){var l=c.charAt(o),p=l.charCodeAt(0);if(n[p]!==255)throw new TypeError(l+" is ambiguous");n[p]=o}var a=c.length,g=c.charAt(0),m=Math.log(a)/Math.log(256),I=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var w=0,B=0,x=0,k=h.length;x!==k&&h[x]===0;)x++,w++;for(var C=(k-x)*I+1>>>0,U=new Uint8Array(C);x!==k;){for(var M=h[x],K=0,H=C-1;(M!==0||K<B)&&H!==-1;H--,K++)M+=256*U[H]>>>0,U[H]=M%a>>>0,M=M/a>>>0;if(M!==0)throw new Error("Non-zero carry");B=K,x++}for(var z=C-B;z!==C&&U[z]===0;)z++;for(var ae=g.repeat(w);z<C;++z)ae+=c.charAt(U[z]);return ae}function A(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var w=0,B=0,x=0;h[w]===g;)B++,w++;for(var k=(h.length-w)*m+1>>>0,C=new Uint8Array(k);h[w];){var U=n[h.charCodeAt(w)];if(U===255)return;for(var M=0,K=k-1;(U!==0||M<x)&&K!==-1;K--,M++)U+=a*C[K]>>>0,C[K]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");x=M,w++}for(var H=k-x;H!==k&&C[H]===0;)H++;for(var z=new Uint8Array(B+(k-H)),ae=B;H!==k;)z[ae++]=C[H++];return z}function _(h){var w=A(h);if(w)return w;throw new Error("Non-base"+a+" character")}return{encode:f,decodeUnsafe:A,decode:_}}wt.exports=Tn});var It=pt((gr,At)=>{"use strict";E();T();v();var Bn=bt(),xn="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";At.exports=Bn(xn)});E();T();v();E();T();v();E();T();v();var fe=bn(It());E();T();v();var $=2n**255n-19n,ue=2n**252n+27742317777372353535851937790883648493n,Fe=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Ve=0x6666666666666666666666666666666666666666666666666666666666666658n,Ie={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:$,n:ue,h:8,Gx:Fe,Gy:Ve},j=(c="")=>{throw new Error(c)},xt=c=>typeof c=="string",Te=(c,n)=>!(c instanceof Uint8Array)||typeof n=="number"&&n>0&&c.length!==n?j("Uint8Array expected"):c,le=c=>new Uint8Array(c),Be=(c,n)=>Te(xt(c)?He(c):le(c),n),b=(c,n=$)=>{let s=c%n;return s>=0n?s:n+s},Et=c=>c instanceof J?c:j("Point expected"),vt,J=class c{constructor(n,s,o,l){this.ex=n,this.ey=s,this.ez=o,this.et=l}static fromAffine(n){return new c(n.x,n.y,1n,b(n.x*n.y))}static fromHex(n,s=!0){let{d:o}=Ie;n=Be(n,32);let l=n.slice();l[31]=n[31]&-129;let p=_t(l);p===0n||(s&&!(0n<p&&p<$)&&j("bad y coord 1"),!s&&!(0n<p&&p<2n**256n)&&j("bad y coord 2"));let a=b(p*p),g=b(a-1n),m=b(o*a+1n),{isValid:I,value:f}=Cn(g,m);I||j("bad y coordinate 3");let A=(f&1n)===1n;return(n[31]&128)!==0!==A&&(f=b(-f)),new c(f,p,1n,b(f*p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(n){let{ex:s,ey:o,ez:l}=this,{ex:p,ey:a,ez:g}=Et(n),m=b(s*g),I=b(p*l),f=b(o*g),A=b(a*l);return m===I&&f===A}is0(){return this.equals(Ee)}negate(){return new c(b(-this.ex),this.ey,this.ez,b(-this.et))}double(){let{ex:n,ey:s,ez:o}=this,{a:l}=Ie,p=b(n*n),a=b(s*s),g=b(2n*b(o*o)),m=b(l*p),I=n+s,f=b(b(I*I)-p-a),A=m+a,_=A-g,h=m-a,w=b(f*_),B=b(A*h),x=b(f*h),k=b(_*A);return new c(w,B,k,x)}add(n){let{ex:s,ey:o,ez:l,et:p}=this,{ex:a,ey:g,ez:m,et:I}=Et(n),{a:f,d:A}=Ie,_=b(s*a),h=b(o*g),w=b(p*A*I),B=b(l*m),x=b((s+o)*(a+g)-_-h),k=b(B-w),C=b(B+w),U=b(h-f*_),M=b(x*k),K=b(C*U),H=b(x*U),z=b(k*C);return new c(M,K,z,H)}mul(n,s=!0){if(n===0n)return s===!0?j("cannot multiply by 0"):Ee;if(typeof n=="bigint"&&0n<n&&n<ue||j("invalid scalar, must be < L"),!s&&this.is0()||n===1n)return this;if(this.equals(se))return Mn(n).p;let o=Ee,l=se;for(let p=this;n>0n;p=p.double(),n>>=1n)n&1n?o=o.add(p):s&&(l=l.add(p));return o}multiply(n){return this.mul(n)}clearCofactor(){return this.mul(BigInt(Ie.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let n=this.mul(ue/2n,!1).double();return ue%2n&&(n=n.add(this)),n.is0()}toAffine(){let{ex:n,ey:s,ez:o}=this;if(this.is0())return{x:0n,y:0n};let l=kt(o);return b(o*l)!==1n&&j("invalid inverse"),{x:b(n*l),y:b(s*l)}}toRawBytes(){let{x:n,y:s}=this.toAffine(),o=Ct(s);return o[31]|=n&1n?128:0,o}toHex(){return $e(this.toRawBytes())}};J.BASE=new J(Fe,Ve,1n,b(Fe*Ve));J.ZERO=new J(0n,1n,1n,0n);var{BASE:se,ZERO:Ee}=J,St=(c,n)=>c.toString(16).padStart(n,"0"),$e=c=>Array.from(c).map(n=>St(n,2)).join(""),He=c=>{let n=c.length;(!xt(c)||n%2)&&j("hex invalid 1");let s=le(n/2);for(let o=0;o<s.length;o++){let l=o*2,p=c.slice(l,l+2),a=Number.parseInt(p,16);(Number.isNaN(a)||a<0)&&j("hex invalid 2"),s[o]=a}return s},Ct=c=>He(St(c,32*2)).reverse(),_t=c=>BigInt("0x"+$e(le(Te(c)).reverse())),ve=(...c)=>{let n=le(c.reduce((o,l)=>o+Te(l).length,0)),s=0;return c.forEach(o=>{n.set(o,s),s+=o.length}),n},kt=(c,n=$)=>{(c===0n||n<=0n)&&j("no inverse n="+c+" mod="+n);let s=b(c,n),o=n,l=0n,p=1n,a=1n,g=0n;for(;s!==0n;){let m=o/s,I=o%s,f=l-a*m,A=p-g*m;o=s,s=I,l=a,p=g,a=f,g=A}return o===1n?b(l,n):j("no inverse")},Y=(c,n)=>{let s=c;for(;n-- >0n;)s*=s,s%=$;return s},Sn=c=>{let s=c*c%$*c%$,o=Y(s,2n)*s%$,l=Y(o,1n)*c%$,p=Y(l,5n)*l%$,a=Y(p,10n)*p%$,g=Y(a,20n)*a%$,m=Y(g,40n)*g%$,I=Y(m,80n)*m%$,f=Y(I,80n)*m%$,A=Y(f,10n)*p%$;return{pow_p_5_8:Y(A,2n)*c%$,b2:s}},Tt=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Cn=(c,n)=>{let s=b(n*n*n),o=b(s*s*n),l=Sn(c*o).pow_p_5_8,p=b(c*s*l),a=b(n*p*p),g=p,m=b(p*Tt),I=a===c,f=a===b(-c),A=a===b(-c*Tt);return I&&(p=g),(f||A)&&(p=m),(b(p)&1n)===1n&&(p=b(-p)),{isValid:I||f,value:p}},Le=c=>b(_t(c),ue),ge,je=(...c)=>qe.sha512Async(...c),Ut=(...c)=>typeof ge=="function"?ge(...c):j("etc.sha512Sync not set"),Pt=c=>{let n=c.slice(0,32);n[0]&=248,n[31]&=127,n[31]|=64;let s=c.slice(32,64),o=Le(n),l=se.mul(o),p=l.toRawBytes();return{head:n,prefix:s,scalar:o,point:l,pointBytes:p}},We=c=>je(Be(c,32)).then(Pt),_n=c=>Pt(Ut(Be(c,32))),Mt=c=>We(c).then(n=>n.pointBytes);function kn(c,n){return c?je(n.hashable).then(n.finish):n.finish(Ut(n.hashable))}var Un=(c,n,s)=>{let{pointBytes:o,scalar:l}=c,p=Le(n),a=se.mul(p).toRawBytes();return{hashable:ve(a,o,s),finish:I=>{let f=b(p+Le(I)*l,ue);return Te(ve(a,Ct(f)),64)}}},Kt=async(c,n)=>{let s=Be(c),o=await We(n),l=await je(o.prefix,s);return kn(!0,Un(o,l,s))};var Bt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,qe={bytesToHex:$e,hexToBytes:He,concatBytes:ve,mod:b,invert:kt,randomBytes:c=>{let n=Bt();return n||j("crypto.getRandomValues must be defined"),n.getRandomValues(le(c))},sha512Async:async(...c)=>{let n=Bt();n||j("crypto.subtle or etc.sha512Async must be defined");let s=ve(...c);return le(await n.subtle.digest("SHA-512",s.buffer))},sha512Sync:void 0};Object.defineProperties(qe,{sha512Sync:{configurable:!1,get(){return ge},set(c){ge||(ge=c)}}});var Nt={getExtendedPublicKeyAsync:We,getExtendedPublicKey:_n,randomPrivateKey:()=>qe.randomBytes(32),precompute(c=8,n=se){return n.multiply(3n),n}},ie=8,Pn=()=>{let c=[],n=256/ie+1,s=se,o=s;for(let l=0;l<n;l++){o=s,c.push(o);for(let p=1;p<2**(ie-1);p++)o=o.add(s),c.push(o);s=o.double()}return c},Mn=c=>{let n=vt||(vt=Pn()),s=(f,A)=>{let _=A.negate();return f?_:A},o=Ee,l=se,p=1+256/ie,a=2**(ie-1),g=BigInt(2**ie-1),m=2**ie,I=BigInt(ie);for(let f=0;f<p;f++){let A=f*a,_=Number(c&g);c>>=I,_>a&&(_-=m,c+=1n);let h=A,w=A+Math.abs(_)-1,B=f%2!==0,x=_<0;_===0?l=l.add(s(B,n[h])):o=o.add(s(x,n[w]))}return{p:o,f:l}};var Q=class c{static generateKey(){let n,s;do n=Nt.randomPrivateKey(),s=(0,fe.encode)(n);while(s.length!==44);return new c(s)}constructor(n){this.secretKey=n;let s=(0,fe.decode)(n);this.privateKey=O.from(s).toString("hex")}async sign(n){return await Kt(n,this.privateKey)}async getPublicKey(){let n=await Mt(this.privateKey);return`ed25519:${(0,fe.encode)(n)}`}toString(){return this.privateKey}};var xe=class{constructor(n="testnet"){this.networkId=n}get keyPrefix(){return`orderly_${this.networkId}_`}},me=class extends xe{getOrderlyKey(n){let s;if(n)s=this.getItem(n,"orderlyKey");else{let o=this.getAddress();if(!o)return null;s=this.getItem(o,"orderlyKey")}return s?new Q(s):null}getAccountId(n){return this.getItem(n,"accountId")}setAccountId(n,s){this.setItem(n,{accountId:s})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(n){localStorage.setItem(`${this.keyPrefix}address`,n)}generateKey(){return Q.generateKey()}setKey(n,s){this.setItem(n,{orderlyKey:s.secretKey})}cleanAllKey(n){localStorage.removeItem(`${this.keyPrefix}${n}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(n,s){let o=this.getItem(n);delete o[s],localStorage.setItem(`${this.keyPrefix}${n}`,JSON.stringify(o))}setItem(n,s){let o=`${this.keyPrefix}${n}`,l=localStorage.getItem(o);l?l=JSON.parse(l):l={},localStorage.setItem(o,JSON.stringify({...l,...s}))}getItem(n,s){let o=`${this.keyPrefix}${n}`,l=localStorage.getItem(o);return l?l=JSON.parse(l):l={},typeof s>"u"?l:l[s]}},we=class{constructor(n){this.secretKey=n}generateKey(){return new Q(this.secretKey)}getOrderlyKey(){return new Q(this.secretKey)}getAccountId(){return""}setAccountId(n){}getAddress(){return""}setAddress(n){}setKey(n,s){}cleanAllKey(){}cleanKey(n){}};E();T();v();var Ot={};mn(Ot,{base64url:()=>ze,calculateStringHash:()=>Xe,formatByUnits:()=>Ce,parseAccountId:()=>Ge,parseBrokerHash:()=>Se,parseTokenHash:()=>Ye,parseUnits:()=>Fn});E();T();v();import{keccak256 as Nn,AbiCoder as On,solidityPackedKeccak256 as Rn,formatUnits as Dn}from"ethers";import{parseUnits as Fn}from"ethers";var ze=function(c){return c.replace(/\+/g,"-").replace(/\//g,"_")};function Se(c){return Xe(c)}function Ge(c,n){let s=On.defaultAbiCoder();return Nn(s.encode(["address","bytes32"],[c,Se(n)]))}function Ye(c){return Xe(c)}function Xe(c){return Rn(["string"],[c])}function Ce(c,n="ether"){return Dn(c,n)}De();var ee=class{constructor(n){this.keyStore=n}async sign(n){let s=Date.now().toString(),o=[s,n.method.toUpperCase(),n.url].join("");n.data&&Object.keys(n.data).length&&(o+=JSON.stringify(n.data));let{signature:l,publicKey:p}=await this.signText(o);return{"orderly-key":p,"orderly-timestamp":s,"orderly-signature":l}}async signText(n){let s=this.keyStore.getOrderlyKey();if(!s)throw new Error("orderlyKeyPair is not defined");let o=O.from(n),l=await s.sign(o),p=O.from(l).toString("base64");return{signature:ze(p),publicKey:await s.getPublicKey()}}};import{default as ps}from"eventemitter3";E();T();v();E();T();v();var _e=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://testnet-api-evm.orderly.org"],["klineDataUrl","https://testnet-api-evm.orderly.org"],["publicWsUrl","wss://testnet-ws-evm.orderly.org"],["privateWsUrl","wss://testnet-ws-private-evm.orderly.org"],["operatorUrl","https://testnet-operator-evm.orderly.org"],["swapSupportApiUrl","https://fi-api.woo.org"],["domain",{testnet:"https://testnet-dex-evm.woo.org",mainnet:"https://dex-evm.woo.org",dexMainnet:"https://dex.woo.org",dexTestnet:"https://testnet-dex.woo.org"}],["brokerId","woofi_pro"],["onlyTestnet",!1],["env","dev-evm"],["PROD_URL",["dex-iap-evm.woo.org","dex-evm.woo.org"]]])}get(n){return this.map.get(n)}getOr(n,s){return this.map.get(n)??s}set(n,s){this.map.set(n,s)}clear(){}},Rt=class extends _e{constructor(s){super();this.configMap=s}_restore(){let s=Object.entries(this.configMap);this.map=new Map(s)}};E();T();v();var X={EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],Registration:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"timestamp",type:"uint64"},{name:"registrationNonce",type:"uint256"}],Withdraw:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"receiver",type:"address"},{name:"token",type:"string"},{name:"amount",type:"uint256"},{name:"withdrawNonce",type:"uint64"},{name:"timestamp",type:"uint64"}],AddOrderlyKey:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"orderlyKey",type:"string"},{name:"scope",type:"string"},{name:"timestamp",type:"uint64"},{name:"expiration",type:"uint64"}],SettlePnl:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"settleNonce",type:"uint64"},{name:"timestamp",type:"uint64"}]},Dt="0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291",Ft="0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D",Vt="0x1826B75e2ef249173FC735149AE4B8e9ea10abff";var Vn=c=>{let n=new we(c||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new ee(n)},Ln=()=>{if(typeof window>"u")throw new Error("the default signer only supports browsers.");let c=new me("");return new ee(c)};function $n(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function Lt(c,n){return{name:"Orderly",version:"1",chainId:c,verifyingContract:n?$n():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function $t(c){let{chainId:n,registrationNonce:s,brokerId:o}=c,l=Date.now(),p="Registration",a={brokerId:o,chainId:n,timestamp:l,registrationNonce:s},g={EIP712Domain:X.EIP712Domain,[p]:X[p]};return[a,{domain:Lt(n),message:a,primaryType:p,types:g}]}function Ht(c){let{publicKey:n,chainId:s,primaryType:o,brokerId:l,expiration:p=365}=c,a=Date.now(),g={brokerId:l,orderlyKey:n,scope:"read,trading",chainId:s,timestamp:a,expiration:a+1e3*60*60*24*p},m={EIP712Domain:X.EIP712Domain,[o]:X[o]},I={domain:Lt(s),message:g,primaryType:o,types:m};return[g,I]}function jt(c){let{chainId:n,settlePnlNonce:s,domain:o,brokerId:l}=c,p="SettlePnl",a=new Date().getTime(),g={EIP712Domain:X.EIP712Domain,[p]:X[p]},m={brokerId:l,chainId:n,timestamp:a,settleNonce:s};return[m,{domain:o,message:m,primaryType:p,types:g}]}E();T();v();var Ze=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"},{internalType:"uint8",name:"decimals_",type:"uint8"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"issue",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_to",type:"address"},{internalType:"uint256",name:"_amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"_paused",type:"bool"}],name:"pauseTransfers",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];var Wt=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AccountIdInvalid",type:"error"},{inputs:[{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],name:"BalanceNotEnough",type:"error"},{inputs:[],name:"BrokerNotAllowed",type:"error"},{inputs:[],name:"OnlyCrossChainManagerCanCall",type:"error"},{inputs:[],name:"TokenNotAllowed",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"address",name:"userAddress",type:"address"},{indexed:!0,internalType:"uint64",name:"depositNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"}],name:"AccountDeposit",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"address",name:"userAddress",type:"address"},{indexed:!0,internalType:"uint64",name:"depositNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"}],name:"AccountDepositTo",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"uint64",name:"withdrawNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"brokerHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"sender",type:"address"},{indexed:!1,internalType:"address",name:"receiver",type:"address"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"},{indexed:!1,internalType:"uint128",name:"fee",type:"uint128"},{indexed:!1,internalType:"uint256",name:"blocktime",type:"uint256"}],name:"AccountWithdraw",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"_tokenAddress",type:"address"}],name:"ChangeTokenAddressAndAllow",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint8",name:"version",type:"uint8"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_brokerHash",type:"bytes32"},{indexed:!1,internalType:"bool",name:"_allowed",type:"bool"}],name:"SetAllowedBroker",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{indexed:!1,internalType:"bool",name:"_allowed",type:"bool"}],name:"SetAllowedToken",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"allowedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{internalType:"address",name:"_tokenAddress",type:"address"}],name:"changeTokenAddressAndAllow",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"crossChainManagerAddress",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"}],internalType:"struct VaultTypes.VaultDepositFE",name:"data",type:"tuple"}],name:"deposit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"depositId",outputs:[{internalType:"uint64",name:"",type:"uint64"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"receiver",type:"address"},{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"}],internalType:"struct VaultTypes.VaultDepositFE",name:"data",type:"tuple"}],name:"depositTo",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"emergencyPause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"emergencyUnpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"getAllAllowedBroker",outputs:[{internalType:"bytes32[]",name:"",type:"bytes32[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAllAllowedToken",outputs:[{internalType:"bytes32[]",name:"",type:"bytes32[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_brokerHash",type:"bytes32"}],name:"getAllowedBroker",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"}],name:"getAllowedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"_brokerHash",type:"bytes32"},{internalType:"bool",name:"_allowed",type:"bool"}],name:"setAllowedBroker",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{internalType:"bool",name:"_allowed",type:"bool"}],name:"setAllowedToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_crossChainManagerAddress",type:"address"}],name:"setCrossChainManager",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"},{internalType:"uint128",name:"fee",type:"uint128"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"receiver",type:"address"},{internalType:"uint64",name:"withdrawNonce",type:"uint64"}],internalType:"struct VaultTypes.VaultWithdraw",name:"data",type:"tuple"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"}];var Je=class{constructor(n){this.configStore=n}getContractInfoByEnv(){return{usdcAddress:Dt,usdcAbi:Ze,vaultAddress:Ft,vaultAbi:Wt,verifyContractAddress:Vt,erc20Abi:Ze}}};E();T();v();E();T();v();var Qe=class{constructor(n=[],s={}){this.providers=n;this.services=s;this.injectProperties={}}register(...n){this.providers.push(...n),n.forEach(s=>{let o=s;o instanceof Function&&(o=new s),this.add(o)})}registerByName(n,s){let o=s;o instanceof Function&&(o=new s),this.addByName(n,o)}get(n){return this.services[n]}getAll(){return Object.assign({},this.services)}add(n){return this.addByName(n.constructor.name,n)}addByName(n,s){return this.services[n]=s,this.services[n.toLowerCase()]=s,this.injectIntoProperties(s,n),this.get(n)}inject(n,s,o){n&&o&&(n[s]=o)}injectIntoProperties(n,s=n.constructor.name){this.getInjectProperty(s.toLowerCase()).forEach(o=>{this.inject(o.target,o.propertyKey,n)})}getInjectProperty(n){return this.injectProperties[n]||(this.injectProperties[n]=[]),this.injectProperties[n]}},qt=Qe;var et=class c{static getContainer(){return c.container||(c.container=new qt),c.container}static register(...n){this.getContainer().register(...n)}static registerByName(n,s){this.getContainer().registerByName(n,s)}static get(n){return this.getContainer().get(n)}static getOr(n,s){return this.getContainer().get(n)||c.registerByName(n,s),s}static getAll(){return this.getContainer().getAll()}constructor(){}},Wn=et;E();T();v();import{AccountStatusEnum as W}from"@orderly.network/types";import qn from"eventemitter3";E();T();v();import{ethers as zt}from"ethers";var ke=class{constructor(n,s,o){this.configStore=n;this.contractManger=s;this.account=o}async withdraw(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");if(!this.account.stateValue.address)throw new Error("account address is rqeuired");let{chainId:s,token:o,amount:l}=n,p="/v1/withdraw_request",a=await this.getWithdrawalNonce(),g=this.account.getDomain(!0),[m,I]=this._generateWithdrawMessage({chainId:s,receiver:this.account.stateValue.address,token:o,amount:this.account.walletClient.parseUnits(l.toString()),nonce:a,domain:g}),A={signature:await this.account.signTypedData(I),message:m,userAddress:this.account.stateValue.address,verifyingContract:g.verifyingContract},_={method:"POST",url:p,data:A},h=await this.account.signer.sign(_);return await this._simpleFetch(p,{method:"POST",body:JSON.stringify(A),headers:{"Content-Type":"application/json","orderly-account-id":this.account.stateValue.accountId,...h}})}_generateWithdrawMessage(n){let{chainId:s,receiver:o,token:l,amount:p,domain:a,nonce:g}=n,m="Withdraw",I=Date.now(),f={EIP712Domain:X.EIP712Domain,[m]:X[m]},A={brokerId:this.configStore.get("brokerId"),chainId:s,receiver:o,token:l,amount:p,timestamp:I,withdrawNonce:g};return[A,{domain:a,message:A,primaryType:m,types:f}]}async getWithdrawalNonce(){let n=Date.now().toString(),s="/v1/withdraw_nonce",o=[n,"GET",s].join(""),l=this.account.signer,{publicKey:p,signature:a}=await l.signText(o),g=await this._simpleFetch(s,{headers:{"orderly-account-id":this.account.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.withdraw_nonce;throw new Error(g.message)}async getNativeBalance(n){let s=await this.account.walletClient?.getBalance(this.account.stateValue.address);return Ce(s,n?.decimals)}async getBalance(n,s){if(!this.account.walletClient)return"0";let o=this.contractManger.getContractInfoByEnv(),l=await this.account.walletClient?.call(n??o.usdcAddress,"balanceOf",[this.account.stateValue.address],{abi:o.usdcAbi});return Ce(l,s?.decimals)}async getBalanceByAddress(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),o=await this.account.walletClient?.call(n,"balanceOf",[this.account.stateValue.address],{abi:s.erc20Abi});return this.account.walletClient?.formatUnits(o)}async getAllowance(n,s){if(!this.account.walletClient)return"0";let o=this.contractManger.getContractInfoByEnv(),l=await this.account.walletClient?.call(n??o.usdcAddress,"allowance",[this.account.stateValue.address,s||o.vaultAddress],{abi:o.usdcAbi});return this.account.walletClient?.formatUnits(l)}async approve(n,s,o){if(!n)throw new Error("address is required");if(!this.account.walletClient)throw new Error("walletClient is undefined");let l=this.contractManger.getContractInfoByEnv(),p=typeof s<"u"&&s!==""?this.account.walletClient.parseUnits(s):zt.MaxUint256.toString();return await this.account.walletClient?.call(n,"approve",[o||l.vaultAddress,p],{abi:l.usdcAbi})}async approveByAddress(n){let{amount:s,address:o}=n;return this._approve(o,s)}async _approve(n,s){if(!this.account.walletClient)throw new Error("walletClient is undefined");let o=typeof s<"u"&&s!==""?this.account.walletClient.parseUnits(s):zt.MaxUint256.toString(),l=this.contractManger.getContractInfoByEnv();return await this.account.walletClient?.call(n,"approve",[l.vaultAddress,o],{abi:l.erc20Abi})}async deposit(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");let s=this.configStore.get("brokerId");if(!s)throw new Error("brokerId is required");let o=this.contractManger.getContractInfoByEnv(),l={accountId:this.account.accountIdHashStr,brokerHash:Se(s),tokenHash:Ye("USDC"),tokenAmount:this.account.walletClient?.parseUnits(n)};return await this.account.walletClient?.sendTransaction(o.vaultAddress,"deposit",{from:this.account.stateValue.address,to:o.vaultAddress,data:[l],value:0n},{abi:o.vaultAbi})}async _simpleFetch(n,s={}){let o=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(o,s).then(l=>l.json())}get usdcAddress(){return this.contractManger.getContractInfoByEnv().usdcAddress}};var Ue=class{constructor(n,s,o,l){this.configStore=n;this.keyStore=s;this.contractManger=o;this.getWalletAdapter=l;this._ee=new qn;this._state={status:W.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.assetsManager=new ke(n,o,this),this._bindEvents()}logout(){}async setAddress(n,s){if(!n)throw new Error("address is required");this.keyStore.setAddress(n);let o={...this.stateValue,status:W.Connected,address:n,connectWallet:s?.wallet};return this._ee.emit("change:status",o),s&&(this.walletClient=this.getWalletAdapter({...s,address:n})),await this._checkAccount(n)}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get accountIdHashStr(){if(!this.address)throw new Error("address is error");let n=this.configStore.get("brokerId");return Ge(this.address,n)}get address(){return this.stateValue.address}get chainId(){return this.walletClient?.chainId}set position(n){let s={...this.stateValue,positon:n};this._ee.emit("change:status",s)}set orders(n){let s={...this.stateValue,orders:n};this._ee.emit("change:status",s)}_bindEvents(){this._ee.addListener("change:status",n=>{this._state=n})}async _checkAccount(n){let s;try{let o=await this._checkAccountExist(n);if(o&&o.account_id)this.keyStore.setAccountId(n,o.account_id),s={...this.stateValue,status:W.SignedIn,accountId:o.account_id,userId:o.user_id},this._ee.emit("change:status",s);else return s={...this.stateValue,status:W.NotSignedIn},this._ee.emit("change:status",s),W.NotSignedIn;let l=this.keyStore.getOrderlyKey();if(s={...this.stateValue,status:W.DisabledTrading},!l)return this._ee.emit("change:status",s),W.DisabledTrading;let p=await l.getPublicKey(),a=await this._checkOrderlyKeyState(o.account_id,p);if(a&&a.orderly_key&&a.key_status==="ACTIVE"){let g=Date.now(),m=a.expiration;if(g>m)return this.keyStore.cleanKey(n,"orderlyKey"),W.DisabledTrading;let I={...this.stateValue,status:W.EnableTrading};return this._ee.emit("change:status",I),W.EnableTrading}return this.keyStore.cleanKey(n,"orderlyKey"),W.NotConnected}catch{}return W.NotSignedIn}async _checkAccountExist(n){let s=this.configStore.get("brokerId"),o=await this._simpleFetch(`/v1/get_account?address=${n}&broker_id=${s}`);return o.success?o.data:null}async createAccount(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getRegisterationNonce(),s=this.stateValue.address;if(!s)throw new Error("address is undefined");let[o,l]=$t({registrationNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId")}),p=await this.signTypedData(l),a=await this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:p,message:o,userAddress:s}),headers:{"Content-Type":"application/json"}});if(a.success){this.keyStore.setAccountId(s,a.data.account_id);let g={...this.stateValue,status:W.DisabledTrading,accountId:a.data.account_id,userId:a.data.user_id};return this._ee.emit("change:status",g),a}}async signTypedData(n){return this.walletClient?await this.walletClient.signTypedData(this.stateValue.address,JSON.stringify(n)):Promise.reject("walletClient is undefined")}async createOrderlyKey(n){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(!this.walletClient)throw new Error("walletClient is undefined");let s="AddOrderlyKey",o=this.keyStore.generateKey(),l=await o.getPublicKey(),[p,a]=Ht({publicKey:l,chainId:this.walletClient.chainId,primaryType:s,expiration:n,brokerId:this.configStore.get("brokerId")}),g=this.stateValue.address;if(!g)throw new Error("address is undefined");let m=await this.signTypedData(a),I=await this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:m,message:p,userAddress:g}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(I.success){this.keyStore.setKey(g,o);let f={...this.stateValue,status:W.EnableTrading};return this._ee.emit("change:status",f),I}else throw new Error(I.message)}async settle(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getSettleNonce(),s=this.stateValue.address,o=this.getDomain(!0),l="/v1/settle_pnl",[p,a]=jt({settlePnlNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId"),domain:o}),m={signature:await this.signTypedData(a),message:p,userAddress:s,verifyingContract:o.verifyingContract},I={method:"POST",url:l,data:m},f=await this.signer.sign(I),A=await this._simpleFetch(l,{method:"POST",body:JSON.stringify(m),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,...f}});if(A.success)return A;throw new Error(A.message)}async disconnect(){let n={...this.stateValue,status:W.NotConnected,accountId:void 0,userId:void 0,address:void 0};this._ee.emit("change:status",n)}async _checkOrderlyKeyState(n,s){let o=await this._simpleFetch(`/v1/get_orderly_key?account_id=${n}&orderly_key=${s}`);if(o.success)return o.data;throw new Error(o.message)}get signer(){return this._singer||(this._singer=new ee(this.keyStore)),this._singer}get wallet(){return this.walletClient}async _getRegisterationNonce(){let n=await this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(n.success)return n.data?.registration_nonce;throw new Error(n.message)}async _getSettleNonce(){let n=Date.now().toString(),o=[n,"GET","/v1/settle_nonce"].join(""),l=this.signer,{publicKey:p,signature:a}=await l.signText(o),g=await this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.settle_nonce;throw new Error(g.message)}async _simpleFetch(n,s={}){let o=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(o,s).then(l=>l.json())}getDomain(n){if(!this.walletClient)throw new Error("walletClient is undefined");return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:n?this.contractManger.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}get on(){return this._ee.on.bind(this._ee)}get once(){return this._ee.once.bind(this._ee)}get off(){return this._ee.off.bind(this._ee)}};Ue.instanceName="account";E();T();v();E();T();v();import{BrowserProvider as zn,ethers as de,toNumber as Gn}from"ethers";import{getParsedEthersError as Gt}from"@enzoferey/ethers-error-parser";var tt=class{constructor(n){this._chainId=parseInt(n.chain.id,16),this.provider=new zn(n.provider,"any"),this._address=n.address}parseUnits(n){return de.parseUnits(n,6).toString()}formatUnits(n){return de.formatUnits(n,6)}getBalance(n){return this.provider.getBalance(n).then(s=>s,s=>{})}deposit(n,s,o){throw new Error("Method not implemented.")}async call(n,s,o,l){let p=await this.provider?.getSigner();return new de.Contract(n,l.abi,p)[s].apply(null,o).catch(g=>{throw Gt(g)})}get chainId(){return this._chainId}get addresses(){return this._address}async send(n,s){return await this.provider?.send(n,s)}async sendTransaction(n,s,o,l){let p=await this.provider?.getSigner();if(!p)throw new Error("singer is not exist");let g=new de.Contract(n,l.abi,this.provider).interface.encodeFunctionData(s,o.data),m={from:o.from,to:o.to,data:g,value:o.value};try{return await p.sendTransaction(m)}catch(I){throw Gt(I)}}async estimateGas(n){let s=await this.provider.estimateGas(n);return Gn(s)}async signTypedData(n,s){return await this.provider?.send("eth_signTypedData_v4",[n,s])}async verify(n,s){let{domain:o,types:l,message:p}=n,a=de.verifyTypedData(o,l,p,s)}on(n,s){this.provider?.on(n,s)}off(n,s){this.provider?.off(n,s)}getContract(n,s){return new de.Contract(n,s,this.provider)}};export{Ue as Account,Rt as BaseConfigStore,Je as BaseContractManager,xe as BaseKeyStore,Q as BaseOrderlyKeyPair,ee as BaseSigner,tt as EtherAdapter,ps as EventEmitter,me as LocalStorageStore,_e as MemoryConfigStore,we as MockKeyStore,Wn as SimpleDI,Ln as getDefaultSigner,Vn as getMockSigner,Ot as utils};
1
+ var pn=Object.create;var Ne=Object.defineProperty;var yn=Object.getOwnPropertyDescriptor;var hn=Object.getOwnPropertyNames;var gn=Object.getPrototypeOf,fn=Object.prototype.hasOwnProperty;var ye=(c,n)=>()=>(c&&(n=c(c=0)),n);var pt=(c,n)=>()=>(n||c((n={exports:{}}).exports,n),n.exports),mn=(c,n)=>{for(var s in n)Ne(c,s,{get:n[s],enumerable:!0})},wn=(c,n,s,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let l of hn(n))!fn.call(c,l)&&l!==s&&Ne(c,l,{get:()=>n[l],enumerable:!(o=yn(n,l))||o.enumerable});return c};var bn=(c,n,s)=>(s=c!=null?pn(gn(c)):{},wn(n||!c||!c.__esModule?Ne(s,"default",{value:c,enumerable:!0}):s,c));var E=ye(()=>{"use strict"});function An(c,n){this.fun=c,this.array=n}function yt(c){var n=Math.floor((Date.now()-te.now())*.001),s=te.now()*.001,o=Math.floor(s)+n,l=Math.floor(s%1*1e9);return c&&(o=o-c[0],l=l-c[1],l<0&&(o--,l+=Re)),[o,l]}var Zn,te,Oe,Re,ht=ye(()=>{"use strict";E();T();v();An.prototype.run=function(){this.fun.apply(null,this.array)};Zn={PATH:"/usr/bin",LANG:navigator.language+".UTF-8",PWD:"/",HOME:"/home",TMP:"/tmp"},te={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0};te.now===void 0&&(Oe=Date.now(),te.timing&&te.timing.navigationStart&&(Oe=te.timing.navigationStart),te.now=()=>Date.now()-Oe);Re=1e9;yt.bigint=function(c){var n=yt(c);return typeof BigInt>"u"?n[0]*Re+n[1]:BigInt(n[0]*Re)+BigInt(n[1])}});var v=ye(()=>{"use strict";ht()});function In(){if(gt)return he;gt=!0,he.byteLength=g,he.toByteArray=I,he.fromByteArray=_;for(var c=[],n=[],s=typeof Uint8Array<"u"?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,p=o.length;l<p;++l)c[l]=o[l],n[o.charCodeAt(l)]=l;n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63;function a(h){var w=h.length;if(w%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var B=h.indexOf("=");B===-1&&(B=w);var x=B===w?0:4-B%4;return[B,x]}function g(h){var w=a(h),B=w[0],x=w[1];return(B+x)*3/4-x}function m(h,w,B){return(w+B)*3/4-B}function I(h){var w,B=a(h),x=B[0],k=B[1],C=new s(m(h,x,k)),U=0,M=k>0?x-4:x,K;for(K=0;K<M;K+=4)w=n[h.charCodeAt(K)]<<18|n[h.charCodeAt(K+1)]<<12|n[h.charCodeAt(K+2)]<<6|n[h.charCodeAt(K+3)],C[U++]=w>>16&255,C[U++]=w>>8&255,C[U++]=w&255;return k===2&&(w=n[h.charCodeAt(K)]<<2|n[h.charCodeAt(K+1)]>>4,C[U++]=w&255),k===1&&(w=n[h.charCodeAt(K)]<<10|n[h.charCodeAt(K+1)]<<4|n[h.charCodeAt(K+2)]>>2,C[U++]=w>>8&255,C[U++]=w&255),C}function f(h){return c[h>>18&63]+c[h>>12&63]+c[h>>6&63]+c[h&63]}function A(h,w,B){for(var x,k=[],C=w;C<B;C+=3)x=(h[C]<<16&16711680)+(h[C+1]<<8&65280)+(h[C+2]&255),k.push(f(x));return k.join("")}function _(h){for(var w,B=h.length,x=B%3,k=[],C=16383,U=0,M=B-x;U<M;U+=C)k.push(A(h,U,U+C>M?M:U+C));return x===1?(w=h[B-1],k.push(c[w>>2]+c[w<<4&63]+"==")):x===2&&(w=(h[B-2]<<8)+h[B-1],k.push(c[w>>10]+c[w>>4&63]+c[w<<2&63]+"=")),k.join("")}return he}function En(){if(ft)return Ae;ft=!0;return Ae.read=function(c,n,s,o,l){var p,a,g=l*8-o-1,m=(1<<g)-1,I=m>>1,f=-7,A=s?l-1:0,_=s?-1:1,h=c[n+A];for(A+=_,p=h&(1<<-f)-1,h>>=-f,f+=g;f>0;p=p*256+c[n+A],A+=_,f-=8);for(a=p&(1<<-f)-1,p>>=-f,f+=o;f>0;a=a*256+c[n+A],A+=_,f-=8);if(p===0)p=1-I;else{if(p===m)return a?NaN:(h?-1:1)*(1/0);a=a+Math.pow(2,o),p=p-I}return(h?-1:1)*a*Math.pow(2,p-o)},Ae.write=function(c,n,s,o,l,p){var a,g,m,I=p*8-l-1,f=(1<<I)-1,A=f>>1,_=l===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=o?0:p-1,w=o?1:-1,B=n<0||n===0&&1/n<0?1:0;for(n=Math.abs(n),isNaN(n)||n===1/0?(g=isNaN(n)?1:0,a=f):(a=Math.floor(Math.log(n)/Math.LN2),n*(m=Math.pow(2,-a))<1&&(a--,m*=2),a+A>=1?n+=_/m:n+=_*Math.pow(2,1-A),n*m>=2&&(a++,m/=2),a+A>=f?(g=0,a=f):a+A>=1?(g=(n*m-1)*Math.pow(2,l),a=a+A):(g=n*Math.pow(2,A-1)*Math.pow(2,l),a=0));l>=8;c[s+h]=g&255,h+=w,g/=256,l-=8);for(a=a<<l|g,I+=l;I>0;c[s+h]=a&255,h+=w,a/=256,I-=8);c[s+h-w]|=B*128},Ae}function vn(){if(mt)return ne;mt=!0;let c=In(),n=En(),s=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ne.Buffer=a,ne.SlowBuffer=k,ne.INSPECT_MAX_BYTES=50;let o=2147483647;ne.kMaxLength=o,a.TYPED_ARRAY_SUPPORT=l(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&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 l(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{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 p(r){if(r>o)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,a.prototype),e}function a(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return f(r)}return g(r,e,t)}a.poolSize=8192;function g(r,e,t){if(typeof r=="string")return A(r,e);if(ArrayBuffer.isView(r))return h(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(G(r,ArrayBuffer)||r&&G(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(G(r,SharedArrayBuffer)||r&&G(r.buffer,SharedArrayBuffer)))return w(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=r.valueOf&&r.valueOf();if(i!=null&&i!==r)return a.from(i,e,t);let u=B(r);if(u)return u;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return a.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}a.from=function(r,e,t){return g(r,e,t)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function m(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function I(r,e,t){return m(r),r<=0?p(r):e!==void 0?typeof t=="string"?p(r).fill(e,t):p(r).fill(e):p(r)}a.alloc=function(r,e,t){return I(r,e,t)};function f(r){return m(r),p(r<0?0:x(r)|0)}a.allocUnsafe=function(r){return f(r)},a.allocUnsafeSlow=function(r){return f(r)};function A(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!a.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=C(r,e)|0,i=p(t),u=i.write(r,e);return u!==t&&(i=i.slice(0,u)),i}function _(r){let e=r.length<0?0:x(r.length)|0,t=p(e);for(let i=0;i<e;i+=1)t[i]=r[i]&255;return t}function h(r){if(G(r,Uint8Array)){let e=new Uint8Array(r);return w(e.buffer,e.byteOffset,e.byteLength)}return _(r)}function w(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let i;return e===void 0&&t===void 0?i=new Uint8Array(r):t===void 0?i=new Uint8Array(r,e):i=new Uint8Array(r,e,t),Object.setPrototypeOf(i,a.prototype),i}function B(r){if(a.isBuffer(r)){let e=x(r.length)|0,t=p(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Ke(r.length)?p(0):_(r);if(r.type==="Buffer"&&Array.isArray(r.data))return _(r.data)}function x(r){if(r>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return r|0}function k(r){return+r!=r&&(r=0),a.alloc(+r)}a.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==a.prototype},a.compare=function(e,t){if(G(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),G(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(e)||!a.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,u=t.length;for(let d=0,y=Math.min(i,u);d<y;++d)if(e[d]!==t[d]){i=e[d],u=t[d];break}return i<u?-1:u<i?1:0},a.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}},a.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return a.alloc(0);let i;if(t===void 0)for(t=0,i=0;i<e.length;++i)t+=e[i].length;let u=a.allocUnsafe(t),d=0;for(i=0;i<e.length;++i){let y=e[i];if(G(y,Uint8Array))d+y.length>u.length?(a.isBuffer(y)||(y=a.from(y)),y.copy(u,d)):Uint8Array.prototype.set.call(u,y,d);else if(a.isBuffer(y))y.copy(u,d);else throw new TypeError('"list" argument must be an Array of Buffers');d+=y.length}return u};function C(r,e){if(a.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||G(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&t===0)return 0;let u=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Me(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return dt(r).length;default:if(u)return i?-1:Me(r).length;e=(""+e).toLowerCase(),u=!0}}a.byteLength=C;function U(r,e,t){let i=!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(r||(r="utf8");;)switch(r){case"hex":return nn(this,e,t);case"utf8":case"utf-8":return nt(this,e,t);case"ascii":return en(this,e,t);case"latin1":case"binary":return tn(this,e,t);case"base64":return Jt(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return rn(this,e,t);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),i=!0}}a.prototype._isBuffer=!0;function M(r,e,t){let i=r[e];r[e]=r[t],r[t]=i}a.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)M(this,t,t+1);return this},a.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)M(this,t,t+3),M(this,t+1,t+2);return this},a.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)M(this,t,t+7),M(this,t+1,t+6),M(this,t+2,t+5),M(this,t+3,t+4);return this},a.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?nt(this,0,e):U.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(e){if(!a.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:a.compare(this,e)===0},a.prototype.inspect=function(){let e="",t=ne.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},s&&(a.prototype[s]=a.prototype.inspect),a.prototype.compare=function(e,t,i,u,d){if(G(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),i===void 0&&(i=e?e.length:0),u===void 0&&(u=0),d===void 0&&(d=this.length),t<0||i>e.length||u<0||d>this.length)throw new RangeError("out of range index");if(u>=d&&t>=i)return 0;if(u>=d)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,u>>>=0,d>>>=0,this===e)return 0;let y=d-u,S=i-t,R=Math.min(y,S),N=this.slice(u,d),D=e.slice(t,i);for(let P=0;P<R;++P)if(N[P]!==D[P]){y=N[P],S=D[P];break}return y<S?-1:S<y?1:0};function K(r,e,t,i,u){if(r.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Ke(t)&&(t=u?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(u)return-1;t=r.length-1}else if(t<0)if(u)t=0;else return-1;if(typeof e=="string"&&(e=a.from(e,i)),a.isBuffer(e))return e.length===0?-1:H(r,e,t,i,u);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?u?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):H(r,[e],t,i,u);throw new TypeError("val must be string, number or Buffer")}function H(r,e,t,i,u){let d=1,y=r.length,S=e.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(r.length<2||e.length<2)return-1;d=2,y/=2,S/=2,t/=2}function R(D,P){return d===1?D[P]:D.readUInt16BE(P*d)}let N;if(u){let D=-1;for(N=t;N<y;N++)if(R(r,N)===R(e,D===-1?0:N-D)){if(D===-1&&(D=N),N-D+1===S)return D*d}else D!==-1&&(N-=N-D),D=-1}else for(t+S>y&&(t=y-S),N=t;N>=0;N--){let D=!0;for(let P=0;P<S;P++)if(R(r,N+P)!==R(e,P)){D=!1;break}if(D)return N}return-1}a.prototype.includes=function(e,t,i){return this.indexOf(e,t,i)!==-1},a.prototype.indexOf=function(e,t,i){return K(this,e,t,i,!0)},a.prototype.lastIndexOf=function(e,t,i){return K(this,e,t,i,!1)};function z(r,e,t,i){t=Number(t)||0;let u=r.length-t;i?(i=Number(i),i>u&&(i=u)):i=u;let d=e.length;i>d/2&&(i=d/2);let y;for(y=0;y<i;++y){let S=parseInt(e.substr(y*2,2),16);if(Ke(S))return y;r[t+y]=S}return y}function ae(r,e,t,i){return be(Me(e,r.length-t),r,t,i)}function Yt(r,e,t,i){return be(cn(e),r,t,i)}function Xt(r,e,t,i){return be(dt(e),r,t,i)}function Zt(r,e,t,i){return be(un(e,r.length-t),r,t,i)}a.prototype.write=function(e,t,i,u){if(t===void 0)u="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")u=t,i=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(i)?(i=i>>>0,u===void 0&&(u="utf8")):(u=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let d=this.length-t;if((i===void 0||i>d)&&(i=d),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");u||(u="utf8");let y=!1;for(;;)switch(u){case"hex":return z(this,e,t,i);case"utf8":case"utf-8":return ae(this,e,t,i);case"ascii":case"latin1":case"binary":return Yt(this,e,t,i);case"base64":return Xt(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Zt(this,e,t,i);default:if(y)throw new TypeError("Unknown encoding: "+u);u=(""+u).toLowerCase(),y=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Jt(r,e,t){return e===0&&t===r.length?c.fromByteArray(r):c.fromByteArray(r.slice(e,t))}function nt(r,e,t){t=Math.min(r.length,t);let i=[],u=e;for(;u<t;){let d=r[u],y=null,S=d>239?4:d>223?3:d>191?2:1;if(u+S<=t){let R,N,D,P;switch(S){case 1:d<128&&(y=d);break;case 2:R=r[u+1],(R&192)===128&&(P=(d&31)<<6|R&63,P>127&&(y=P));break;case 3:R=r[u+1],N=r[u+2],(R&192)===128&&(N&192)===128&&(P=(d&15)<<12|(R&63)<<6|N&63,P>2047&&(P<55296||P>57343)&&(y=P));break;case 4:R=r[u+1],N=r[u+2],D=r[u+3],(R&192)===128&&(N&192)===128&&(D&192)===128&&(P=(d&15)<<18|(R&63)<<12|(N&63)<<6|D&63,P>65535&&P<1114112&&(y=P))}}y===null?(y=65533,S=1):y>65535&&(y-=65536,i.push(y>>>10&1023|55296),y=56320|y&1023),i.push(y),u+=S}return Qt(i)}let rt=4096;function Qt(r){let e=r.length;if(e<=rt)return String.fromCharCode.apply(String,r);let t="",i=0;for(;i<e;)t+=String.fromCharCode.apply(String,r.slice(i,i+=rt));return t}function en(r,e,t){let i="";t=Math.min(r.length,t);for(let u=e;u<t;++u)i+=String.fromCharCode(r[u]&127);return i}function tn(r,e,t){let i="";t=Math.min(r.length,t);for(let u=e;u<t;++u)i+=String.fromCharCode(r[u]);return i}function nn(r,e,t){let i=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>i)&&(t=i);let u="";for(let d=e;d<t;++d)u+=ln[r[d]];return u}function rn(r,e,t){let i=r.slice(e,t),u="";for(let d=0;d<i.length-1;d+=2)u+=String.fromCharCode(i[d]+i[d+1]*256);return u}a.prototype.slice=function(e,t){let i=this.length;e=~~e,t=t===void 0?i:~~t,e<0?(e+=i,e<0&&(e=0)):e>i&&(e=i),t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),t<e&&(t=e);let u=this.subarray(e,t);return Object.setPrototypeOf(u,a.prototype),u};function L(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||L(e,t,this.length);let u=this[e],d=1,y=0;for(;++y<t&&(d*=256);)u+=this[e+y]*d;return u},a.prototype.readUintBE=a.prototype.readUIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||L(e,t,this.length);let u=this[e+--t],d=1;for(;t>0&&(d*=256);)u+=this[e+--t]*d;return u},a.prototype.readUint8=a.prototype.readUInt8=function(e,t){return e=e>>>0,t||L(e,1,this.length),this[e]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||L(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||L(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||L(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||L(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readBigUInt64LE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&pe(e,this.length-8);let u=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,d=this[++e]+this[++e]*2**8+this[++e]*2**16+i*2**24;return BigInt(u)+(BigInt(d)<<BigInt(32))}),a.prototype.readBigUInt64BE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&pe(e,this.length-8);let u=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],d=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i;return(BigInt(u)<<BigInt(32))+BigInt(d)}),a.prototype.readIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||L(e,t,this.length);let u=this[e],d=1,y=0;for(;++y<t&&(d*=256);)u+=this[e+y]*d;return d*=128,u>=d&&(u-=Math.pow(2,8*t)),u},a.prototype.readIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||L(e,t,this.length);let u=t,d=1,y=this[e+--u];for(;u>0&&(d*=256);)y+=this[e+--u]*d;return d*=128,y>=d&&(y-=Math.pow(2,8*t)),y},a.prototype.readInt8=function(e,t){return e=e>>>0,t||L(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},a.prototype.readInt16LE=function(e,t){e=e>>>0,t||L(e,2,this.length);let i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i},a.prototype.readInt16BE=function(e,t){e=e>>>0,t||L(e,2,this.length);let i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i},a.prototype.readInt32LE=function(e,t){return e=e>>>0,t||L(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e=e>>>0,t||L(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readBigInt64LE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&pe(e,this.length-8);let u=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(i<<24);return(BigInt(u)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),a.prototype.readBigInt64BE=Z(function(e){e=e>>>0,ce(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&pe(e,this.length-8);let u=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(u)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i)}),a.prototype.readFloatLE=function(e,t){return e=e>>>0,t||L(e,4,this.length),n.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e=e>>>0,t||L(e,4,this.length),n.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||L(e,8,this.length),n.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||L(e,8,this.length),n.read(this,e,!1,52,8)};function q(r,e,t,i,u,d){if(!a.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>u||e<d)throw new RangeError('"value" argument is out of bounds');if(t+i>r.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(e,t,i,u){if(e=+e,t=t>>>0,i=i>>>0,!u){let S=Math.pow(2,8*i)-1;q(this,e,t,i,S,0)}let d=1,y=0;for(this[t]=e&255;++y<i&&(d*=256);)this[t+y]=e/d&255;return t+i},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(e,t,i,u){if(e=+e,t=t>>>0,i=i>>>0,!u){let S=Math.pow(2,8*i)-1;q(this,e,t,i,S,0)}let d=i-1,y=1;for(this[t+d]=e&255;--d>=0&&(y*=256);)this[t+d]=e/y&255;return t+i},a.prototype.writeUint8=a.prototype.writeUInt8=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,1,255,0),this[t]=e&255,t+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function it(r,e,t,i,u){lt(e,i,u,r,t,7);let d=Number(e&BigInt(4294967295));r[t++]=d,d=d>>8,r[t++]=d,d=d>>8,r[t++]=d,d=d>>8,r[t++]=d;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,t}function st(r,e,t,i,u){lt(e,i,u,r,t,7);let d=Number(e&BigInt(4294967295));r[t+7]=d,d=d>>8,r[t+6]=d,d=d>>8,r[t+5]=d,d=d>>8,r[t+4]=d;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=y,y=y>>8,r[t+2]=y,y=y>>8,r[t+1]=y,y=y>>8,r[t]=y,t+8}a.prototype.writeBigUInt64LE=Z(function(e,t=0){return it(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Z(function(e,t=0){return st(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(e,t,i,u){if(e=+e,t=t>>>0,!u){let R=Math.pow(2,8*i-1);q(this,e,t,i,R-1,-R)}let d=0,y=1,S=0;for(this[t]=e&255;++d<i&&(y*=256);)e<0&&S===0&&this[t+d-1]!==0&&(S=1),this[t+d]=(e/y>>0)-S&255;return t+i},a.prototype.writeIntBE=function(e,t,i,u){if(e=+e,t=t>>>0,!u){let R=Math.pow(2,8*i-1);q(this,e,t,i,R-1,-R)}let d=i-1,y=1,S=0;for(this[t+d]=e&255;--d>=0&&(y*=256);)e<0&&S===0&&this[t+d+1]!==0&&(S=1),this[t+d]=(e/y>>0)-S&255;return t+i},a.prototype.writeInt8=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},a.prototype.writeInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},a.prototype.writeInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||q(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},a.prototype.writeBigInt64LE=Z(function(e,t=0){return it(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Z(function(e,t=0){return st(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function at(r,e,t,i,u,d){if(t+i>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function ot(r,e,t,i,u){return e=+e,t=t>>>0,u||at(r,e,t,4),n.write(r,e,t,i,23,4),t+4}a.prototype.writeFloatLE=function(e,t,i){return ot(this,e,t,!0,i)},a.prototype.writeFloatBE=function(e,t,i){return ot(this,e,t,!1,i)};function ct(r,e,t,i,u){return e=+e,t=t>>>0,u||at(r,e,t,8),n.write(r,e,t,i,52,8),t+8}a.prototype.writeDoubleLE=function(e,t,i){return ct(this,e,t,!0,i)},a.prototype.writeDoubleBE=function(e,t,i){return ct(this,e,t,!1,i)},a.prototype.copy=function(e,t,i,u){if(!a.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),!u&&u!==0&&(u=this.length),t>=e.length&&(t=e.length),t||(t=0),u>0&&u<i&&(u=i),u===i||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("sourceEnd out of bounds");u>this.length&&(u=this.length),e.length-t<u-i&&(u=e.length-t+i);let d=u-i;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,i,u):Uint8Array.prototype.set.call(e,this.subarray(i,u),t),d},a.prototype.fill=function(e,t,i,u){if(typeof e=="string"){if(typeof t=="string"?(u=t,t=0,i=this.length):typeof i=="string"&&(u=i,i=this.length),u!==void 0&&typeof u!="string")throw new TypeError("encoding must be a string");if(typeof u=="string"&&!a.isEncoding(u))throw new TypeError("Unknown encoding: "+u);if(e.length===1){let y=e.charCodeAt(0);(u==="utf8"&&y<128||u==="latin1")&&(e=y)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;t=t>>>0,i=i===void 0?this.length:i>>>0,e||(e=0);let d;if(typeof e=="number")for(d=t;d<i;++d)this[d]=e;else{let y=a.isBuffer(e)?e:a.from(e,u),S=y.length;if(S===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(d=0;d<i-t;++d)this[d+t]=y[d%S]}return this};let oe={};function Pe(r,e,t){oe[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(u){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:u,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Pe("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Pe("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),Pe("ERR_OUT_OF_RANGE",function(r,e,t){let i=`The value of "${r}" is out of range.`,u=t;return Number.isInteger(t)&&Math.abs(t)>2**32?u=ut(String(t)):typeof t=="bigint"&&(u=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(u=ut(u)),u+="n"),i+=` It must be ${e}. Received ${u}`,i},RangeError);function ut(r){let e="",t=r.length,i=r[0]==="-"?1:0;for(;t>=i+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function sn(r,e,t){ce(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&pe(e,r.length-(t+1))}function lt(r,e,t,i,u,d){if(r>t||r<e){let y=typeof e=="bigint"?"n":"",S;throw d>3?e===0||e===BigInt(0)?S=`>= 0${y} and < 2${y} ** ${(d+1)*8}${y}`:S=`>= -(2${y} ** ${(d+1)*8-1}${y}) and < 2 ** ${(d+1)*8-1}${y}`:S=`>= ${e}${y} and <= ${t}${y}`,new oe.ERR_OUT_OF_RANGE("value",S,r)}sn(i,u,d)}function ce(r,e){if(typeof r!="number")throw new oe.ERR_INVALID_ARG_TYPE(e,"number",r)}function pe(r,e,t){throw Math.floor(r)!==r?(ce(r,t),new oe.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new oe.ERR_BUFFER_OUT_OF_BOUNDS:new oe.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let an=/[^+/0-9A-Za-z-_]/g;function on(r){if(r=r.split("=")[0],r=r.trim().replace(an,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Me(r,e){e=e||1/0;let t,i=r.length,u=null,d=[];for(let y=0;y<i;++y){if(t=r.charCodeAt(y),t>55295&&t<57344){if(!u){if(t>56319){(e-=3)>-1&&d.push(239,191,189);continue}else if(y+1===i){(e-=3)>-1&&d.push(239,191,189);continue}u=t;continue}if(t<56320){(e-=3)>-1&&d.push(239,191,189),u=t;continue}t=(u-55296<<10|t-56320)+65536}else u&&(e-=3)>-1&&d.push(239,191,189);if(u=null,t<128){if((e-=1)<0)break;d.push(t)}else if(t<2048){if((e-=2)<0)break;d.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;d.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;d.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return d}function cn(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function un(r,e){let t,i,u,d=[];for(let y=0;y<r.length&&!((e-=2)<0);++y)t=r.charCodeAt(y),i=t>>8,u=t%256,d.push(u),d.push(i);return d}function dt(r){return c.toByteArray(on(r))}function be(r,e,t,i){let u;for(u=0;u<i&&!(u+t>=e.length||u>=r.length);++u)e[u+t]=r[u];return u}function G(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Ke(r){return r!==r}let ln=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let i=t*16;for(let u=0;u<16;++u)e[i+u]=r[t]+r[u]}return e}();function Z(r){return typeof BigInt>"u"?dn:r}function dn(){throw new Error("BigInt not supported")}return ne}var he,gt,Ae,ft,ne,mt,re,O,rr,ir,De=ye(()=>{"use strict";E();T();v();he={},gt=!1;Ae={},ft=!1;ne={},mt=!1;re=vn();re.Buffer;re.SlowBuffer;re.INSPECT_MAX_BYTES;re.kMaxLength;O=re.Buffer,rr=re.INSPECT_MAX_BYTES,ir=re.kMaxLength});var T=ye(()=>{"use strict";De()});var bt=pt((dr,wt)=>{"use strict";E();T();v();function Tn(c){if(c.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var o=0;o<c.length;o++){var l=c.charAt(o),p=l.charCodeAt(0);if(n[p]!==255)throw new TypeError(l+" is ambiguous");n[p]=o}var a=c.length,g=c.charAt(0),m=Math.log(a)/Math.log(256),I=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var w=0,B=0,x=0,k=h.length;x!==k&&h[x]===0;)x++,w++;for(var C=(k-x)*I+1>>>0,U=new Uint8Array(C);x!==k;){for(var M=h[x],K=0,H=C-1;(M!==0||K<B)&&H!==-1;H--,K++)M+=256*U[H]>>>0,U[H]=M%a>>>0,M=M/a>>>0;if(M!==0)throw new Error("Non-zero carry");B=K,x++}for(var z=C-B;z!==C&&U[z]===0;)z++;for(var ae=g.repeat(w);z<C;++z)ae+=c.charAt(U[z]);return ae}function A(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var w=0,B=0,x=0;h[w]===g;)B++,w++;for(var k=(h.length-w)*m+1>>>0,C=new Uint8Array(k);h[w];){var U=n[h.charCodeAt(w)];if(U===255)return;for(var M=0,K=k-1;(U!==0||M<x)&&K!==-1;K--,M++)U+=a*C[K]>>>0,C[K]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");x=M,w++}for(var H=k-x;H!==k&&C[H]===0;)H++;for(var z=new Uint8Array(B+(k-H)),ae=B;H!==k;)z[ae++]=C[H++];return z}function _(h){var w=A(h);if(w)return w;throw new Error("Non-base"+a+" character")}return{encode:f,decodeUnsafe:A,decode:_}}wt.exports=Tn});var It=pt((gr,At)=>{"use strict";E();T();v();var Bn=bt(),xn="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";At.exports=Bn(xn)});E();T();v();E();T();v();E();T();v();var fe=bn(It());E();T();v();var $=2n**255n-19n,ue=2n**252n+27742317777372353535851937790883648493n,Fe=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,Ve=0x6666666666666666666666666666666666666666666666666666666666666658n,Ie={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:$,n:ue,h:8,Gx:Fe,Gy:Ve},j=(c="")=>{throw new Error(c)},xt=c=>typeof c=="string",Te=(c,n)=>!(c instanceof Uint8Array)||typeof n=="number"&&n>0&&c.length!==n?j("Uint8Array expected"):c,le=c=>new Uint8Array(c),Be=(c,n)=>Te(xt(c)?He(c):le(c),n),b=(c,n=$)=>{let s=c%n;return s>=0n?s:n+s},Et=c=>c instanceof J?c:j("Point expected"),vt,J=class c{constructor(n,s,o,l){this.ex=n,this.ey=s,this.ez=o,this.et=l}static fromAffine(n){return new c(n.x,n.y,1n,b(n.x*n.y))}static fromHex(n,s=!0){let{d:o}=Ie;n=Be(n,32);let l=n.slice();l[31]=n[31]&-129;let p=_t(l);p===0n||(s&&!(0n<p&&p<$)&&j("bad y coord 1"),!s&&!(0n<p&&p<2n**256n)&&j("bad y coord 2"));let a=b(p*p),g=b(a-1n),m=b(o*a+1n),{isValid:I,value:f}=Cn(g,m);I||j("bad y coordinate 3");let A=(f&1n)===1n;return(n[31]&128)!==0!==A&&(f=b(-f)),new c(f,p,1n,b(f*p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(n){let{ex:s,ey:o,ez:l}=this,{ex:p,ey:a,ez:g}=Et(n),m=b(s*g),I=b(p*l),f=b(o*g),A=b(a*l);return m===I&&f===A}is0(){return this.equals(Ee)}negate(){return new c(b(-this.ex),this.ey,this.ez,b(-this.et))}double(){let{ex:n,ey:s,ez:o}=this,{a:l}=Ie,p=b(n*n),a=b(s*s),g=b(2n*b(o*o)),m=b(l*p),I=n+s,f=b(b(I*I)-p-a),A=m+a,_=A-g,h=m-a,w=b(f*_),B=b(A*h),x=b(f*h),k=b(_*A);return new c(w,B,k,x)}add(n){let{ex:s,ey:o,ez:l,et:p}=this,{ex:a,ey:g,ez:m,et:I}=Et(n),{a:f,d:A}=Ie,_=b(s*a),h=b(o*g),w=b(p*A*I),B=b(l*m),x=b((s+o)*(a+g)-_-h),k=b(B-w),C=b(B+w),U=b(h-f*_),M=b(x*k),K=b(C*U),H=b(x*U),z=b(k*C);return new c(M,K,z,H)}mul(n,s=!0){if(n===0n)return s===!0?j("cannot multiply by 0"):Ee;if(typeof n=="bigint"&&0n<n&&n<ue||j("invalid scalar, must be < L"),!s&&this.is0()||n===1n)return this;if(this.equals(se))return Mn(n).p;let o=Ee,l=se;for(let p=this;n>0n;p=p.double(),n>>=1n)n&1n?o=o.add(p):s&&(l=l.add(p));return o}multiply(n){return this.mul(n)}clearCofactor(){return this.mul(BigInt(Ie.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let n=this.mul(ue/2n,!1).double();return ue%2n&&(n=n.add(this)),n.is0()}toAffine(){let{ex:n,ey:s,ez:o}=this;if(this.is0())return{x:0n,y:0n};let l=kt(o);return b(o*l)!==1n&&j("invalid inverse"),{x:b(n*l),y:b(s*l)}}toRawBytes(){let{x:n,y:s}=this.toAffine(),o=Ct(s);return o[31]|=n&1n?128:0,o}toHex(){return $e(this.toRawBytes())}};J.BASE=new J(Fe,Ve,1n,b(Fe*Ve));J.ZERO=new J(0n,1n,1n,0n);var{BASE:se,ZERO:Ee}=J,St=(c,n)=>c.toString(16).padStart(n,"0"),$e=c=>Array.from(c).map(n=>St(n,2)).join(""),He=c=>{let n=c.length;(!xt(c)||n%2)&&j("hex invalid 1");let s=le(n/2);for(let o=0;o<s.length;o++){let l=o*2,p=c.slice(l,l+2),a=Number.parseInt(p,16);(Number.isNaN(a)||a<0)&&j("hex invalid 2"),s[o]=a}return s},Ct=c=>He(St(c,32*2)).reverse(),_t=c=>BigInt("0x"+$e(le(Te(c)).reverse())),ve=(...c)=>{let n=le(c.reduce((o,l)=>o+Te(l).length,0)),s=0;return c.forEach(o=>{n.set(o,s),s+=o.length}),n},kt=(c,n=$)=>{(c===0n||n<=0n)&&j("no inverse n="+c+" mod="+n);let s=b(c,n),o=n,l=0n,p=1n,a=1n,g=0n;for(;s!==0n;){let m=o/s,I=o%s,f=l-a*m,A=p-g*m;o=s,s=I,l=a,p=g,a=f,g=A}return o===1n?b(l,n):j("no inverse")},Y=(c,n)=>{let s=c;for(;n-- >0n;)s*=s,s%=$;return s},Sn=c=>{let s=c*c%$*c%$,o=Y(s,2n)*s%$,l=Y(o,1n)*c%$,p=Y(l,5n)*l%$,a=Y(p,10n)*p%$,g=Y(a,20n)*a%$,m=Y(g,40n)*g%$,I=Y(m,80n)*m%$,f=Y(I,80n)*m%$,A=Y(f,10n)*p%$;return{pow_p_5_8:Y(A,2n)*c%$,b2:s}},Tt=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Cn=(c,n)=>{let s=b(n*n*n),o=b(s*s*n),l=Sn(c*o).pow_p_5_8,p=b(c*s*l),a=b(n*p*p),g=p,m=b(p*Tt),I=a===c,f=a===b(-c),A=a===b(-c*Tt);return I&&(p=g),(f||A)&&(p=m),(b(p)&1n)===1n&&(p=b(-p)),{isValid:I||f,value:p}},Le=c=>b(_t(c),ue),ge,je=(...c)=>qe.sha512Async(...c),Ut=(...c)=>typeof ge=="function"?ge(...c):j("etc.sha512Sync not set"),Pt=c=>{let n=c.slice(0,32);n[0]&=248,n[31]&=127,n[31]|=64;let s=c.slice(32,64),o=Le(n),l=se.mul(o),p=l.toRawBytes();return{head:n,prefix:s,scalar:o,point:l,pointBytes:p}},We=c=>je(Be(c,32)).then(Pt),_n=c=>Pt(Ut(Be(c,32))),Mt=c=>We(c).then(n=>n.pointBytes);function kn(c,n){return c?je(n.hashable).then(n.finish):n.finish(Ut(n.hashable))}var Un=(c,n,s)=>{let{pointBytes:o,scalar:l}=c,p=Le(n),a=se.mul(p).toRawBytes();return{hashable:ve(a,o,s),finish:I=>{let f=b(p+Le(I)*l,ue);return Te(ve(a,Ct(f)),64)}}},Kt=async(c,n)=>{let s=Be(c),o=await We(n),l=await je(o.prefix,s);return kn(!0,Un(o,l,s))};var Bt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,qe={bytesToHex:$e,hexToBytes:He,concatBytes:ve,mod:b,invert:kt,randomBytes:c=>{let n=Bt();return n||j("crypto.getRandomValues must be defined"),n.getRandomValues(le(c))},sha512Async:async(...c)=>{let n=Bt();n||j("crypto.subtle or etc.sha512Async must be defined");let s=ve(...c);return le(await n.subtle.digest("SHA-512",s.buffer))},sha512Sync:void 0};Object.defineProperties(qe,{sha512Sync:{configurable:!1,get(){return ge},set(c){ge||(ge=c)}}});var Nt={getExtendedPublicKeyAsync:We,getExtendedPublicKey:_n,randomPrivateKey:()=>qe.randomBytes(32),precompute(c=8,n=se){return n.multiply(3n),n}},ie=8,Pn=()=>{let c=[],n=256/ie+1,s=se,o=s;for(let l=0;l<n;l++){o=s,c.push(o);for(let p=1;p<2**(ie-1);p++)o=o.add(s),c.push(o);s=o.double()}return c},Mn=c=>{let n=vt||(vt=Pn()),s=(f,A)=>{let _=A.negate();return f?_:A},o=Ee,l=se,p=1+256/ie,a=2**(ie-1),g=BigInt(2**ie-1),m=2**ie,I=BigInt(ie);for(let f=0;f<p;f++){let A=f*a,_=Number(c&g);c>>=I,_>a&&(_-=m,c+=1n);let h=A,w=A+Math.abs(_)-1,B=f%2!==0,x=_<0;_===0?l=l.add(s(B,n[h])):o=o.add(s(x,n[w]))}return{p:o,f:l}};var Q=class c{static generateKey(){let n,s;do n=Nt.randomPrivateKey(),s=(0,fe.encode)(n);while(s.length!==44);return new c(s)}constructor(n){this.secretKey=n;let s=(0,fe.decode)(n);this.privateKey=O.from(s).toString("hex")}async sign(n){return await Kt(n,this.privateKey)}async getPublicKey(){let n=await Mt(this.privateKey);return`ed25519:${(0,fe.encode)(n)}`}toString(){return this.privateKey}};var xe=class{constructor(n="testnet"){this.networkId=n}get keyPrefix(){return`orderly_${this.networkId}_`}},me=class extends xe{getOrderlyKey(n){let s;if(n)s=this.getItem(n,"orderlyKey");else{let o=this.getAddress();if(!o)return null;s=this.getItem(o,"orderlyKey")}return s?new Q(s):null}getAccountId(n){return this.getItem(n,"accountId")}setAccountId(n,s){this.setItem(n,{accountId:s})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(n){localStorage.setItem(`${this.keyPrefix}address`,n)}generateKey(){return Q.generateKey()}setKey(n,s){this.setItem(n,{orderlyKey:s.secretKey})}cleanAllKey(n){localStorage.removeItem(`${this.keyPrefix}${n}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(n,s){let o=this.getItem(n);delete o[s],localStorage.setItem(`${this.keyPrefix}${n}`,JSON.stringify(o))}setItem(n,s){let o=`${this.keyPrefix}${n}`,l=localStorage.getItem(o);l?l=JSON.parse(l):l={},localStorage.setItem(o,JSON.stringify({...l,...s}))}getItem(n,s){let o=`${this.keyPrefix}${n}`,l=localStorage.getItem(o);return l?l=JSON.parse(l):l={},typeof s>"u"?l:l[s]}},we=class{constructor(n){this.secretKey=n}generateKey(){return new Q(this.secretKey)}getOrderlyKey(){return new Q(this.secretKey)}getAccountId(){return""}setAccountId(n){}getAddress(){return""}setAddress(n){}setKey(n,s){}cleanAllKey(){}cleanKey(n){}};E();T();v();var Ot={};mn(Ot,{base64url:()=>ze,calculateStringHash:()=>Xe,formatByUnits:()=>Ce,parseAccountId:()=>Ge,parseBrokerHash:()=>Se,parseTokenHash:()=>Ye,parseUnits:()=>Fn});E();T();v();import{keccak256 as Nn,AbiCoder as On,solidityPackedKeccak256 as Rn,formatUnits as Dn}from"ethers";import{parseUnits as Fn}from"ethers";var ze=function(c){return c.replace(/\+/g,"-").replace(/\//g,"_")};function Se(c){return Xe(c)}function Ge(c,n){let s=On.defaultAbiCoder();return Nn(s.encode(["address","bytes32"],[c,Se(n)]))}function Ye(c){return Xe(c)}function Xe(c){return Rn(["string"],[c])}function Ce(c,n="ether"){return Dn(c,n)}De();var ee=class{constructor(n){this.keyStore=n}async sign(n){let s=Date.now().toString(),o=[s,n.method.toUpperCase(),n.url].join("");n.data&&Object.keys(n.data).length&&(o+=JSON.stringify(n.data));let{signature:l,publicKey:p}=await this.signText(o);return{"orderly-key":p,"orderly-timestamp":s,"orderly-signature":l}}async signText(n){let s=this.keyStore.getOrderlyKey();if(!s)throw new Error("orderlyKeyPair is not defined");let o=O.from(n),l=await s.sign(o),p=O.from(l).toString("base64");return{signature:ze(p),publicKey:await s.getPublicKey()}}};import{default as ps}from"eventemitter3";E();T();v();E();T();v();var _e=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://api-evm.orderly.org"],["klineDataUrl","https://testnet-api-evm.orderly.org"],["publicWsUrl","wss://testnet-ws-evm.orderly.org"],["privateWsUrl","wss://testnet-ws-private-evm.orderly.org"],["operatorUrl","https://testnet-operator-evm.orderly.org"],["swapSupportApiUrl","https://fi-api.woo.org"],["domain",{testnet:"https://testnet-dex-evm.woo.org",mainnet:"https://dex-evm.woo.org",dexMainnet:"https://dex.woo.org",dexTestnet:"https://testnet-dex.woo.org"}],["brokerId","woofi_pro"],["onlyTestnet",!1],["env","dev-evm"],["PROD_URL",["dex-iap-evm.woo.org","dex-evm.woo.org"]]])}get(n){return this.map.get(n)}getOr(n,s){return this.map.get(n)??s}set(n,s){this.map.set(n,s)}clear(){}},Rt=class extends _e{constructor(s){super();this.configMap=s}_restore(){let s=Object.entries(this.configMap);this.map=new Map(s)}};E();T();v();var X={EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],Registration:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"timestamp",type:"uint64"},{name:"registrationNonce",type:"uint256"}],Withdraw:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"receiver",type:"address"},{name:"token",type:"string"},{name:"amount",type:"uint256"},{name:"withdrawNonce",type:"uint64"},{name:"timestamp",type:"uint64"}],AddOrderlyKey:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"orderlyKey",type:"string"},{name:"scope",type:"string"},{name:"timestamp",type:"uint64"},{name:"expiration",type:"uint64"}],SettlePnl:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"settleNonce",type:"uint64"},{name:"timestamp",type:"uint64"}]},Dt="0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291",Ft="0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D",Vt="0x1826B75e2ef249173FC735149AE4B8e9ea10abff";var Vn=c=>{let n=new we(c||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new ee(n)},Ln=()=>{if(typeof window>"u")throw new Error("the default signer only supports browsers.");let c=new me("");return new ee(c)};function $n(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function Lt(c,n){return{name:"Orderly",version:"1",chainId:c,verifyingContract:n?$n():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function $t(c){let{chainId:n,registrationNonce:s,brokerId:o}=c,l=Date.now(),p="Registration",a={brokerId:o,chainId:n,timestamp:l,registrationNonce:s},g={EIP712Domain:X.EIP712Domain,[p]:X[p]};return[a,{domain:Lt(n),message:a,primaryType:p,types:g}]}function Ht(c){let{publicKey:n,chainId:s,primaryType:o,brokerId:l,expiration:p=365}=c,a=Date.now(),g={brokerId:l,orderlyKey:n,scope:"read,trading",chainId:s,timestamp:a,expiration:a+1e3*60*60*24*p},m={EIP712Domain:X.EIP712Domain,[o]:X[o]},I={domain:Lt(s),message:g,primaryType:o,types:m};return[g,I]}function jt(c){let{chainId:n,settlePnlNonce:s,domain:o,brokerId:l}=c,p="SettlePnl",a=new Date().getTime(),g={EIP712Domain:X.EIP712Domain,[p]:X[p]},m={brokerId:l,chainId:n,timestamp:a,settleNonce:s};return[m,{domain:o,message:m,primaryType:p,types:g}]}E();T();v();var Ze=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"},{internalType:"uint8",name:"decimals_",type:"uint8"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"issue",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_to",type:"address"},{internalType:"uint256",name:"_amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"_paused",type:"bool"}],name:"pauseTransfers",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];var Wt=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AccountIdInvalid",type:"error"},{inputs:[{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],name:"BalanceNotEnough",type:"error"},{inputs:[],name:"BrokerNotAllowed",type:"error"},{inputs:[],name:"OnlyCrossChainManagerCanCall",type:"error"},{inputs:[],name:"TokenNotAllowed",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"address",name:"userAddress",type:"address"},{indexed:!0,internalType:"uint64",name:"depositNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"}],name:"AccountDeposit",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"address",name:"userAddress",type:"address"},{indexed:!0,internalType:"uint64",name:"depositNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"}],name:"AccountDepositTo",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"accountId",type:"bytes32"},{indexed:!0,internalType:"uint64",name:"withdrawNonce",type:"uint64"},{indexed:!1,internalType:"bytes32",name:"brokerHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"sender",type:"address"},{indexed:!1,internalType:"address",name:"receiver",type:"address"},{indexed:!1,internalType:"bytes32",name:"tokenHash",type:"bytes32"},{indexed:!1,internalType:"uint128",name:"tokenAmount",type:"uint128"},{indexed:!1,internalType:"uint128",name:"fee",type:"uint128"},{indexed:!1,internalType:"uint256",name:"blocktime",type:"uint256"}],name:"AccountWithdraw",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"_tokenAddress",type:"address"}],name:"ChangeTokenAddressAndAllow",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint8",name:"version",type:"uint8"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_brokerHash",type:"bytes32"},{indexed:!1,internalType:"bool",name:"_allowed",type:"bool"}],name:"SetAllowedBroker",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{indexed:!1,internalType:"bool",name:"_allowed",type:"bool"}],name:"SetAllowedToken",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[{internalType:"bytes32",name:"",type:"bytes32"}],name:"allowedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{internalType:"address",name:"_tokenAddress",type:"address"}],name:"changeTokenAddressAndAllow",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"crossChainManagerAddress",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"}],internalType:"struct VaultTypes.VaultDepositFE",name:"data",type:"tuple"}],name:"deposit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"depositId",outputs:[{internalType:"uint64",name:"",type:"uint64"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"receiver",type:"address"},{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"}],internalType:"struct VaultTypes.VaultDepositFE",name:"data",type:"tuple"}],name:"depositTo",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"emergencyPause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"emergencyUnpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"getAllAllowedBroker",outputs:[{internalType:"bytes32[]",name:"",type:"bytes32[]"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAllAllowedToken",outputs:[{internalType:"bytes32[]",name:"",type:"bytes32[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_brokerHash",type:"bytes32"}],name:"getAllowedBroker",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"}],name:"getAllowedToken",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"_brokerHash",type:"bytes32"},{internalType:"bool",name:"_allowed",type:"bool"}],name:"setAllowedBroker",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"_tokenHash",type:"bytes32"},{internalType:"bool",name:"_allowed",type:"bool"}],name:"setAllowedToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_crossChainManagerAddress",type:"address"}],name:"setCrossChainManager",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"bytes32",name:"accountId",type:"bytes32"},{internalType:"bytes32",name:"brokerHash",type:"bytes32"},{internalType:"bytes32",name:"tokenHash",type:"bytes32"},{internalType:"uint128",name:"tokenAmount",type:"uint128"},{internalType:"uint128",name:"fee",type:"uint128"},{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"receiver",type:"address"},{internalType:"uint64",name:"withdrawNonce",type:"uint64"}],internalType:"struct VaultTypes.VaultWithdraw",name:"data",type:"tuple"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"}];var Je=class{constructor(n){this.configStore=n}getContractInfoByEnv(){return{usdcAddress:Dt,usdcAbi:Ze,vaultAddress:Ft,vaultAbi:Wt,verifyContractAddress:Vt,erc20Abi:Ze}}};E();T();v();E();T();v();var Qe=class{constructor(n=[],s={}){this.providers=n;this.services=s;this.injectProperties={}}register(...n){this.providers.push(...n),n.forEach(s=>{let o=s;o instanceof Function&&(o=new s),this.add(o)})}registerByName(n,s){let o=s;o instanceof Function&&(o=new s),this.addByName(n,o)}get(n){return this.services[n]}getAll(){return Object.assign({},this.services)}add(n){return this.addByName(n.constructor.name,n)}addByName(n,s){return this.services[n]=s,this.services[n.toLowerCase()]=s,this.injectIntoProperties(s,n),this.get(n)}inject(n,s,o){n&&o&&(n[s]=o)}injectIntoProperties(n,s=n.constructor.name){this.getInjectProperty(s.toLowerCase()).forEach(o=>{this.inject(o.target,o.propertyKey,n)})}getInjectProperty(n){return this.injectProperties[n]||(this.injectProperties[n]=[]),this.injectProperties[n]}},qt=Qe;var et=class c{static getContainer(){return c.container||(c.container=new qt),c.container}static register(...n){this.getContainer().register(...n)}static registerByName(n,s){this.getContainer().registerByName(n,s)}static get(n){return this.getContainer().get(n)}static getOr(n,s){return this.getContainer().get(n)||c.registerByName(n,s),s}static getAll(){return this.getContainer().getAll()}constructor(){}},Wn=et;E();T();v();import{AccountStatusEnum as W}from"@orderly.network/types";import qn from"eventemitter3";E();T();v();import{ethers as zt}from"ethers";var ke=class{constructor(n,s,o){this.configStore=n;this.contractManger=s;this.account=o}async withdraw(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");if(!this.account.stateValue.address)throw new Error("account address is rqeuired");let{chainId:s,token:o,amount:l}=n,p="/v1/withdraw_request",a=await this.getWithdrawalNonce(),g=this.account.getDomain(!0),[m,I]=this._generateWithdrawMessage({chainId:s,receiver:this.account.stateValue.address,token:o,amount:this.account.walletClient.parseUnits(l.toString()),nonce:a,domain:g}),A={signature:await this.account.signTypedData(I),message:m,userAddress:this.account.stateValue.address,verifyingContract:g.verifyingContract},_={method:"POST",url:p,data:A},h=await this.account.signer.sign(_);return await this._simpleFetch(p,{method:"POST",body:JSON.stringify(A),headers:{"Content-Type":"application/json","orderly-account-id":this.account.stateValue.accountId,...h}})}_generateWithdrawMessage(n){let{chainId:s,receiver:o,token:l,amount:p,domain:a,nonce:g}=n,m="Withdraw",I=Date.now(),f={EIP712Domain:X.EIP712Domain,[m]:X[m]},A={brokerId:this.configStore.get("brokerId"),chainId:s,receiver:o,token:l,amount:p,timestamp:I,withdrawNonce:g};return[A,{domain:a,message:A,primaryType:m,types:f}]}async getWithdrawalNonce(){let n=Date.now().toString(),s="/v1/withdraw_nonce",o=[n,"GET",s].join(""),l=this.account.signer,{publicKey:p,signature:a}=await l.signText(o),g=await this._simpleFetch(s,{headers:{"orderly-account-id":this.account.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.withdraw_nonce;throw new Error(g.message)}async getNativeBalance(n){let s=await this.account.walletClient?.getBalance(this.account.stateValue.address);return Ce(s,n?.decimals)}async getBalance(n,s){if(!this.account.walletClient)return"0";let o=this.contractManger.getContractInfoByEnv(),l=await this.account.walletClient?.call(n??o.usdcAddress,"balanceOf",[this.account.stateValue.address],{abi:o.usdcAbi});return Ce(l,s?.decimals)}async getBalanceByAddress(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),o=await this.account.walletClient?.call(n,"balanceOf",[this.account.stateValue.address],{abi:s.erc20Abi});return this.account.walletClient?.formatUnits(o)}async getAllowance(n,s){if(!this.account.walletClient)return"0";let o=this.contractManger.getContractInfoByEnv(),l=await this.account.walletClient?.call(n??o.usdcAddress,"allowance",[this.account.stateValue.address,s||o.vaultAddress],{abi:o.usdcAbi});return this.account.walletClient?.formatUnits(l)}async approve(n,s,o){if(!n)throw new Error("address is required");if(!this.account.walletClient)throw new Error("walletClient is undefined");let l=this.contractManger.getContractInfoByEnv(),p=typeof s<"u"&&s!==""?this.account.walletClient.parseUnits(s):zt.MaxUint256.toString();return await this.account.walletClient?.call(n,"approve",[o||l.vaultAddress,p],{abi:l.usdcAbi})}async approveByAddress(n){let{amount:s,address:o}=n;return this._approve(o,s)}async _approve(n,s){if(!this.account.walletClient)throw new Error("walletClient is undefined");let o=typeof s<"u"&&s!==""?this.account.walletClient.parseUnits(s):zt.MaxUint256.toString(),l=this.contractManger.getContractInfoByEnv();return await this.account.walletClient?.call(n,"approve",[l.vaultAddress,o],{abi:l.erc20Abi})}async deposit(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");let s=this.configStore.get("brokerId");if(!s)throw new Error("brokerId is required");let o=this.contractManger.getContractInfoByEnv(),l={accountId:this.account.accountIdHashStr,brokerHash:Se(s),tokenHash:Ye("USDC"),tokenAmount:this.account.walletClient?.parseUnits(n)};return await this.account.walletClient?.sendTransaction(o.vaultAddress,"deposit",{from:this.account.stateValue.address,to:o.vaultAddress,data:[l],value:0n},{abi:o.vaultAbi})}async _simpleFetch(n,s={}){let o=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(o,s).then(l=>l.json())}get usdcAddress(){return this.contractManger.getContractInfoByEnv().usdcAddress}};var Ue=class{constructor(n,s,o,l){this.configStore=n;this.keyStore=s;this.contractManger=o;this.getWalletAdapter=l;this._ee=new qn;this._state={status:W.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.assetsManager=new ke(n,o,this),this._bindEvents()}logout(){}async setAddress(n,s){if(!n)throw new Error("address is required");this.keyStore.setAddress(n);let o={...this.stateValue,status:W.Connected,address:n,connectWallet:s?.wallet};return this._ee.emit("change:status",o),s&&(this.walletClient=this.getWalletAdapter({...s,address:n})),await this._checkAccount(n)}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get accountIdHashStr(){if(!this.address)throw new Error("address is error");let n=this.configStore.get("brokerId");return Ge(this.address,n)}get address(){return this.stateValue.address}get chainId(){return this.walletClient?.chainId}set position(n){let s={...this.stateValue,positon:n};this._ee.emit("change:status",s)}set orders(n){let s={...this.stateValue,orders:n};this._ee.emit("change:status",s)}_bindEvents(){this._ee.addListener("change:status",n=>{this._state=n})}async _checkAccount(n){let s;try{let o=await this._checkAccountExist(n);if(o&&o.account_id)this.keyStore.setAccountId(n,o.account_id),s={...this.stateValue,status:W.SignedIn,accountId:o.account_id,userId:o.user_id},this._ee.emit("change:status",s);else return s={...this.stateValue,status:W.NotSignedIn},this._ee.emit("change:status",s),W.NotSignedIn;let l=this.keyStore.getOrderlyKey();if(s={...this.stateValue,status:W.DisabledTrading},!l)return this._ee.emit("change:status",s),W.DisabledTrading;let p=await l.getPublicKey(),a=await this._checkOrderlyKeyState(o.account_id,p);if(a&&a.orderly_key&&a.key_status==="ACTIVE"){let g=Date.now(),m=a.expiration;if(g>m)return this.keyStore.cleanKey(n,"orderlyKey"),W.DisabledTrading;let I={...this.stateValue,status:W.EnableTrading};return this._ee.emit("change:status",I),W.EnableTrading}return this.keyStore.cleanKey(n,"orderlyKey"),W.NotConnected}catch{}return W.NotSignedIn}async _checkAccountExist(n){let s=this.configStore.get("brokerId"),o=await this._simpleFetch(`/v1/get_account?address=${n}&broker_id=${s}`);return o.success?o.data:null}async createAccount(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getRegisterationNonce(),s=this.stateValue.address;if(!s)throw new Error("address is undefined");let[o,l]=$t({registrationNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId")}),p=await this.signTypedData(l),a=await this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:p,message:o,userAddress:s}),headers:{"Content-Type":"application/json"}});if(a.success){this.keyStore.setAccountId(s,a.data.account_id);let g={...this.stateValue,status:W.DisabledTrading,accountId:a.data.account_id,userId:a.data.user_id};return this._ee.emit("change:status",g),a}}async signTypedData(n){return this.walletClient?await this.walletClient.signTypedData(this.stateValue.address,JSON.stringify(n)):Promise.reject("walletClient is undefined")}async createOrderlyKey(n){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(!this.walletClient)throw new Error("walletClient is undefined");let s="AddOrderlyKey",o=this.keyStore.generateKey(),l=await o.getPublicKey(),[p,a]=Ht({publicKey:l,chainId:this.walletClient.chainId,primaryType:s,expiration:n,brokerId:this.configStore.get("brokerId")}),g=this.stateValue.address;if(!g)throw new Error("address is undefined");let m=await this.signTypedData(a),I=await this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:m,message:p,userAddress:g}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(I.success){this.keyStore.setKey(g,o);let f={...this.stateValue,status:W.EnableTrading};return this._ee.emit("change:status",f),I}else throw new Error(I.message)}async settle(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getSettleNonce(),s=this.stateValue.address,o=this.getDomain(!0),l="/v1/settle_pnl",[p,a]=jt({settlePnlNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId"),domain:o}),m={signature:await this.signTypedData(a),message:p,userAddress:s,verifyingContract:o.verifyingContract},I={method:"POST",url:l,data:m},f=await this.signer.sign(I),A=await this._simpleFetch(l,{method:"POST",body:JSON.stringify(m),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,...f}});if(A.success)return A;throw new Error(A.message)}async disconnect(){let n={...this.stateValue,status:W.NotConnected,accountId:void 0,userId:void 0,address:void 0};this._ee.emit("change:status",n)}async _checkOrderlyKeyState(n,s){let o=await this._simpleFetch(`/v1/get_orderly_key?account_id=${n}&orderly_key=${s}`);if(o.success)return o.data;throw new Error(o.message)}get signer(){return this._singer||(this._singer=new ee(this.keyStore)),this._singer}get wallet(){return this.walletClient}async _getRegisterationNonce(){let n=await this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(n.success)return n.data?.registration_nonce;throw new Error(n.message)}async _getSettleNonce(){let n=Date.now().toString(),o=[n,"GET","/v1/settle_nonce"].join(""),l=this.signer,{publicKey:p,signature:a}=await l.signText(o),g=await this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.settle_nonce;throw new Error(g.message)}async _simpleFetch(n,s={}){let o=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(o,s).then(l=>l.json())}getDomain(n){if(!this.walletClient)throw new Error("walletClient is undefined");return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:n?this.contractManger.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}get on(){return this._ee.on.bind(this._ee)}get once(){return this._ee.once.bind(this._ee)}get off(){return this._ee.off.bind(this._ee)}};Ue.instanceName="account";E();T();v();E();T();v();import{BrowserProvider as zn,ethers as de,toNumber as Gn}from"ethers";import{getParsedEthersError as Gt}from"@enzoferey/ethers-error-parser";var tt=class{constructor(n){this._chainId=parseInt(n.chain.id,16),this.provider=new zn(n.provider,"any"),this._address=n.address}parseUnits(n){return de.parseUnits(n,6).toString()}formatUnits(n){return de.formatUnits(n,6)}getBalance(n){return this.provider.getBalance(n).then(s=>s,s=>{})}deposit(n,s,o){throw new Error("Method not implemented.")}async call(n,s,o,l){let p=await this.provider?.getSigner();return new de.Contract(n,l.abi,p)[s].apply(null,o).catch(g=>{throw Gt(g)})}get chainId(){return this._chainId}get addresses(){return this._address}async send(n,s){return await this.provider?.send(n,s)}async sendTransaction(n,s,o,l){let p=await this.provider?.getSigner();if(!p)throw new Error("singer is not exist");let g=new de.Contract(n,l.abi,this.provider).interface.encodeFunctionData(s,o.data),m={from:o.from,to:o.to,data:g,value:o.value};try{return await p.sendTransaction(m)}catch(I){throw Gt(I)}}async estimateGas(n){let s=await this.provider.estimateGas(n);return Gn(s)}async signTypedData(n,s){return await this.provider?.send("eth_signTypedData_v4",[n,s])}async verify(n,s){let{domain:o,types:l,message:p}=n,a=de.verifyTypedData(o,l,p,s)}on(n,s){this.provider?.on(n,s)}off(n,s){this.provider?.off(n,s)}getContract(n,s){return new de.Contract(n,s,this.provider)}};export{Ue as Account,Rt as BaseConfigStore,Je as BaseContractManager,xe as BaseKeyStore,Q as BaseOrderlyKeyPair,ee as BaseSigner,tt as EtherAdapter,ps as EventEmitter,me as LocalStorageStore,_e as MemoryConfigStore,we as MockKeyStore,Wn as SimpleDI,Ln as getDefaultSigner,Vn as getMockSigner,Ot as utils};
2
2
  /*! Bundled license information:
3
3
 
4
4
  @jspm/core/nodelibs/browser/buffer.js: