@orderly.network/core 0.1.0 → 0.1.1
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ir=Object.create;var Be=Object.defineProperty;var ar=Object.getOwnPropertyDescriptor;var sr=Object.getOwnPropertyNames;var or=Object.getPrototypeOf,cr=Object.prototype.hasOwnProperty;var ur=(r,e)=>()=>(r&&(e=r(r=0)),e);var ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),lr=(r,e)=>{for(var t in e)Be(r,t,{get:e[t],enumerable:!0})},pr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of sr(e))!cr.call(r,i)&&i!==t&&Be(r,i,{get:()=>e[i],enumerable:!(n=ar(e,i))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?ir(or(r)):{},pr(e||!r||!r.__esModule?Be(t,"default",{value:r,enumerable:!0}):t,r));var ct=ee(he=>{"use strict";f();he.byteLength=dr;he.toByteArray=fr;he.fromByteArray=wr;var O=[],K=[],yr=typeof Uint8Array<"u"?Uint8Array:Array,Ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(X=0,st=Ue.length;X<st;++X)O[X]=Ue[X],K[Ue.charCodeAt(X)]=X;var X,st;K["-".charCodeAt(0)]=62;K["_".charCodeAt(0)]=63;function ot(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function dr(r){var e=ot(r),t=e[0],n=e[1];return(t+n)*3/4-n}function hr(r,e,t){return(e+t)*3/4-t}function fr(r){var e,t=ot(r),n=t[0],i=t[1],a=new yr(hr(r,n,i)),s=0,c=i>0?n-4:n,u;for(u=0;u<c;u+=4)e=K[r.charCodeAt(u)]<<18|K[r.charCodeAt(u+1)]<<12|K[r.charCodeAt(u+2)]<<6|K[r.charCodeAt(u+3)],a[s++]=e>>16&255,a[s++]=e>>8&255,a[s++]=e&255;return i===2&&(e=K[r.charCodeAt(u)]<<2|K[r.charCodeAt(u+1)]>>4,a[s++]=e&255),i===1&&(e=K[r.charCodeAt(u)]<<10|K[r.charCodeAt(u+1)]<<4|K[r.charCodeAt(u+2)]>>2,a[s++]=e>>8&255,a[s++]=e&255),a}function gr(r){return O[r>>18&63]+O[r>>12&63]+O[r>>6&63]+O[r&63]}function mr(r,e,t){for(var n,i=[],a=e;a<t;a+=3)n=(r[a]<<16&16711680)+(r[a+1]<<8&65280)+(r[a+2]&255),i.push(gr(n));return i.join("")}function wr(r){for(var e,t=r.length,n=t%3,i=[],a=16383,s=0,c=t-n;s<c;s+=a)i.push(mr(r,s,s+a>c?c:s+a));return n===1?(e=r[t-1],i.push(O[e>>2]+O[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(O[e>>10]+O[e>>4&63]+O[e<<2&63]+"=")),i.join("")}});var ut=ee(_e=>{"use strict";f();_e.read=function(r,e,t,n,i){var a,s,c=i*8-n-1,u=(1<<c)-1,l=u>>1,p=-7,y=t?i-1:0,g=t?-1:1,h=r[e+y];for(y+=g,a=h&(1<<-p)-1,h>>=-p,p+=c;p>0;a=a*256+r[e+y],y+=g,p-=8);for(s=a&(1<<-p)-1,a>>=-p,p+=n;p>0;s=s*256+r[e+y],y+=g,p-=8);if(a===0)a=1-l;else{if(a===u)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,n),a=a-l}return(h?-1:1)*s*Math.pow(2,a-n)};_e.write=function(r,e,t,n,i,a){var s,c,u,l=a*8-i-1,p=(1<<l)-1,y=p>>1,g=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:a-1,m=n?1:-1,I=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,s=p):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),s+y>=1?e+=g/u:e+=g*Math.pow(2,1-y),e*u>=2&&(s++,u/=2),s+y>=p?(c=0,s=p):s+y>=1?(c=(e*u-1)*Math.pow(2,i),s=s+y):(c=e*Math.pow(2,y-1)*Math.pow(2,i),s=0));i>=8;r[t+h]=c&255,h+=m,c/=256,i-=8);for(s=s<<i|c,l+=i;l>0;r[t+h]=s&255,h+=m,s/=256,l-=8);r[t+h-m]|=I*128}});var Re=ee(re=>{"use strict";f();var Fe=ct(),te=ut(),lt=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;re.Buffer=o;re.SlowBuffer=Er;re.INSPECT_MAX_BYTES=50;var fe=2147483647;re.kMaxLength=fe;o.TYPED_ARRAY_SUPPORT=br();!o.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 br(){try{var 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(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}});Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function H(r){if(r>fe)throw new RangeError('The value "'+r+'" is invalid for option "size"');var e=new Uint8Array(r);return Object.setPrototypeOf(e,o.prototype),e}function o(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 De(r)}return dt(r,e,t)}o.poolSize=8192;function dt(r,e,t){if(typeof r=="string")return vr(r,e);if(ArrayBuffer.isView(r))return Ar(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(N(r,ArrayBuffer)||r&&N(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(N(r,SharedArrayBuffer)||r&&N(r.buffer,SharedArrayBuffer)))return Ke(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return o.from(n,e,t);var i=Tr(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return o.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)}o.from=function(r,e,t){return dt(r,e,t)};Object.setPrototypeOf(o.prototype,Uint8Array.prototype);Object.setPrototypeOf(o,Uint8Array);function ht(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 xr(r,e,t){return ht(r),r<=0?H(r):e!==void 0?typeof t=="string"?H(r).fill(e,t):H(r).fill(e):H(r)}o.alloc=function(r,e,t){return xr(r,e,t)};function De(r){return ht(r),H(r<0?0:Oe(r)|0)}o.allocUnsafe=function(r){return De(r)};o.allocUnsafeSlow=function(r){return De(r)};function vr(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var t=ft(r,e)|0,n=H(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function Me(r){for(var e=r.length<0?0:Oe(r.length)|0,t=H(e),n=0;n<e;n+=1)t[n]=r[n]&255;return t}function Ar(r){if(N(r,Uint8Array)){var e=new Uint8Array(r);return Ke(e.buffer,e.byteOffset,e.byteLength)}return Me(r)}function Ke(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');var n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,o.prototype),n}function Tr(r){if(o.isBuffer(r)){var e=Oe(r.length)|0,t=H(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Ne(r.length)?H(0):Me(r);if(r.type==="Buffer"&&Array.isArray(r.data))return Me(r.data)}function Oe(r){if(r>=fe)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+fe.toString(16)+" bytes");return r|0}function Er(r){return+r!=r&&(r=0),o.alloc(+r)}o.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==o.prototype};o.compare=function(e,t){if(N(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),N(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var n=e.length,i=t.length,a=0,s=Math.min(n,i);a<s;++a)if(e[a]!==t[a]){n=e[a],i=t[a];break}return n<i?-1:i<n?1:0};o.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}};o.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return o.alloc(0);var n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var i=o.allocUnsafe(t),a=0;for(n=0;n<e.length;++n){var s=e[n];if(N(s,Uint8Array))a+s.length>i.length?o.from(s).copy(i,a):Uint8Array.prototype.set.call(i,s,a);else if(o.isBuffer(s))s.copy(i,a);else throw new TypeError('"list" argument must be an Array of Buffers');a+=s.length}return i};function ft(r,e){if(o.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||N(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);var t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Pe(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return vt(r).length;default:if(i)return n?-1:Pe(r).length;e=(""+e).toLowerCase(),i=!0}}o.byteLength=ft;function Ir(r,e,t){var n=!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 Pr(this,e,t);case"utf8":case"utf-8":return mt(this,e,t);case"ascii":return Mr(this,e,t);case"latin1":case"binary":return Kr(this,e,t);case"base64":return _r(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Dr(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}o.prototype._isBuffer=!0;function Y(r,e,t){var n=r[e];r[e]=r[t],r[t]=n}o.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)Y(this,t,t+1);return this};o.prototype.swap32=function(){var e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)Y(this,t,t+3),Y(this,t+1,t+2);return this};o.prototype.swap64=function(){var e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)Y(this,t,t+7),Y(this,t+1,t+6),Y(this,t+2,t+5),Y(this,t+3,t+4);return this};o.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?mt(this,0,e):Ir.apply(this,arguments)};o.prototype.toLocaleString=o.prototype.toString;o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:o.compare(this,e)===0};o.prototype.inspect=function(){var e="",t=re.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};lt&&(o.prototype[lt]=o.prototype.inspect);o.prototype.compare=function(e,t,n,i,a){if(N(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.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),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),a===void 0&&(a=this.length),t<0||n>e.length||i<0||a>this.length)throw new RangeError("out of range index");if(i>=a&&t>=n)return 0;if(i>=a)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,a>>>=0,this===e)return 0;for(var s=a-i,c=n-t,u=Math.min(s,c),l=this.slice(i,a),p=e.slice(t,n),y=0;y<u;++y)if(l[y]!==p[y]){s=l[y],c=p[y];break}return s<c?-1:c<s?1:0};function gt(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Ne(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=o.from(e,n)),o.isBuffer(e))return e.length===0?-1:pt(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):pt(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function pt(r,e,t,n,i){var a=1,s=r.length,c=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;a=2,s/=2,c/=2,t/=2}function u(h,m){return a===1?h[m]:h.readUInt16BE(m*a)}var l;if(i){var p=-1;for(l=t;l<s;l++)if(u(r,l)===u(e,p===-1?0:l-p)){if(p===-1&&(p=l),l-p+1===c)return p*a}else p!==-1&&(l-=l-p),p=-1}else for(t+c>s&&(t=s-c),l=t;l>=0;l--){for(var y=!0,g=0;g<c;g++)if(u(r,l+g)!==u(e,g)){y=!1;break}if(y)return l}return-1}o.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};o.prototype.indexOf=function(e,t,n){return gt(this,e,t,n,!0)};o.prototype.lastIndexOf=function(e,t,n){return gt(this,e,t,n,!1)};function Cr(r,e,t,n){t=Number(t)||0;var i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;var a=e.length;n>a/2&&(n=a/2);for(var s=0;s<n;++s){var c=parseInt(e.substr(s*2,2),16);if(Ne(c))return s;r[t+s]=c}return s}function Sr(r,e,t,n){return ge(Pe(e,r.length-t),r,t,n)}function kr(r,e,t,n){return ge(Rr(e),r,t,n)}function Br(r,e,t,n){return ge(vt(e),r,t,n)}function Ur(r,e,t,n){return ge(Vr(e,r.length-t),r,t,n)}o.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var a=this.length-t;if((n===void 0||n>a)&&(n=a),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var s=!1;;)switch(i){case"hex":return Cr(this,e,t,n);case"utf8":case"utf-8":return Sr(this,e,t,n);case"ascii":case"latin1":case"binary":return kr(this,e,t,n);case"base64":return Br(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ur(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function _r(r,e,t){return e===0&&t===r.length?Fe.fromByteArray(r):Fe.fromByteArray(r.slice(e,t))}function mt(r,e,t){t=Math.min(r.length,t);for(var n=[],i=e;i<t;){var a=r[i],s=null,c=a>239?4:a>223?3:a>191?2:1;if(i+c<=t){var u,l,p,y;switch(c){case 1:a<128&&(s=a);break;case 2:u=r[i+1],(u&192)===128&&(y=(a&31)<<6|u&63,y>127&&(s=y));break;case 3:u=r[i+1],l=r[i+2],(u&192)===128&&(l&192)===128&&(y=(a&15)<<12|(u&63)<<6|l&63,y>2047&&(y<55296||y>57343)&&(s=y));break;case 4:u=r[i+1],l=r[i+2],p=r[i+3],(u&192)===128&&(l&192)===128&&(p&192)===128&&(y=(a&15)<<18|(u&63)<<12|(l&63)<<6|p&63,y>65535&&y<1114112&&(s=y))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=c}return Fr(n)}var yt=4096;function Fr(r){var e=r.length;if(e<=yt)return String.fromCharCode.apply(String,r);for(var t="",n=0;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=yt));return t}function Mr(r,e,t){var n="";t=Math.min(r.length,t);for(var i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function Kr(r,e,t){var n="";t=Math.min(r.length,t);for(var i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function Pr(r,e,t){var n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);for(var i="",a=e;a<t;++a)i+=Lr[r[a]];return i}function Dr(r,e,t){for(var n=r.slice(e,t),i="",a=0;a<n.length-1;a+=2)i+=String.fromCharCode(n[a]+n[a+1]*256);return i}o.prototype.slice=function(e,t){var n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);var i=this.subarray(e,t);return Object.setPrototypeOf(i,o.prototype),i};function T(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")}o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var i=this[e],a=1,s=0;++s<t&&(a*=256);)i+=this[e+s]*a;return i};o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var i=this[e+--t],a=1;t>0&&(a*=256);)i+=this[e+--t]*a;return i};o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e=e>>>0,t||T(e,1,this.length),this[e]};o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||T(e,2,this.length),this[e]|this[e+1]<<8};o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||T(e,2,this.length),this[e]<<8|this[e+1]};o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||T(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};o.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var i=this[e],a=1,s=0;++s<t&&(a*=256);)i+=this[e+s]*a;return a*=128,i>=a&&(i-=Math.pow(2,8*t)),i};o.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var i=t,a=1,s=this[e+--i];i>0&&(a*=256);)s+=this[e+--i]*a;return a*=128,s>=a&&(s-=Math.pow(2,8*t)),s};o.prototype.readInt8=function(e,t){return e=e>>>0,t||T(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};o.prototype.readInt16LE=function(e,t){e=e>>>0,t||T(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};o.prototype.readInt16BE=function(e,t){e=e>>>0,t||T(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};o.prototype.readInt32LE=function(e,t){return e=e>>>0,t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};o.prototype.readInt32BE=function(e,t){return e=e>>>0,t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};o.prototype.readFloatLE=function(e,t){return e=e>>>0,t||T(e,4,this.length),te.read(this,e,!0,23,4)};o.prototype.readFloatBE=function(e,t){return e=e>>>0,t||T(e,4,this.length),te.read(this,e,!1,23,4)};o.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||T(e,8,this.length),te.read(this,e,!0,52,8)};o.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||T(e,8,this.length),te.read(this,e,!1,52,8)};function U(r,e,t,n,i,a){if(!o.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<a)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){var a=Math.pow(2,8*n)-1;U(this,e,t,n,a,0)}var s=1,c=0;for(this[t]=e&255;++c<n&&(s*=256);)this[t+c]=e/s&255;return t+n};o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){var a=Math.pow(2,8*n)-1;U(this,e,t,n,a,0)}var s=n-1,c=1;for(this[t+s]=e&255;--s>=0&&(c*=256);)this[t+s]=e/c&255;return t+n};o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,1,255,0),this[t]=e&255,t+1};o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||U(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};o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||U(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};o.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){var a=Math.pow(2,8*n-1);U(this,e,t,n,a-1,-a)}var s=0,c=1,u=0;for(this[t]=e&255;++s<n&&(c*=256);)e<0&&u===0&&this[t+s-1]!==0&&(u=1),this[t+s]=(e/c>>0)-u&255;return t+n};o.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){var a=Math.pow(2,8*n-1);U(this,e,t,n,a-1,-a)}var s=n-1,c=1,u=0;for(this[t+s]=e&255;--s>=0&&(c*=256);)e<0&&u===0&&this[t+s+1]!==0&&(u=1),this[t+s]=(e/c>>0)-u&255;return t+n};o.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};o.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};o.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};o.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||U(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};o.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||U(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};function wt(r,e,t,n,i,a){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function bt(r,e,t,n,i){return e=+e,t=t>>>0,i||wt(r,e,t,4,34028234663852886e22,-34028234663852886e22),te.write(r,e,t,n,23,4),t+4}o.prototype.writeFloatLE=function(e,t,n){return bt(this,e,t,!0,n)};o.prototype.writeFloatBE=function(e,t,n){return bt(this,e,t,!1,n)};function xt(r,e,t,n,i){return e=+e,t=t>>>0,i||wt(r,e,t,8,17976931348623157e292,-17976931348623157e292),te.write(r,e,t,n,52,8),t+8}o.prototype.writeDoubleLE=function(e,t,n){return xt(this,e,t,!0,n)};o.prototype.writeDoubleBE=function(e,t,n){return xt(this,e,t,!1,n)};o.prototype.copy=function(e,t,n,i){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);var a=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),a};o.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!o.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){var a=e.charCodeAt(0);(i==="utf8"&&a<128||i==="latin1")&&(e=a)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);var s;if(typeof e=="number")for(s=t;s<n;++s)this[s]=e;else{var c=o.isBuffer(e)?e:o.from(e,i),u=c.length;if(u===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-t;++s)this[s+t]=c[s%u]}return this};var Or=/[^+/0-9A-Za-z-_]/g;function Nr(r){if(r=r.split("=")[0],r=r.trim().replace(Or,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Pe(r,e){e=e||1/0;for(var t,n=r.length,i=null,a=[],s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&a.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&a.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&a.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&a.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;a.push(t)}else if(t<2048){if((e-=2)<0)break;a.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;a.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;a.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return a}function Rr(r){for(var e=[],t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function Vr(r,e){for(var t,n,i,a=[],s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,a.push(i),a.push(n);return a}function vt(r){return Fe.toByteArray(Nr(r))}function ge(r,e,t,n){for(var i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function N(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Ne(r){return r!==r}var Lr=function(){for(var r="0123456789abcdef",e=new Array(256),t=0;t<16;++t)for(var n=t*16,i=0;i<16;++i)e[n+i]=r[t]+r[i];return e}()});var Ct=ee((En,It)=>{"use strict";f();var v=It.exports={},R,V;function Ve(){throw new Error("setTimeout has not been defined")}function Le(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?R=setTimeout:R=Ve}catch{R=Ve}try{typeof clearTimeout=="function"?V=clearTimeout:V=Le}catch{V=Le}})();function At(r){if(R===setTimeout)return setTimeout(r,0);if((R===Ve||!R)&&setTimeout)return R=setTimeout,setTimeout(r,0);try{return R(r,0)}catch{try{return R.call(null,r,0)}catch{return R.call(this,r,0)}}}function Wr(r){if(V===clearTimeout)return clearTimeout(r);if((V===Le||!V)&&clearTimeout)return V=clearTimeout,clearTimeout(r);try{return V(r)}catch{try{return V.call(null,r)}catch{return V.call(this,r)}}}var j=[],ne=!1,Z,me=-1;function Hr(){!ne||!Z||(ne=!1,Z.length?j=Z.concat(j):me=-1,j.length&&Tt())}function Tt(){if(!ne){var r=At(Hr);ne=!0;for(var e=j.length;e;){for(Z=j,j=[];++me<e;)Z&&Z[me].run();me=-1,e=j.length}Z=null,ne=!1,Wr(r)}}v.nextTick=function(r){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];j.push(new Et(r,e)),j.length===1&&!ne&&At(Tt)};function Et(r,e){this.fun=r,this.array=e}Et.prototype.run=function(){this.fun.apply(null,this.array)};v.title="browser";v.browser=!0;v.env={};v.argv=[];v.version="";v.versions={};function z(){}v.on=z;v.addListener=z;v.once=z;v.off=z;v.removeListener=z;v.removeAllListeners=z;v.emit=z;v.prependListener=z;v.prependOnceListener=z;v.listeners=function(r){return[]};v.binding=function(r){throw new Error("process.binding is not supported")};v.cwd=function(){return"/"};v.chdir=function(r){throw new Error("process.chdir is not supported")};v.umask=function(){return 0}});var w,b,Cn,f=ur(()=>{"use strict";w=de(Re()),b=de(Ct()),Cn=function(r){function e(){var n=this||self;return delete r.prototype.__magic__,n}if(typeof globalThis=="object")return globalThis;if(this)return e();r.defineProperty(r.prototype,"__magic__",{configurable:!0,get:e});var t=__magic__;return t}(Object)});var kt=ee((kn,St)=>{"use strict";f();function jr(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var n=0;n<r.length;n++){var i=r.charAt(n),a=i.charCodeAt(0);if(e[a]!==255)throw new TypeError(i+" is ambiguous");e[a]=n}var s=r.length,c=r.charAt(0),u=Math.log(s)/Math.log(256),l=Math.log(256)/Math.log(s);function p(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 m=0,I=0,A=0,C=h.length;A!==C&&h[A]===0;)A++,m++;for(var _=(C-A)*l+1>>>0,S=new Uint8Array(_);A!==C;){for(var M=h[A],D=0,F=_-1;(M!==0||D<I)&&F!==-1;F--,D++)M+=256*S[F]>>>0,S[F]=M%s>>>0,M=M/s>>>0;if(M!==0)throw new Error("Non-zero carry");I=D,A++}for(var P=_-I;P!==_&&S[P]===0;)P++;for(var ye=c.repeat(m);P<_;++P)ye+=r.charAt(S[P]);return ye}function y(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var m=0,I=0,A=0;h[m]===c;)I++,m++;for(var C=(h.length-m)*u+1>>>0,_=new Uint8Array(C);h[m];){var S=e[h.charCodeAt(m)];if(S===255)return;for(var M=0,D=C-1;(S!==0||M<A)&&D!==-1;D--,M++)S+=s*_[D]>>>0,_[D]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");A=M,m++}for(var F=C-A;F!==C&&_[F]===0;)F++;for(var P=new Uint8Array(I+(C-F)),ye=I;F!==C;)P[ye++]=_[F++];return P}function g(h){var m=y(h);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:p,decodeUnsafe:y,decode:g}}St.exports=jr});var Ut=ee((Un,Bt)=>{"use strict";f();var zr=kt(),qr="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";Bt.exports=zr(qr)});f();f();f();var ce=de(Ut());f();var E=2n**255n-19n,ie=2n**252n+27742317777372353535851937790883648493n,We=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,He=0x6666666666666666666666666666666666666666666666666666666666666658n,we={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:E,n:ie,h:8,Gx:We,Gy:He},k=(r="")=>{throw new Error(r)},Pt=r=>typeof r=="string",ve=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?k("Uint8Array expected"):r,ae=r=>new Uint8Array(r),Ae=(r,e)=>ve(Pt(r)?qe(r):ae(r),e),d=(r,e=E)=>{let t=r%e;return t>=0n?t:e+t},_t=r=>r instanceof q?r:k("Point expected"),Ft,q=class r{constructor(e,t,n,i){this.ex=e,this.ey=t,this.ez=n,this.et=i}static fromAffine(e){return new r(e.x,e.y,1n,d(e.x*e.y))}static fromHex(e,t=!0){let{d:n}=we;e=Ae(e,32);let i=e.slice();i[31]=e[31]&-129;let a=Nt(i);a===0n||(t&&!(0n<a&&a<E)&&k("bad y coord 1"),!t&&!(0n<a&&a<2n**256n)&&k("bad y coord 2"));let s=d(a*a),c=d(s-1n),u=d(n*s+1n),{isValid:l,value:p}=Gr(c,u);l||k("bad y coordinate 3");let y=(p&1n)===1n;return(e[31]&128)!==0!==y&&(p=d(-p)),new r(p,a,1n,d(p*a))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:t,ey:n,ez:i}=this,{ex:a,ey:s,ez:c}=_t(e),u=d(t*c),l=d(a*i),p=d(n*c),y=d(s*i);return u===l&&p===y}is0(){return this.equals(be)}negate(){return new r(d(-this.ex),this.ey,this.ez,d(-this.et))}double(){let{ex:e,ey:t,ez:n}=this,{a:i}=we,a=d(e*e),s=d(t*t),c=d(2n*d(n*n)),u=d(i*a),l=e+t,p=d(d(l*l)-a-s),y=u+s,g=y-c,h=u-s,m=d(p*g),I=d(y*h),A=d(p*h),C=d(g*y);return new r(m,I,C,A)}add(e){let{ex:t,ey:n,ez:i,et:a}=this,{ex:s,ey:c,ez:u,et:l}=_t(e),{a:p,d:y}=we,g=d(t*s),h=d(n*c),m=d(a*y*l),I=d(i*u),A=d((t+n)*(s+c)-g-h),C=d(I-m),_=d(I+m),S=d(h-p*g),M=d(A*C),D=d(_*S),F=d(A*S),P=d(C*_);return new r(M,D,P,F)}mul(e,t=!0){if(e===0n)return t===!0?k("cannot multiply by 0"):be;if(typeof e=="bigint"&&0n<e&&e<ie||k("invalid scalar, must be < L"),!t&&this.is0()||e===1n)return this;if(this.equals(Q))return Qr(e).p;let n=be,i=Q;for(let a=this;e>0n;a=a.double(),e>>=1n)e&1n?n=n.add(a):t&&(i=i.add(a));return n}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(we.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(ie/2n,!1).double();return ie%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:t,ez:n}=this;if(this.is0())return{x:0n,y:0n};let i=Rt(n);return d(n*i)!==1n&&k("invalid inverse"),{x:d(e*i),y:d(t*i)}}toRawBytes(){let{x:e,y:t}=this.toAffine(),n=Ot(t);return n[31]|=e&1n?128:0,n}toHex(){return ze(this.toRawBytes())}};q.BASE=new q(We,He,1n,d(We*He));q.ZERO=new q(0n,1n,1n,0n);var{BASE:Q,ZERO:be}=q,Dt=(r,e)=>r.toString(16).padStart(e,"0"),ze=r=>Array.from(r).map(e=>Dt(e,2)).join(""),qe=r=>{let e=r.length;(!Pt(r)||e%2)&&k("hex invalid 1");let t=ae(e/2);for(let n=0;n<t.length;n++){let i=n*2,a=r.slice(i,i+2),s=Number.parseInt(a,16);(Number.isNaN(s)||s<0)&&k("hex invalid 2"),t[n]=s}return t},Ot=r=>qe(Dt(r,32*2)).reverse(),Nt=r=>BigInt("0x"+ze(ae(ve(r)).reverse())),xe=(...r)=>{let e=ae(r.reduce((n,i)=>n+ve(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},Rt=(r,e=E)=>{(r===0n||e<=0n)&&k("no inverse n="+r+" mod="+e);let t=d(r,e),n=e,i=0n,a=1n,s=1n,c=0n;for(;t!==0n;){let u=n/t,l=n%t,p=i-s*u,y=a-c*u;n=t,t=l,i=s,a=c,s=p,c=y}return n===1n?d(i,e):k("no inverse")},L=(r,e)=>{let t=r;for(;e-- >0n;)t*=t,t%=E;return t},$r=r=>{let t=r*r%E*r%E,n=L(t,2n)*t%E,i=L(n,1n)*r%E,a=L(i,5n)*i%E,s=L(a,10n)*a%E,c=L(s,20n)*s%E,u=L(c,40n)*c%E,l=L(u,80n)*u%E,p=L(l,80n)*u%E,y=L(p,10n)*a%E;return{pow_p_5_8:L(y,2n)*r%E,b2:t}},Mt=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Gr=(r,e)=>{let t=d(e*e*e),n=d(t*t*e),i=$r(r*n).pow_p_5_8,a=d(r*t*i),s=d(e*a*a),c=a,u=d(a*Mt),l=s===r,p=s===d(-r),y=s===d(-r*Mt);return l&&(a=c),(p||y)&&(a=u),(d(a)&1n)===1n&&(a=d(-a)),{isValid:l||p,value:a}},je=r=>d(Nt(r),ie),oe,$e=(...r)=>Xe.sha512Async(...r),Vt=(...r)=>typeof oe=="function"?oe(...r):k("etc.sha512Sync not set"),Lt=r=>{let e=r.slice(0,32);e[0]&=248,e[31]&=127,e[31]|=64;let t=r.slice(32,64),n=je(e),i=Q.mul(n),a=i.toRawBytes();return{head:e,prefix:t,scalar:n,point:i,pointBytes:a}},Ge=r=>$e(Ae(r,32)).then(Lt),Xr=r=>Lt(Vt(Ae(r,32))),Wt=r=>Ge(r).then(e=>e.pointBytes);function Yr(r,e){return r?$e(e.hashable).then(e.finish):e.finish(Vt(e.hashable))}var Zr=(r,e,t)=>{let{pointBytes:n,scalar:i}=r,a=je(e),s=Q.mul(a).toRawBytes();return{hashable:xe(s,n,t),finish:l=>{let p=d(a+je(l)*i,ie);return ve(xe(s,Ot(p)),64)}}},Ht=async(r,e)=>{let t=Ae(r),n=await Ge(e),i=await $e(n.prefix,t);return Yr(!0,Zr(n,i,t))};var Kt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Xe={bytesToHex:ze,hexToBytes:qe,concatBytes:xe,mod:d,invert:Rt,randomBytes:r=>{let e=Kt();return e||k("crypto.getRandomValues must be defined"),e.getRandomValues(ae(r))},sha512Async:async(...r)=>{let e=Kt();e||k("crypto.subtle or etc.sha512Async must be defined");let t=xe(...r);return ae(await e.subtle.digest("SHA-512",t.buffer))},sha512Sync:void 0};Object.defineProperties(Xe,{sha512Sync:{configurable:!1,get(){return oe},set(r){oe||(oe=r)}}});var jt={getExtendedPublicKeyAsync:Ge,getExtendedPublicKey:Xr,randomPrivateKey:()=>Xe.randomBytes(32),precompute(r=8,e=Q){return e.multiply(3n),e}},J=8,Jr=()=>{let r=[],e=256/J+1,t=Q,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let a=1;a<2**(J-1);a++)n=n.add(t),r.push(n);t=n.double()}return r},Qr=r=>{let e=Ft||(Ft=Jr()),t=(p,y)=>{let g=y.negate();return p?g:y},n=be,i=Q,a=1+256/J,s=2**(J-1),c=BigInt(2**J-1),u=2**J,l=BigInt(J);for(let p=0;p<a;p++){let y=p*s,g=Number(r&c);r>>=l,g>s&&(g-=u,r+=1n);let h=y,m=y+Math.abs(g)-1,I=p%2!==0,A=g<0;g===0?i=i.add(t(I,e[h])):n=n.add(t(A,e[m]))}return{p:n,f:i}};var $=class r{static generateKey(){let e,t;do e=jt.randomPrivateKey(),t=(0,ce.encode)(e);while(t.length!==44);return new r(t)}constructor(e){this.secretKey=e;let t=(0,ce.decode)(e);this.privateKey=w.Buffer.from(t).toString("hex")}async sign(e){return await Ht(e,this.privateKey)}async getPublicKey(){let e=await Wt(this.privateKey);return`ed25519:${(0,ce.encode)(e)}`}toString(){return this.privateKey}};var Te=class{constructor(e="testnet"){this.networkId=e}get keyPrefix(){return`orderly_${this.networkId}_`}},ue=class extends Te{getOrderlyKey(e){let t;if(e)t=this.getItem(e,"orderlyKey");else{let n=this.getAddress();if(!n)return null;t=this.getItem(n,"orderlyKey")}return t?new $(t):null}getAccountId(e){return this.getItem(e,"accountId")}setAccountId(e,t){this.setItem(e,{accountId:t})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(e){localStorage.setItem(`${this.keyPrefix}address`,e)}generateKey(){return $.generateKey()}setKey(e,t){this.setItem(e,{orderlyKey:t.secretKey})}cleanAllKey(e){localStorage.removeItem(`${this.keyPrefix}${e}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(e,t){let n=this.getItem(e);delete n[t],localStorage.setItem(`${this.keyPrefix}${e}`,JSON.stringify(n))}setItem(e,t){let n=`${this.keyPrefix}${e}`,i=localStorage.getItem(n);i?i=JSON.parse(i):i={},localStorage.setItem(n,JSON.stringify({...i,...t}))}getItem(e,t){let n=`${this.keyPrefix}${e}`,i=localStorage.getItem(n);return i?i=JSON.parse(i):i={},typeof t>"u"?i:i[t]}},le=class{constructor(e){this.secretKey=e}generateKey(){return new $(this.secretKey)}getOrderlyKey(){return new $(this.secretKey)}getAccountId(){return""}setAccountId(e){}getAddress(){return""}setAddress(e){}setKey(e,t){}cleanAllKey(){}cleanKey(e){}};f();var zt={};lr(zt,{base64url:()=>Ye,calculateStringHash:()=>Qe,formatByUnits:()=>Ie,parseAccountId:()=>Ze,parseBrokerHash:()=>Ee,parseTokenHash:()=>Je,parseUnits:()=>sn});f();import{keccak256 as tn,AbiCoder as rn,solidityPackedKeccak256 as nn,formatUnits as an}from"ethers";import{parseUnits as sn}from"ethers";var Ye=function(r){return r.replace(/\+/g,"-").replace(/\//g,"_")};function Ee(r){return Qe(r)}function Ze(r,e){let t=rn.defaultAbiCoder();return tn(t.encode(["address","bytes32"],[r,Ee(e)]))}function Je(r){return Qe(r)}function Qe(r){return nn(["string"],[r])}function Ie(r,e="ether"){return an(r,e)}var et=de(Re()),G=class{constructor(e){this.keyStore=e}async sign(e){let t=Date.now().toString(),n=[t,e.method.toUpperCase(),e.url].join("");e.data&&Object.keys(e.data).length&&(n+=JSON.stringify(e.data));let{signature:i,publicKey:a}=await this.signText(n);return{"orderly-key":a,"orderly-timestamp":t,"orderly-signature":i}}async signText(e){let t=this.keyStore.getOrderlyKey();if(!t)throw new Error("orderlyKeyPair is not defined");let n=et.Buffer.from(e),i=await t.sign(n),a=et.Buffer.from(i).toString("base64");return{signature:Ye(a),publicKey:await t.getPublicKey()}}};import{default as Yi}from"eventemitter3";f();f();var Ce=class{constructor(e){this._restore(e)}_restore(e){let t=e?.brokerId||"woofi_pro",n=e?.networkId||"mainnet";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",t],["env","dev-evm"],["networkId",n],["PROD_URL",["dex-iap-evm.woo.org","dex-evm.woo.org"]]])}get(e){return this.map.get(e)}getOr(e,t){return this.map.get(e)??t}set(e,t){this.map.set(e,t)}clear(){}},qt=class extends Ce{constructor(t){super();this.configMap=t}};f();var W={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"}]},$t="0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291",Gt="0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D",Xt="0x1826B75e2ef249173FC735149AE4B8e9ea10abff";var on=r=>{let e=new le(r||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new G(e)},cn=()=>{if(typeof window>"u")throw new Error("the default signer only supports browsers.");let r=new ue("");return new G(r)};function un(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function Yt(r,e){return{name:"Orderly",version:"1",chainId:r,verifyingContract:e?un():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function Zt(r){let{chainId:e,registrationNonce:t,brokerId:n}=r,i=Date.now(),a="Registration",s={brokerId:n,chainId:e,timestamp:i,registrationNonce:t},c={EIP712Domain:W.EIP712Domain,[a]:W[a]};return[s,{domain:Yt(e),message:s,primaryType:a,types:c}]}function Jt(r){let{publicKey:e,chainId:t,primaryType:n,brokerId:i,expiration:a=365}=r,s=Date.now(),c={brokerId:i,orderlyKey:e,scope:"read,trading",chainId:t,timestamp:s,expiration:s+1e3*60*60*24*a},u={EIP712Domain:W.EIP712Domain,[n]:W[n]},l={domain:Yt(t),message:c,primaryType:n,types:u};return[c,l]}function Qt(r){let{chainId:e,settlePnlNonce:t,domain:n,brokerId:i}=r,a="SettlePnl",s=new Date().getTime(),c={EIP712Domain:W.EIP712Domain,[a]:W[a]},u={brokerId:i,chainId:e,timestamp:s,settleNonce:t};return[u,{domain:n,message:u,primaryType:a,types:c}]}f();var tt=[{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 er=[{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 pe=class{constructor(e){this.configStore=e}getContractInfoByEnv(){return{usdcAddress:$t,usdcAbi:tt,vaultAddress:Gt,vaultAbi:er,verifyContractAddress:Xt,erc20Abi:tt}}};f();f();var rt=class{constructor(e=[],t={}){this.providers=e;this.services=t;this.injectProperties={}}register(...e){this.providers.push(...e),e.forEach(t=>{let n=t;n instanceof Function&&(n=new t),this.add(n)})}registerByName(e,t){let n=t;n instanceof Function&&(n=new t),this.addByName(e,n)}get(e){return this.services[e]}getAll(){return Object.assign({},this.services)}add(e){return this.addByName(e.constructor.name,e)}addByName(e,t){return this.services[e]=t,this.services[e.toLowerCase()]=t,this.injectIntoProperties(t,e),this.get(e)}inject(e,t,n){e&&n&&(e[t]=n)}injectIntoProperties(e,t=e.constructor.name){this.getInjectProperty(t.toLowerCase()).forEach(n=>{this.inject(n.target,n.propertyKey,e)})}getInjectProperty(e){return this.injectProperties[e]||(this.injectProperties[e]=[]),this.injectProperties[e]}},tr=rt;var nt=class r{static getContainer(){return r.container||(r.container=new tr),r.container}static register(...e){this.getContainer().register(...e)}static registerByName(e,t){this.getContainer().registerByName(e,t)}static get(e){return this.getContainer().get(e)}static getOr(e,t){return this.getContainer().get(e)||r.registerByName(e,t),t}static getAll(){return this.getContainer().getAll()}constructor(){}},yn=nt;f();import{AccountStatusEnum as B}from"@orderly.network/types";import dn from"eventemitter3";f();import{ethers as rr}from"ethers";var Se=class{constructor(e,t,n){this.configStore=e;this.contractManger=t;this.account=n}async withdraw(e){if(!this.account.walletClient)throw new Error("walletClient is undefined");if(!this.account.stateValue.address)throw new Error("account address is rqeuired");let{chainId:t,token:n,amount:i}=e,a="/v1/withdraw_request",s=await this.getWithdrawalNonce(),c=this.account.getDomain(!0),[u,l]=this._generateWithdrawMessage({chainId:t,receiver:this.account.stateValue.address,token:n,amount:this.account.walletClient.parseUnits(i.toString()),nonce:s,domain:c}),y={signature:await this.account.signTypedData(l),message:u,userAddress:this.account.stateValue.address,verifyingContract:c.verifyingContract},g={method:"POST",url:a,data:y},h=await this.account.signer.sign(g);return await this._simpleFetch(a,{method:"POST",body:JSON.stringify(y),headers:{"Content-Type":"application/json","orderly-account-id":this.account.stateValue.accountId,...h}})}_generateWithdrawMessage(e){let{chainId:t,receiver:n,token:i,amount:a,domain:s,nonce:c}=e,u="Withdraw",l=Date.now(),p={EIP712Domain:W.EIP712Domain,[u]:W[u]},y={brokerId:this.configStore.get("brokerId"),chainId:t,receiver:n,token:i,amount:a,timestamp:l,withdrawNonce:c};return[y,{domain:s,message:y,primaryType:u,types:p}]}async getWithdrawalNonce(){let e=Date.now().toString(),t="/v1/withdraw_nonce",n=[e,"GET",t].join(""),i=this.account.signer,{publicKey:a,signature:s}=await i.signText(n),c=await this._simpleFetch(t,{headers:{"orderly-account-id":this.account.stateValue.accountId,"orderly-key":a,"orderly-timestamp":e,"orderly-signature":s}});if(c.success)return c.data?.withdraw_nonce;throw new Error(c.message)}async getNativeBalance(e){let t=await this.account.walletClient?.getBalance(this.account.stateValue.address);return Ie(t,e?.decimals)}async getBalance(e,t){if(!this.account.walletClient)return"0";let n=this.contractManger.getContractInfoByEnv(),i=await this.account.walletClient?.call(e??n.usdcAddress,"balanceOf",[this.account.stateValue.address],{abi:n.usdcAbi});return Ie(i,t?.decimals)}async getBalanceByAddress(e){if(!this.account.walletClient)return"0";let t=this.contractManger.getContractInfoByEnv(),n=await this.account.walletClient?.call(e,"balanceOf",[this.account.stateValue.address],{abi:t.erc20Abi});return this.account.walletClient?.formatUnits(n)}async getAllowance(e,t){if(!this.account.walletClient)return"0";let n=this.contractManger.getContractInfoByEnv(),i=await this.account.walletClient?.call(e??n.usdcAddress,"allowance",[this.account.stateValue.address,t||n.vaultAddress],{abi:n.usdcAbi});return this.account.walletClient?.formatUnits(i)}async approve(e,t,n){if(!e)throw new Error("address is required");if(!this.account.walletClient)throw new Error("walletClient is undefined");let i=this.contractManger.getContractInfoByEnv(),a=typeof t<"u"&&t!==""?this.account.walletClient.parseUnits(t):rr.MaxUint256.toString();return await this.account.walletClient?.call(e,"approve",[n||i.vaultAddress,a],{abi:i.usdcAbi})}async approveByAddress(e){let{amount:t,address:n}=e;return this._approve(n,t)}async _approve(e,t){if(!this.account.walletClient)throw new Error("walletClient is undefined");let n=typeof t<"u"&&t!==""?this.account.walletClient.parseUnits(t):rr.MaxUint256.toString(),i=this.contractManger.getContractInfoByEnv();return await this.account.walletClient?.call(e,"approve",[i.vaultAddress,n],{abi:i.erc20Abi})}async deposit(e){if(!this.account.walletClient)throw new Error("walletClient is undefined");let t=this.configStore.get("brokerId");if(!t)throw new Error("[Assets]:brokerId is required");let n=this.contractManger.getContractInfoByEnv(),i={accountId:this.account.accountIdHashStr,brokerHash:Ee(t),tokenHash:Je("USDC"),tokenAmount:this.account.walletClient?.parseUnits(e)};return await this.account.walletClient?.sendTransaction(n.vaultAddress,"deposit",{from:this.account.stateValue.address,to:n.vaultAddress,data:[i],value:0n},{abi:n.vaultAbi})}async _simpleFetch(e,t={}){let n=`${this.configStore.get("apiBaseUrl")}${e}`;return fetch(n,t).then(i=>i.json())}get usdcAddress(){return this.contractManger.getContractInfoByEnv().usdcAddress}};var ke=class{constructor(e,t,n){this.configStore=e;this.keyStore=t;this.getWalletAdapter=n;this._ee=new dn;this._state={status:B.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.contractManger=new pe(e),this.assetsManager=new Se(e,this.contractManger,this),this._bindEvents()}logout(){}async setAddress(e,t){if(!e)throw new Error("address is required");this.keyStore.setAddress(e);let n={...this.stateValue,status:B.Connected,address:e,connectWallet:t?.wallet};return this._ee.emit("change:status",n),t&&(this.walletClient=this.getWalletAdapter({...t,address:e})),await this._checkAccount(e)}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get accountIdHashStr(){if(!this.address)throw new Error("address is error");let e=this.configStore.get("brokerId");return Ze(this.address,e)}get address(){return this.stateValue.address}get chainId(){return this.walletClient?.chainId}set position(e){let t={...this.stateValue,positon:e};this._ee.emit("change:status",t)}set orders(e){let t={...this.stateValue,orders:e};this._ee.emit("change:status",t)}_bindEvents(){this._ee.addListener("change:status",e=>{this._state=e})}async _checkAccount(e){let t;try{let n=await this._checkAccountExist(e);if(n&&n.account_id)this.keyStore.setAccountId(e,n.account_id),t={...this.stateValue,status:B.SignedIn,accountId:n.account_id,userId:n.user_id},this._ee.emit("change:status",t);else return t={...this.stateValue,status:B.NotSignedIn},this._ee.emit("change:status",t),B.NotSignedIn;let i=this.keyStore.getOrderlyKey();if(t={...this.stateValue,status:B.DisabledTrading},!i)return this._ee.emit("change:status",t),B.DisabledTrading;let a=await i.getPublicKey(),s=await this._checkOrderlyKeyState(n.account_id,a);if(s&&s.orderly_key&&s.key_status==="ACTIVE"){let c=Date.now(),u=s.expiration;if(c>u)return this.keyStore.cleanKey(e,"orderlyKey"),B.DisabledTrading;let l={...this.stateValue,status:B.EnableTrading};return this._ee.emit("change:status",l),B.EnableTrading}return this.keyStore.cleanKey(e,"orderlyKey"),B.NotConnected}catch{}return B.NotSignedIn}async _checkAccountExist(e){let t=this.configStore.get("brokerId"),n=await this._simpleFetch(`/v1/get_account?address=${e}&broker_id=${t}`);return n.success?n.data:null}async createAccount(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let e=await this._getRegisterationNonce(),t=this.stateValue.address;if(!t)throw new Error("address is undefined");let[n,i]=Zt({registrationNonce:e,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId")}),a=await this.signTypedData(i),s=await this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:a,message:n,userAddress:t}),headers:{"Content-Type":"application/json"}});if(s.success){this.keyStore.setAccountId(t,s.data.account_id);let c={...this.stateValue,status:B.DisabledTrading,accountId:s.data.account_id,userId:s.data.user_id};return this._ee.emit("change:status",c),s}}async signTypedData(e){return this.walletClient?await this.walletClient.signTypedData(this.stateValue.address,JSON.stringify(e)):Promise.reject("walletClient is undefined")}async createOrderlyKey(e){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(!this.walletClient)throw new Error("walletClient is undefined");let t="AddOrderlyKey",n=this.keyStore.generateKey(),i=await n.getPublicKey(),[a,s]=Jt({publicKey:i,chainId:this.walletClient.chainId,primaryType:t,expiration:e,brokerId:this.configStore.get("brokerId")}),c=this.stateValue.address;if(!c)throw new Error("address is undefined");let u=await this.signTypedData(s),l=await this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:u,message:a,userAddress:c}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(l.success){this.keyStore.setKey(c,n);let p={...this.stateValue,status:B.EnableTrading};return this._ee.emit("change:status",p),l}else throw new Error(l.message)}async settle(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let e=await this._getSettleNonce(),t=this.stateValue.address,n=this.getDomain(!0),i="/v1/settle_pnl",[a,s]=Qt({settlePnlNonce:e,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId"),domain:n}),u={signature:await this.signTypedData(s),message:a,userAddress:t,verifyingContract:n.verifyingContract},l={method:"POST",url:i,data:u},p=await this.signer.sign(l),y=await this._simpleFetch(i,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,...p}});if(y.success)return y;throw new Error(y.message)}async disconnect(){let e={...this.stateValue,status:B.NotConnected,accountId:void 0,userId:void 0,address:void 0};this._ee.emit("change:status",e)}async _checkOrderlyKeyState(e,t){let n=await this._simpleFetch(`/v1/get_orderly_key?account_id=${e}&orderly_key=${t}`);if(n.success)return n.data;throw new Error(n.message)}get signer(){return this._singer||(this._singer=new G(this.keyStore)),this._singer}get wallet(){return this.walletClient}async _getRegisterationNonce(){let e=await this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(e.success)return e.data?.registration_nonce;throw new Error(e.message)}async _getSettleNonce(){let e=Date.now().toString(),n=[e,"GET","/v1/settle_nonce"].join(""),i=this.signer,{publicKey:a,signature:s}=await i.signText(n),c=await this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":a,"orderly-timestamp":e,"orderly-signature":s}});if(c.success)return c.data?.settle_nonce;throw new Error(c.message)}async _simpleFetch(e,t={}){let n=`${this.configStore.get("apiBaseUrl")}${e}`;return fetch(n,t).then(i=>i.json())}getDomain(e){if(!this.walletClient)throw new Error("walletClient is undefined");return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:e?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)}};ke.instanceName="account";f();var hn={mainnet:{apiBaseUrl:"https://api-evm.orderly.org",publicWsUrl:"wss://ws-evm.orderly.org",privateWsUrl:"wss://ws-private-evm.orderly.org",operatorUrl:"https://operator-evm.orderly.org"},testnet:{apiBaseUrl:"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"}},it=class{constructor(e){let t=e.env||"prod",n=e.networkId||"mainnet",i=hn[n];this.map=new Map([["brokerId",e.brokerId],["env",t],["apiBaseUrl",i.apiBaseUrl],["publicWsUrl",i.publicWsUrl],["privateWsUrl",i.privateWsUrl],["operatorUrl",i.operatorUrl],["networkId",n]])}get(e){return this.map.get(e)}getOr(e,t){return this.map.get(e)??t}set(e,t){this.map.set(e,t)}clear(){throw new Error("Method not implemented.")}};f();f();import{BrowserProvider as fn,ethers as se,toNumber as gn}from"ethers";import{getParsedEthersError as nr}from"@enzoferey/ethers-error-parser";var at=class{constructor(e){this._chainId=parseInt(e.chain.id,16),this.provider=new fn(e.provider,"any"),this._address=e.address}parseUnits(e){return se.parseUnits(e,6).toString()}formatUnits(e){return se.formatUnits(e,6)}getBalance(e){return this.provider.getBalance(e).then(t=>t,t=>{})}deposit(e,t,n){throw new Error("Method not implemented.")}async call(e,t,n,i){let a=await this.provider?.getSigner();return new se.Contract(e,i.abi,a)[t].apply(null,n).catch(c=>{throw nr(c)})}get chainId(){return this._chainId}get addresses(){return this._address}async send(e,t){return await this.provider?.send(e,t)}async sendTransaction(e,t,n,i){let a=await this.provider?.getSigner();if(!a)throw new Error("singer is not exist");let c=new se.Contract(e,i.abi,this.provider).interface.encodeFunctionData(t,n.data),u={from:n.from,to:n.to,data:c,value:n.value};try{return await a.sendTransaction(u)}catch(l){throw nr(l)}}async estimateGas(e){let t=await this.provider.estimateGas(e);return gn(t)}async signTypedData(e,t){return await this.provider?.send("eth_signTypedData_v4",[e,t])}async verify(e,t){let{domain:n,types:i,message:a}=e,s=se.verifyTypedData(n,i,a,t)}on(e,t){this.provider?.on(e,t)}off(e,t){this.provider?.off(e,t)}getContract(e,t){return new se.Contract(e,t,this.provider)}};export{ke as Account,qt as BaseConfigStore,pe as BaseContractManager,Te as BaseKeyStore,$ as BaseOrderlyKeyPair,G as BaseSigner,it as DefaultConfigStore,at as EtherAdapter,Yi as EventEmitter,ue as LocalStorageStore,Ce as MemoryConfigStore,le as MockKeyStore,yn as SimpleDI,cn as getDefaultSigner,on as getMockSigner,zt as utils};
|
|
1
|
+
var ir=Object.create;var Be=Object.defineProperty;var ar=Object.getOwnPropertyDescriptor;var sr=Object.getOwnPropertyNames;var or=Object.getPrototypeOf,cr=Object.prototype.hasOwnProperty;var ur=(r,e)=>()=>(r&&(e=r(r=0)),e);var ee=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),lr=(r,e)=>{for(var t in e)Be(r,t,{get:e[t],enumerable:!0})},pr=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of sr(e))!cr.call(r,i)&&i!==t&&Be(r,i,{get:()=>e[i],enumerable:!(n=ar(e,i))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?ir(or(r)):{},pr(e||!r||!r.__esModule?Be(t,"default",{value:r,enumerable:!0}):t,r));var ct=ee(he=>{"use strict";f();he.byteLength=dr;he.toByteArray=fr;he.fromByteArray=wr;var O=[],K=[],yr=typeof Uint8Array<"u"?Uint8Array:Array,Ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(X=0,st=Ue.length;X<st;++X)O[X]=Ue[X],K[Ue.charCodeAt(X)]=X;var X,st;K["-".charCodeAt(0)]=62;K["_".charCodeAt(0)]=63;function ot(r){var e=r.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function dr(r){var e=ot(r),t=e[0],n=e[1];return(t+n)*3/4-n}function hr(r,e,t){return(e+t)*3/4-t}function fr(r){var e,t=ot(r),n=t[0],i=t[1],a=new yr(hr(r,n,i)),s=0,c=i>0?n-4:n,u;for(u=0;u<c;u+=4)e=K[r.charCodeAt(u)]<<18|K[r.charCodeAt(u+1)]<<12|K[r.charCodeAt(u+2)]<<6|K[r.charCodeAt(u+3)],a[s++]=e>>16&255,a[s++]=e>>8&255,a[s++]=e&255;return i===2&&(e=K[r.charCodeAt(u)]<<2|K[r.charCodeAt(u+1)]>>4,a[s++]=e&255),i===1&&(e=K[r.charCodeAt(u)]<<10|K[r.charCodeAt(u+1)]<<4|K[r.charCodeAt(u+2)]>>2,a[s++]=e>>8&255,a[s++]=e&255),a}function gr(r){return O[r>>18&63]+O[r>>12&63]+O[r>>6&63]+O[r&63]}function mr(r,e,t){for(var n,i=[],a=e;a<t;a+=3)n=(r[a]<<16&16711680)+(r[a+1]<<8&65280)+(r[a+2]&255),i.push(gr(n));return i.join("")}function wr(r){for(var e,t=r.length,n=t%3,i=[],a=16383,s=0,c=t-n;s<c;s+=a)i.push(mr(r,s,s+a>c?c:s+a));return n===1?(e=r[t-1],i.push(O[e>>2]+O[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(O[e>>10]+O[e>>4&63]+O[e<<2&63]+"=")),i.join("")}});var ut=ee(_e=>{"use strict";f();_e.read=function(r,e,t,n,i){var a,s,c=i*8-n-1,u=(1<<c)-1,l=u>>1,p=-7,y=t?i-1:0,g=t?-1:1,h=r[e+y];for(y+=g,a=h&(1<<-p)-1,h>>=-p,p+=c;p>0;a=a*256+r[e+y],y+=g,p-=8);for(s=a&(1<<-p)-1,a>>=-p,p+=n;p>0;s=s*256+r[e+y],y+=g,p-=8);if(a===0)a=1-l;else{if(a===u)return s?NaN:(h?-1:1)*(1/0);s=s+Math.pow(2,n),a=a-l}return(h?-1:1)*s*Math.pow(2,a-n)};_e.write=function(r,e,t,n,i,a){var s,c,u,l=a*8-i-1,p=(1<<l)-1,y=p>>1,g=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=n?0:a-1,m=n?1:-1,I=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,s=p):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),s+y>=1?e+=g/u:e+=g*Math.pow(2,1-y),e*u>=2&&(s++,u/=2),s+y>=p?(c=0,s=p):s+y>=1?(c=(e*u-1)*Math.pow(2,i),s=s+y):(c=e*Math.pow(2,y-1)*Math.pow(2,i),s=0));i>=8;r[t+h]=c&255,h+=m,c/=256,i-=8);for(s=s<<i|c,l+=i;l>0;r[t+h]=s&255,h+=m,s/=256,l-=8);r[t+h-m]|=I*128}});var Re=ee(re=>{"use strict";f();var Fe=ct(),te=ut(),lt=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;re.Buffer=o;re.SlowBuffer=Er;re.INSPECT_MAX_BYTES=50;var fe=2147483647;re.kMaxLength=fe;o.TYPED_ARRAY_SUPPORT=br();!o.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 br(){try{var 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(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}});Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}});function H(r){if(r>fe)throw new RangeError('The value "'+r+'" is invalid for option "size"');var e=new Uint8Array(r);return Object.setPrototypeOf(e,o.prototype),e}function o(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 De(r)}return dt(r,e,t)}o.poolSize=8192;function dt(r,e,t){if(typeof r=="string")return vr(r,e);if(ArrayBuffer.isView(r))return Ar(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(N(r,ArrayBuffer)||r&&N(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(N(r,SharedArrayBuffer)||r&&N(r.buffer,SharedArrayBuffer)))return Ke(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');var n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return o.from(n,e,t);var i=Tr(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return o.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)}o.from=function(r,e,t){return dt(r,e,t)};Object.setPrototypeOf(o.prototype,Uint8Array.prototype);Object.setPrototypeOf(o,Uint8Array);function ht(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 xr(r,e,t){return ht(r),r<=0?H(r):e!==void 0?typeof t=="string"?H(r).fill(e,t):H(r).fill(e):H(r)}o.alloc=function(r,e,t){return xr(r,e,t)};function De(r){return ht(r),H(r<0?0:Oe(r)|0)}o.allocUnsafe=function(r){return De(r)};o.allocUnsafeSlow=function(r){return De(r)};function vr(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var t=ft(r,e)|0,n=H(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function Me(r){for(var e=r.length<0?0:Oe(r.length)|0,t=H(e),n=0;n<e;n+=1)t[n]=r[n]&255;return t}function Ar(r){if(N(r,Uint8Array)){var e=new Uint8Array(r);return Ke(e.buffer,e.byteOffset,e.byteLength)}return Me(r)}function Ke(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');var n;return e===void 0&&t===void 0?n=new Uint8Array(r):t===void 0?n=new Uint8Array(r,e):n=new Uint8Array(r,e,t),Object.setPrototypeOf(n,o.prototype),n}function Tr(r){if(o.isBuffer(r)){var e=Oe(r.length)|0,t=H(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Ne(r.length)?H(0):Me(r);if(r.type==="Buffer"&&Array.isArray(r.data))return Me(r.data)}function Oe(r){if(r>=fe)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+fe.toString(16)+" bytes");return r|0}function Er(r){return+r!=r&&(r=0),o.alloc(+r)}o.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==o.prototype};o.compare=function(e,t){if(N(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),N(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var n=e.length,i=t.length,a=0,s=Math.min(n,i);a<s;++a)if(e[a]!==t[a]){n=e[a],i=t[a];break}return n<i?-1:i<n?1:0};o.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}};o.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return o.alloc(0);var n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;var i=o.allocUnsafe(t),a=0;for(n=0;n<e.length;++n){var s=e[n];if(N(s,Uint8Array))a+s.length>i.length?o.from(s).copy(i,a):Uint8Array.prototype.set.call(i,s,a);else if(o.isBuffer(s))s.copy(i,a);else throw new TypeError('"list" argument must be an Array of Buffers');a+=s.length}return i};function ft(r,e){if(o.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||N(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);var t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Pe(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return vt(r).length;default:if(i)return n?-1:Pe(r).length;e=(""+e).toLowerCase(),i=!0}}o.byteLength=ft;function Ir(r,e,t){var n=!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 Pr(this,e,t);case"utf8":case"utf-8":return mt(this,e,t);case"ascii":return Mr(this,e,t);case"latin1":case"binary":return Kr(this,e,t);case"base64":return _r(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Dr(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}o.prototype._isBuffer=!0;function Y(r,e,t){var n=r[e];r[e]=r[t],r[t]=n}o.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)Y(this,t,t+1);return this};o.prototype.swap32=function(){var e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)Y(this,t,t+3),Y(this,t+1,t+2);return this};o.prototype.swap64=function(){var e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)Y(this,t,t+7),Y(this,t+1,t+6),Y(this,t+2,t+5),Y(this,t+3,t+4);return this};o.prototype.toString=function(){var e=this.length;return e===0?"":arguments.length===0?mt(this,0,e):Ir.apply(this,arguments)};o.prototype.toLocaleString=o.prototype.toString;o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:o.compare(this,e)===0};o.prototype.inspect=function(){var e="",t=re.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"};lt&&(o.prototype[lt]=o.prototype.inspect);o.prototype.compare=function(e,t,n,i,a){if(N(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.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),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),a===void 0&&(a=this.length),t<0||n>e.length||i<0||a>this.length)throw new RangeError("out of range index");if(i>=a&&t>=n)return 0;if(i>=a)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,a>>>=0,this===e)return 0;for(var s=a-i,c=n-t,u=Math.min(s,c),l=this.slice(i,a),p=e.slice(t,n),y=0;y<u;++y)if(l[y]!==p[y]){s=l[y],c=p[y];break}return s<c?-1:c<s?1:0};function gt(r,e,t,n,i){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Ne(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=o.from(e,n)),o.isBuffer(e))return e.length===0?-1:pt(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):pt(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function pt(r,e,t,n,i){var a=1,s=r.length,c=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;a=2,s/=2,c/=2,t/=2}function u(h,m){return a===1?h[m]:h.readUInt16BE(m*a)}var l;if(i){var p=-1;for(l=t;l<s;l++)if(u(r,l)===u(e,p===-1?0:l-p)){if(p===-1&&(p=l),l-p+1===c)return p*a}else p!==-1&&(l-=l-p),p=-1}else for(t+c>s&&(t=s-c),l=t;l>=0;l--){for(var y=!0,g=0;g<c;g++)if(u(r,l+g)!==u(e,g)){y=!1;break}if(y)return l}return-1}o.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1};o.prototype.indexOf=function(e,t,n){return gt(this,e,t,n,!0)};o.prototype.lastIndexOf=function(e,t,n){return gt(this,e,t,n,!1)};function Cr(r,e,t,n){t=Number(t)||0;var i=r.length-t;n?(n=Number(n),n>i&&(n=i)):n=i;var a=e.length;n>a/2&&(n=a/2);for(var s=0;s<n;++s){var c=parseInt(e.substr(s*2,2),16);if(Ne(c))return s;r[t+s]=c}return s}function Sr(r,e,t,n){return ge(Pe(e,r.length-t),r,t,n)}function kr(r,e,t,n){return ge(Rr(e),r,t,n)}function Br(r,e,t,n){return ge(vt(e),r,t,n)}function Ur(r,e,t,n){return ge(Vr(e,r.length-t),r,t,n)}o.prototype.write=function(e,t,n,i){if(t===void 0)i="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")i=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var a=this.length-t;if((n===void 0||n>a)&&(n=a),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var s=!1;;)switch(i){case"hex":return Cr(this,e,t,n);case"utf8":case"utf-8":return Sr(this,e,t,n);case"ascii":case"latin1":case"binary":return kr(this,e,t,n);case"base64":return Br(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ur(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}};o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function _r(r,e,t){return e===0&&t===r.length?Fe.fromByteArray(r):Fe.fromByteArray(r.slice(e,t))}function mt(r,e,t){t=Math.min(r.length,t);for(var n=[],i=e;i<t;){var a=r[i],s=null,c=a>239?4:a>223?3:a>191?2:1;if(i+c<=t){var u,l,p,y;switch(c){case 1:a<128&&(s=a);break;case 2:u=r[i+1],(u&192)===128&&(y=(a&31)<<6|u&63,y>127&&(s=y));break;case 3:u=r[i+1],l=r[i+2],(u&192)===128&&(l&192)===128&&(y=(a&15)<<12|(u&63)<<6|l&63,y>2047&&(y<55296||y>57343)&&(s=y));break;case 4:u=r[i+1],l=r[i+2],p=r[i+3],(u&192)===128&&(l&192)===128&&(p&192)===128&&(y=(a&15)<<18|(u&63)<<12|(l&63)<<6|p&63,y>65535&&y<1114112&&(s=y))}}s===null?(s=65533,c=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|s&1023),n.push(s),i+=c}return Fr(n)}var yt=4096;function Fr(r){var e=r.length;if(e<=yt)return String.fromCharCode.apply(String,r);for(var t="",n=0;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=yt));return t}function Mr(r,e,t){var n="";t=Math.min(r.length,t);for(var i=e;i<t;++i)n+=String.fromCharCode(r[i]&127);return n}function Kr(r,e,t){var n="";t=Math.min(r.length,t);for(var i=e;i<t;++i)n+=String.fromCharCode(r[i]);return n}function Pr(r,e,t){var n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);for(var i="",a=e;a<t;++a)i+=Lr[r[a]];return i}function Dr(r,e,t){for(var n=r.slice(e,t),i="",a=0;a<n.length-1;a+=2)i+=String.fromCharCode(n[a]+n[a+1]*256);return i}o.prototype.slice=function(e,t){var n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);var i=this.subarray(e,t);return Object.setPrototypeOf(i,o.prototype),i};function T(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")}o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var i=this[e],a=1,s=0;++s<t&&(a*=256);)i+=this[e+s]*a;return i};o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var i=this[e+--t],a=1;t>0&&(a*=256);)i+=this[e+--t]*a;return i};o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e=e>>>0,t||T(e,1,this.length),this[e]};o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||T(e,2,this.length),this[e]|this[e+1]<<8};o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||T(e,2,this.length),this[e]<<8|this[e+1]};o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||T(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};o.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var i=this[e],a=1,s=0;++s<t&&(a*=256);)i+=this[e+s]*a;return a*=128,i>=a&&(i-=Math.pow(2,8*t)),i};o.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||T(e,t,this.length);for(var i=t,a=1,s=this[e+--i];i>0&&(a*=256);)s+=this[e+--i]*a;return a*=128,s>=a&&(s-=Math.pow(2,8*t)),s};o.prototype.readInt8=function(e,t){return e=e>>>0,t||T(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};o.prototype.readInt16LE=function(e,t){e=e>>>0,t||T(e,2,this.length);var n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};o.prototype.readInt16BE=function(e,t){e=e>>>0,t||T(e,2,this.length);var n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};o.prototype.readInt32LE=function(e,t){return e=e>>>0,t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};o.prototype.readInt32BE=function(e,t){return e=e>>>0,t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};o.prototype.readFloatLE=function(e,t){return e=e>>>0,t||T(e,4,this.length),te.read(this,e,!0,23,4)};o.prototype.readFloatBE=function(e,t){return e=e>>>0,t||T(e,4,this.length),te.read(this,e,!1,23,4)};o.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||T(e,8,this.length),te.read(this,e,!0,52,8)};o.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||T(e,8,this.length),te.read(this,e,!1,52,8)};function U(r,e,t,n,i,a){if(!o.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<a)throw new RangeError('"value" argument is out of bounds');if(t+n>r.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){var a=Math.pow(2,8*n)-1;U(this,e,t,n,a,0)}var s=1,c=0;for(this[t]=e&255;++c<n&&(s*=256);)this[t+c]=e/s&255;return t+n};o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){var a=Math.pow(2,8*n)-1;U(this,e,t,n,a,0)}var s=n-1,c=1;for(this[t+s]=e&255;--s>=0&&(c*=256);)this[t+s]=e/c&255;return t+n};o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,1,255,0),this[t]=e&255,t+1};o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||U(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};o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||U(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};o.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){var a=Math.pow(2,8*n-1);U(this,e,t,n,a-1,-a)}var s=0,c=1,u=0;for(this[t]=e&255;++s<n&&(c*=256);)e<0&&u===0&&this[t+s-1]!==0&&(u=1),this[t+s]=(e/c>>0)-u&255;return t+n};o.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){var a=Math.pow(2,8*n-1);U(this,e,t,n,a-1,-a)}var s=n-1,c=1,u=0;for(this[t+s]=e&255;--s>=0&&(c*=256);)e<0&&u===0&&this[t+s+1]!==0&&(u=1),this[t+s]=(e/c>>0)-u&255;return t+n};o.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};o.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};o.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||U(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};o.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||U(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};o.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||U(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};function wt(r,e,t,n,i,a){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function bt(r,e,t,n,i){return e=+e,t=t>>>0,i||wt(r,e,t,4,34028234663852886e22,-34028234663852886e22),te.write(r,e,t,n,23,4),t+4}o.prototype.writeFloatLE=function(e,t,n){return bt(this,e,t,!0,n)};o.prototype.writeFloatBE=function(e,t,n){return bt(this,e,t,!1,n)};function xt(r,e,t,n,i){return e=+e,t=t>>>0,i||wt(r,e,t,8,17976931348623157e292,-17976931348623157e292),te.write(r,e,t,n,52,8),t+8}o.prototype.writeDoubleLE=function(e,t,n){return xt(this,e,t,!0,n)};o.prototype.writeDoubleBE=function(e,t,n){return xt(this,e,t,!1,n)};o.prototype.copy=function(e,t,n,i){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i<n&&(i=n),i===n||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t<i-n&&(i=e.length-t+n);var a=i-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,i):Uint8Array.prototype.set.call(e,this.subarray(n,i),t),a};o.prototype.fill=function(e,t,n,i){if(typeof e=="string"){if(typeof t=="string"?(i=t,t=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!o.isEncoding(i))throw new TypeError("Unknown encoding: "+i);if(e.length===1){var a=e.charCodeAt(0);(i==="utf8"&&a<128||i==="latin1")&&(e=a)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;t=t>>>0,n=n===void 0?this.length:n>>>0,e||(e=0);var s;if(typeof e=="number")for(s=t;s<n;++s)this[s]=e;else{var c=o.isBuffer(e)?e:o.from(e,i),u=c.length;if(u===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<n-t;++s)this[s+t]=c[s%u]}return this};var Or=/[^+/0-9A-Za-z-_]/g;function Nr(r){if(r=r.split("=")[0],r=r.trim().replace(Or,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Pe(r,e){e=e||1/0;for(var t,n=r.length,i=null,a=[],s=0;s<n;++s){if(t=r.charCodeAt(s),t>55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&a.push(239,191,189);continue}else if(s+1===n){(e-=3)>-1&&a.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&a.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&a.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;a.push(t)}else if(t<2048){if((e-=2)<0)break;a.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;a.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;a.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return a}function Rr(r){for(var e=[],t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function Vr(r,e){for(var t,n,i,a=[],s=0;s<r.length&&!((e-=2)<0);++s)t=r.charCodeAt(s),n=t>>8,i=t%256,a.push(i),a.push(n);return a}function vt(r){return Fe.toByteArray(Nr(r))}function ge(r,e,t,n){for(var i=0;i<n&&!(i+t>=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function N(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Ne(r){return r!==r}var Lr=function(){for(var r="0123456789abcdef",e=new Array(256),t=0;t<16;++t)for(var n=t*16,i=0;i<16;++i)e[n+i]=r[t]+r[i];return e}()});var Ct=ee((En,It)=>{"use strict";f();var v=It.exports={},R,V;function Ve(){throw new Error("setTimeout has not been defined")}function Le(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?R=setTimeout:R=Ve}catch{R=Ve}try{typeof clearTimeout=="function"?V=clearTimeout:V=Le}catch{V=Le}})();function At(r){if(R===setTimeout)return setTimeout(r,0);if((R===Ve||!R)&&setTimeout)return R=setTimeout,setTimeout(r,0);try{return R(r,0)}catch{try{return R.call(null,r,0)}catch{return R.call(this,r,0)}}}function Wr(r){if(V===clearTimeout)return clearTimeout(r);if((V===Le||!V)&&clearTimeout)return V=clearTimeout,clearTimeout(r);try{return V(r)}catch{try{return V.call(null,r)}catch{return V.call(this,r)}}}var j=[],ne=!1,Z,me=-1;function Hr(){!ne||!Z||(ne=!1,Z.length?j=Z.concat(j):me=-1,j.length&&Tt())}function Tt(){if(!ne){var r=At(Hr);ne=!0;for(var e=j.length;e;){for(Z=j,j=[];++me<e;)Z&&Z[me].run();me=-1,e=j.length}Z=null,ne=!1,Wr(r)}}v.nextTick=function(r){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];j.push(new Et(r,e)),j.length===1&&!ne&&At(Tt)};function Et(r,e){this.fun=r,this.array=e}Et.prototype.run=function(){this.fun.apply(null,this.array)};v.title="browser";v.browser=!0;v.env={};v.argv=[];v.version="";v.versions={};function z(){}v.on=z;v.addListener=z;v.once=z;v.off=z;v.removeListener=z;v.removeAllListeners=z;v.emit=z;v.prependListener=z;v.prependOnceListener=z;v.listeners=function(r){return[]};v.binding=function(r){throw new Error("process.binding is not supported")};v.cwd=function(){return"/"};v.chdir=function(r){throw new Error("process.chdir is not supported")};v.umask=function(){return 0}});var w,b,Cn,f=ur(()=>{"use strict";w=de(Re()),b=de(Ct()),Cn=function(r){function e(){var n=this||self;return delete r.prototype.__magic__,n}if(typeof globalThis=="object")return globalThis;if(this)return e();r.defineProperty(r.prototype,"__magic__",{configurable:!0,get:e});var t=__magic__;return t}(Object)});var kt=ee((kn,St)=>{"use strict";f();function jr(r){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),t=0;t<e.length;t++)e[t]=255;for(var n=0;n<r.length;n++){var i=r.charAt(n),a=i.charCodeAt(0);if(e[a]!==255)throw new TypeError(i+" is ambiguous");e[a]=n}var s=r.length,c=r.charAt(0),u=Math.log(s)/Math.log(256),l=Math.log(256)/Math.log(s);function p(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 m=0,I=0,A=0,C=h.length;A!==C&&h[A]===0;)A++,m++;for(var _=(C-A)*l+1>>>0,S=new Uint8Array(_);A!==C;){for(var M=h[A],D=0,F=_-1;(M!==0||D<I)&&F!==-1;F--,D++)M+=256*S[F]>>>0,S[F]=M%s>>>0,M=M/s>>>0;if(M!==0)throw new Error("Non-zero carry");I=D,A++}for(var P=_-I;P!==_&&S[P]===0;)P++;for(var ye=c.repeat(m);P<_;++P)ye+=r.charAt(S[P]);return ye}function y(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var m=0,I=0,A=0;h[m]===c;)I++,m++;for(var C=(h.length-m)*u+1>>>0,_=new Uint8Array(C);h[m];){var S=e[h.charCodeAt(m)];if(S===255)return;for(var M=0,D=C-1;(S!==0||M<A)&&D!==-1;D--,M++)S+=s*_[D]>>>0,_[D]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");A=M,m++}for(var F=C-A;F!==C&&_[F]===0;)F++;for(var P=new Uint8Array(I+(C-F)),ye=I;F!==C;)P[ye++]=_[F++];return P}function g(h){var m=y(h);if(m)return m;throw new Error("Non-base"+s+" character")}return{encode:p,decodeUnsafe:y,decode:g}}St.exports=jr});var Ut=ee((Un,Bt)=>{"use strict";f();var zr=kt(),qr="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";Bt.exports=zr(qr)});f();f();f();var ce=de(Ut());f();var E=2n**255n-19n,ie=2n**252n+27742317777372353535851937790883648493n,We=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,He=0x6666666666666666666666666666666666666666666666666666666666666658n,we={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:E,n:ie,h:8,Gx:We,Gy:He},k=(r="")=>{throw new Error(r)},Pt=r=>typeof r=="string",ve=(r,e)=>!(r instanceof Uint8Array)||typeof e=="number"&&e>0&&r.length!==e?k("Uint8Array expected"):r,ae=r=>new Uint8Array(r),Ae=(r,e)=>ve(Pt(r)?qe(r):ae(r),e),d=(r,e=E)=>{let t=r%e;return t>=0n?t:e+t},_t=r=>r instanceof q?r:k("Point expected"),Ft,q=class r{constructor(e,t,n,i){this.ex=e,this.ey=t,this.ez=n,this.et=i}static fromAffine(e){return new r(e.x,e.y,1n,d(e.x*e.y))}static fromHex(e,t=!0){let{d:n}=we;e=Ae(e,32);let i=e.slice();i[31]=e[31]&-129;let a=Nt(i);a===0n||(t&&!(0n<a&&a<E)&&k("bad y coord 1"),!t&&!(0n<a&&a<2n**256n)&&k("bad y coord 2"));let s=d(a*a),c=d(s-1n),u=d(n*s+1n),{isValid:l,value:p}=Gr(c,u);l||k("bad y coordinate 3");let y=(p&1n)===1n;return(e[31]&128)!==0!==y&&(p=d(-p)),new r(p,a,1n,d(p*a))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(e){let{ex:t,ey:n,ez:i}=this,{ex:a,ey:s,ez:c}=_t(e),u=d(t*c),l=d(a*i),p=d(n*c),y=d(s*i);return u===l&&p===y}is0(){return this.equals(be)}negate(){return new r(d(-this.ex),this.ey,this.ez,d(-this.et))}double(){let{ex:e,ey:t,ez:n}=this,{a:i}=we,a=d(e*e),s=d(t*t),c=d(2n*d(n*n)),u=d(i*a),l=e+t,p=d(d(l*l)-a-s),y=u+s,g=y-c,h=u-s,m=d(p*g),I=d(y*h),A=d(p*h),C=d(g*y);return new r(m,I,C,A)}add(e){let{ex:t,ey:n,ez:i,et:a}=this,{ex:s,ey:c,ez:u,et:l}=_t(e),{a:p,d:y}=we,g=d(t*s),h=d(n*c),m=d(a*y*l),I=d(i*u),A=d((t+n)*(s+c)-g-h),C=d(I-m),_=d(I+m),S=d(h-p*g),M=d(A*C),D=d(_*S),F=d(A*S),P=d(C*_);return new r(M,D,P,F)}mul(e,t=!0){if(e===0n)return t===!0?k("cannot multiply by 0"):be;if(typeof e=="bigint"&&0n<e&&e<ie||k("invalid scalar, must be < L"),!t&&this.is0()||e===1n)return this;if(this.equals(Q))return Qr(e).p;let n=be,i=Q;for(let a=this;e>0n;a=a.double(),e>>=1n)e&1n?n=n.add(a):t&&(i=i.add(a));return n}multiply(e){return this.mul(e)}clearCofactor(){return this.mul(BigInt(we.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let e=this.mul(ie/2n,!1).double();return ie%2n&&(e=e.add(this)),e.is0()}toAffine(){let{ex:e,ey:t,ez:n}=this;if(this.is0())return{x:0n,y:0n};let i=Rt(n);return d(n*i)!==1n&&k("invalid inverse"),{x:d(e*i),y:d(t*i)}}toRawBytes(){let{x:e,y:t}=this.toAffine(),n=Ot(t);return n[31]|=e&1n?128:0,n}toHex(){return ze(this.toRawBytes())}};q.BASE=new q(We,He,1n,d(We*He));q.ZERO=new q(0n,1n,1n,0n);var{BASE:Q,ZERO:be}=q,Dt=(r,e)=>r.toString(16).padStart(e,"0"),ze=r=>Array.from(r).map(e=>Dt(e,2)).join(""),qe=r=>{let e=r.length;(!Pt(r)||e%2)&&k("hex invalid 1");let t=ae(e/2);for(let n=0;n<t.length;n++){let i=n*2,a=r.slice(i,i+2),s=Number.parseInt(a,16);(Number.isNaN(s)||s<0)&&k("hex invalid 2"),t[n]=s}return t},Ot=r=>qe(Dt(r,32*2)).reverse(),Nt=r=>BigInt("0x"+ze(ae(ve(r)).reverse())),xe=(...r)=>{let e=ae(r.reduce((n,i)=>n+ve(i).length,0)),t=0;return r.forEach(n=>{e.set(n,t),t+=n.length}),e},Rt=(r,e=E)=>{(r===0n||e<=0n)&&k("no inverse n="+r+" mod="+e);let t=d(r,e),n=e,i=0n,a=1n,s=1n,c=0n;for(;t!==0n;){let u=n/t,l=n%t,p=i-s*u,y=a-c*u;n=t,t=l,i=s,a=c,s=p,c=y}return n===1n?d(i,e):k("no inverse")},L=(r,e)=>{let t=r;for(;e-- >0n;)t*=t,t%=E;return t},$r=r=>{let t=r*r%E*r%E,n=L(t,2n)*t%E,i=L(n,1n)*r%E,a=L(i,5n)*i%E,s=L(a,10n)*a%E,c=L(s,20n)*s%E,u=L(c,40n)*c%E,l=L(u,80n)*u%E,p=L(l,80n)*u%E,y=L(p,10n)*a%E;return{pow_p_5_8:L(y,2n)*r%E,b2:t}},Mt=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Gr=(r,e)=>{let t=d(e*e*e),n=d(t*t*e),i=$r(r*n).pow_p_5_8,a=d(r*t*i),s=d(e*a*a),c=a,u=d(a*Mt),l=s===r,p=s===d(-r),y=s===d(-r*Mt);return l&&(a=c),(p||y)&&(a=u),(d(a)&1n)===1n&&(a=d(-a)),{isValid:l||p,value:a}},je=r=>d(Nt(r),ie),oe,$e=(...r)=>Xe.sha512Async(...r),Vt=(...r)=>typeof oe=="function"?oe(...r):k("etc.sha512Sync not set"),Lt=r=>{let e=r.slice(0,32);e[0]&=248,e[31]&=127,e[31]|=64;let t=r.slice(32,64),n=je(e),i=Q.mul(n),a=i.toRawBytes();return{head:e,prefix:t,scalar:n,point:i,pointBytes:a}},Ge=r=>$e(Ae(r,32)).then(Lt),Xr=r=>Lt(Vt(Ae(r,32))),Wt=r=>Ge(r).then(e=>e.pointBytes);function Yr(r,e){return r?$e(e.hashable).then(e.finish):e.finish(Vt(e.hashable))}var Zr=(r,e,t)=>{let{pointBytes:n,scalar:i}=r,a=je(e),s=Q.mul(a).toRawBytes();return{hashable:xe(s,n,t),finish:l=>{let p=d(a+je(l)*i,ie);return ve(xe(s,Ot(p)),64)}}},Ht=async(r,e)=>{let t=Ae(r),n=await Ge(e),i=await $e(n.prefix,t);return Yr(!0,Zr(n,i,t))};var Kt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Xe={bytesToHex:ze,hexToBytes:qe,concatBytes:xe,mod:d,invert:Rt,randomBytes:r=>{let e=Kt();return e||k("crypto.getRandomValues must be defined"),e.getRandomValues(ae(r))},sha512Async:async(...r)=>{let e=Kt();e||k("crypto.subtle or etc.sha512Async must be defined");let t=xe(...r);return ae(await e.subtle.digest("SHA-512",t.buffer))},sha512Sync:void 0};Object.defineProperties(Xe,{sha512Sync:{configurable:!1,get(){return oe},set(r){oe||(oe=r)}}});var jt={getExtendedPublicKeyAsync:Ge,getExtendedPublicKey:Xr,randomPrivateKey:()=>Xe.randomBytes(32),precompute(r=8,e=Q){return e.multiply(3n),e}},J=8,Jr=()=>{let r=[],e=256/J+1,t=Q,n=t;for(let i=0;i<e;i++){n=t,r.push(n);for(let a=1;a<2**(J-1);a++)n=n.add(t),r.push(n);t=n.double()}return r},Qr=r=>{let e=Ft||(Ft=Jr()),t=(p,y)=>{let g=y.negate();return p?g:y},n=be,i=Q,a=1+256/J,s=2**(J-1),c=BigInt(2**J-1),u=2**J,l=BigInt(J);for(let p=0;p<a;p++){let y=p*s,g=Number(r&c);r>>=l,g>s&&(g-=u,r+=1n);let h=y,m=y+Math.abs(g)-1,I=p%2!==0,A=g<0;g===0?i=i.add(t(I,e[h])):n=n.add(t(A,e[m]))}return{p:n,f:i}};var $=class r{static generateKey(){let e,t;do e=jt.randomPrivateKey(),t=(0,ce.encode)(e);while(t.length!==44);return new r(t)}constructor(e){this.secretKey=e;let t=(0,ce.decode)(e);this.privateKey=w.Buffer.from(t).toString("hex")}async sign(e){return await Ht(e,this.privateKey)}async getPublicKey(){let e=await Wt(this.privateKey);return`ed25519:${(0,ce.encode)(e)}`}toString(){return this.privateKey}};var Te=class{constructor(e="testnet"){this.networkId=e}get keyPrefix(){return`orderly_${this.networkId}_`}},ue=class extends Te{getOrderlyKey(e){let t;if(e)t=this.getItem(e,"orderlyKey");else{let n=this.getAddress();if(!n)return null;t=this.getItem(n,"orderlyKey")}return t?new $(t):null}getAccountId(e){return this.getItem(e,"accountId")}setAccountId(e,t){this.setItem(e,{accountId:t})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(e){localStorage.setItem(`${this.keyPrefix}address`,e)}generateKey(){return $.generateKey()}setKey(e,t){this.setItem(e,{orderlyKey:t.secretKey})}cleanAllKey(e){localStorage.removeItem(`${this.keyPrefix}${e}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(e,t){let n=this.getItem(e);delete n[t],localStorage.setItem(`${this.keyPrefix}${e}`,JSON.stringify(n))}setItem(e,t){let n=`${this.keyPrefix}${e}`,i=localStorage.getItem(n);i?i=JSON.parse(i):i={},localStorage.setItem(n,JSON.stringify({...i,...t}))}getItem(e,t){let n=`${this.keyPrefix}${e}`,i=localStorage.getItem(n);return i?i=JSON.parse(i):i={},typeof t>"u"?i:i[t]}},le=class{constructor(e){this.secretKey=e}generateKey(){return new $(this.secretKey)}getOrderlyKey(){return new $(this.secretKey)}getAccountId(){return""}setAccountId(e){}getAddress(){return""}setAddress(e){}setKey(e,t){}cleanAllKey(){}cleanKey(e){}};f();var zt={};lr(zt,{base64url:()=>Ye,calculateStringHash:()=>Qe,formatByUnits:()=>Ie,parseAccountId:()=>Ze,parseBrokerHash:()=>Ee,parseTokenHash:()=>Je,parseUnits:()=>sn});f();import{keccak256 as tn,AbiCoder as rn,solidityPackedKeccak256 as nn,formatUnits as an}from"ethers-v6";import{parseUnits as sn}from"ethers-v6";var Ye=function(r){return r.replace(/\+/g,"-").replace(/\//g,"_")};function Ee(r){return Qe(r)}function Ze(r,e){let t=rn.defaultAbiCoder();return tn(t.encode(["address","bytes32"],[r,Ee(e)]))}function Je(r){return Qe(r)}function Qe(r){return nn(["string"],[r])}function Ie(r,e="ether"){return an(r,e)}var et=de(Re()),G=class{constructor(e){this.keyStore=e}async sign(e){let t=Date.now().toString(),n=[t,e.method.toUpperCase(),e.url].join("");e.data&&Object.keys(e.data).length&&(n+=JSON.stringify(e.data));let{signature:i,publicKey:a}=await this.signText(n);return{"orderly-key":a,"orderly-timestamp":t,"orderly-signature":i}}async signText(e){let t=this.keyStore.getOrderlyKey();if(!t)throw new Error("orderlyKeyPair is not defined");let n=et.Buffer.from(e),i=await t.sign(n),a=et.Buffer.from(i).toString("base64");return{signature:Ye(a),publicKey:await t.getPublicKey()}}};import{default as Yi}from"eventemitter3";f();f();var Ce=class{constructor(e){this._restore(e)}_restore(e){let t=e?.brokerId||"woofi_pro",n=e?.networkId||"mainnet";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",t],["env","dev-evm"],["networkId",n],["PROD_URL",["dex-iap-evm.woo.org","dex-evm.woo.org"]]])}get(e){return this.map.get(e)}getOr(e,t){return this.map.get(e)??t}set(e,t){this.map.set(e,t)}clear(){}},qt=class extends Ce{constructor(t){super();this.configMap=t}};f();var W={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"}]},$t="0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291",Gt="0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D",Xt="0x1826B75e2ef249173FC735149AE4B8e9ea10abff";var on=r=>{let e=new le(r||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new G(e)},cn=()=>{if(typeof window>"u")throw new Error("the default signer only supports browsers.");let r=new ue("");return new G(r)};function un(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function Yt(r,e){return{name:"Orderly",version:"1",chainId:r,verifyingContract:e?un():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function Zt(r){let{chainId:e,registrationNonce:t,brokerId:n}=r,i=Date.now(),a="Registration",s={brokerId:n,chainId:e,timestamp:i,registrationNonce:t},c={EIP712Domain:W.EIP712Domain,[a]:W[a]};return[s,{domain:Yt(e),message:s,primaryType:a,types:c}]}function Jt(r){let{publicKey:e,chainId:t,primaryType:n,brokerId:i,expiration:a=365}=r,s=Date.now(),c={brokerId:i,orderlyKey:e,scope:"read,trading",chainId:t,timestamp:s,expiration:s+1e3*60*60*24*a},u={EIP712Domain:W.EIP712Domain,[n]:W[n]},l={domain:Yt(t),message:c,primaryType:n,types:u};return[c,l]}function Qt(r){let{chainId:e,settlePnlNonce:t,domain:n,brokerId:i}=r,a="SettlePnl",s=new Date().getTime(),c={EIP712Domain:W.EIP712Domain,[a]:W[a]},u={brokerId:i,chainId:e,timestamp:s,settleNonce:t};return[u,{domain:n,message:u,primaryType:a,types:c}]}f();var tt=[{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 er=[{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 pe=class{constructor(e){this.configStore=e}getContractInfoByEnv(){return{usdcAddress:$t,usdcAbi:tt,vaultAddress:Gt,vaultAbi:er,verifyContractAddress:Xt,erc20Abi:tt}}};f();f();var rt=class{constructor(e=[],t={}){this.providers=e;this.services=t;this.injectProperties={}}register(...e){this.providers.push(...e),e.forEach(t=>{let n=t;n instanceof Function&&(n=new t),this.add(n)})}registerByName(e,t){let n=t;n instanceof Function&&(n=new t),this.addByName(e,n)}get(e){return this.services[e]}getAll(){return Object.assign({},this.services)}add(e){return this.addByName(e.constructor.name,e)}addByName(e,t){return this.services[e]=t,this.services[e.toLowerCase()]=t,this.injectIntoProperties(t,e),this.get(e)}inject(e,t,n){e&&n&&(e[t]=n)}injectIntoProperties(e,t=e.constructor.name){this.getInjectProperty(t.toLowerCase()).forEach(n=>{this.inject(n.target,n.propertyKey,e)})}getInjectProperty(e){return this.injectProperties[e]||(this.injectProperties[e]=[]),this.injectProperties[e]}},tr=rt;var nt=class r{static getContainer(){return r.container||(r.container=new tr),r.container}static register(...e){this.getContainer().register(...e)}static registerByName(e,t){this.getContainer().registerByName(e,t)}static get(e){return this.getContainer().get(e)}static getOr(e,t){return this.getContainer().get(e)||r.registerByName(e,t),t}static getAll(){return this.getContainer().getAll()}constructor(){}},yn=nt;f();import{AccountStatusEnum as B}from"@orderly.network/types";import dn from"eventemitter3";f();import{ethers as rr}from"ethers-v6";var Se=class{constructor(e,t,n){this.configStore=e;this.contractManger=t;this.account=n}async withdraw(e){if(!this.account.walletClient)throw new Error("walletClient is undefined");if(!this.account.stateValue.address)throw new Error("account address is rqeuired");let{chainId:t,token:n,amount:i}=e,a="/v1/withdraw_request",s=await this.getWithdrawalNonce(),c=this.account.getDomain(!0),[u,l]=this._generateWithdrawMessage({chainId:t,receiver:this.account.stateValue.address,token:n,amount:this.account.walletClient.parseUnits(i.toString()),nonce:s,domain:c}),y={signature:await this.account.signTypedData(l),message:u,userAddress:this.account.stateValue.address,verifyingContract:c.verifyingContract},g={method:"POST",url:a,data:y},h=await this.account.signer.sign(g);return await this._simpleFetch(a,{method:"POST",body:JSON.stringify(y),headers:{"Content-Type":"application/json","orderly-account-id":this.account.stateValue.accountId,...h}})}_generateWithdrawMessage(e){let{chainId:t,receiver:n,token:i,amount:a,domain:s,nonce:c}=e,u="Withdraw",l=Date.now(),p={EIP712Domain:W.EIP712Domain,[u]:W[u]},y={brokerId:this.configStore.get("brokerId"),chainId:t,receiver:n,token:i,amount:a,timestamp:l,withdrawNonce:c};return[y,{domain:s,message:y,primaryType:u,types:p}]}async getWithdrawalNonce(){let e=Date.now().toString(),t="/v1/withdraw_nonce",n=[e,"GET",t].join(""),i=this.account.signer,{publicKey:a,signature:s}=await i.signText(n),c=await this._simpleFetch(t,{headers:{"orderly-account-id":this.account.stateValue.accountId,"orderly-key":a,"orderly-timestamp":e,"orderly-signature":s}});if(c.success)return c.data?.withdraw_nonce;throw new Error(c.message)}async getNativeBalance(e){let t=await this.account.walletClient?.getBalance(this.account.stateValue.address);return Ie(t,e?.decimals)}async getBalance(e,t){if(!this.account.walletClient)return"0";let n=this.contractManger.getContractInfoByEnv(),i=await this.account.walletClient?.call(e??n.usdcAddress,"balanceOf",[this.account.stateValue.address],{abi:n.usdcAbi});return Ie(i,t?.decimals)}async getBalanceByAddress(e){if(!this.account.walletClient)return"0";let t=this.contractManger.getContractInfoByEnv(),n=await this.account.walletClient?.call(e,"balanceOf",[this.account.stateValue.address],{abi:t.erc20Abi});return this.account.walletClient?.formatUnits(n)}async getAllowance(e,t){if(!this.account.walletClient)return"0";let n=this.contractManger.getContractInfoByEnv(),i=await this.account.walletClient?.call(e??n.usdcAddress,"allowance",[this.account.stateValue.address,t||n.vaultAddress],{abi:n.usdcAbi});return this.account.walletClient?.formatUnits(i)}async approve(e,t,n){if(!e)throw new Error("address is required");if(!this.account.walletClient)throw new Error("walletClient is undefined");let i=this.contractManger.getContractInfoByEnv(),a=typeof t<"u"&&t!==""?this.account.walletClient.parseUnits(t):rr.MaxUint256.toString();return await this.account.walletClient?.call(e,"approve",[n||i.vaultAddress,a],{abi:i.usdcAbi})}async approveByAddress(e){let{amount:t,address:n}=e;return this._approve(n,t)}async _approve(e,t){if(!this.account.walletClient)throw new Error("walletClient is undefined");let n=typeof t<"u"&&t!==""?this.account.walletClient.parseUnits(t):rr.MaxUint256.toString(),i=this.contractManger.getContractInfoByEnv();return await this.account.walletClient?.call(e,"approve",[i.vaultAddress,n],{abi:i.erc20Abi})}async deposit(e){if(!this.account.walletClient)throw new Error("walletClient is undefined");let t=this.configStore.get("brokerId");if(!t)throw new Error("[Assets]:brokerId is required");let n=this.contractManger.getContractInfoByEnv(),i={accountId:this.account.accountIdHashStr,brokerHash:Ee(t),tokenHash:Je("USDC"),tokenAmount:this.account.walletClient?.parseUnits(e)};return await this.account.walletClient?.sendTransaction(n.vaultAddress,"deposit",{from:this.account.stateValue.address,to:n.vaultAddress,data:[i],value:0n},{abi:n.vaultAbi})}async _simpleFetch(e,t={}){let n=`${this.configStore.get("apiBaseUrl")}${e}`;return fetch(n,t).then(i=>i.json())}get usdcAddress(){return this.contractManger.getContractInfoByEnv().usdcAddress}};var ke=class{constructor(e,t,n){this.configStore=e;this.keyStore=t;this.getWalletAdapter=n;this._ee=new dn;this._state={status:B.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.contractManger=new pe(e),this.assetsManager=new Se(e,this.contractManger,this),this._bindEvents()}logout(){}async setAddress(e,t){if(!e)throw new Error("address is required");this.keyStore.setAddress(e);let n={...this.stateValue,status:B.Connected,address:e,connectWallet:t?.wallet};return this._ee.emit("change:status",n),t&&(this.walletClient=this.getWalletAdapter({...t,address:e})),await this._checkAccount(e)}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get accountIdHashStr(){if(!this.address)throw new Error("address is error");let e=this.configStore.get("brokerId");return Ze(this.address,e)}get address(){return this.stateValue.address}get chainId(){return this.walletClient?.chainId}set position(e){let t={...this.stateValue,positon:e};this._ee.emit("change:status",t)}set orders(e){let t={...this.stateValue,orders:e};this._ee.emit("change:status",t)}_bindEvents(){this._ee.addListener("change:status",e=>{this._state=e})}async _checkAccount(e){let t;try{let n=await this._checkAccountExist(e);if(n&&n.account_id)this.keyStore.setAccountId(e,n.account_id),t={...this.stateValue,status:B.SignedIn,accountId:n.account_id,userId:n.user_id},this._ee.emit("change:status",t);else return t={...this.stateValue,status:B.NotSignedIn},this._ee.emit("change:status",t),B.NotSignedIn;let i=this.keyStore.getOrderlyKey();if(t={...this.stateValue,status:B.DisabledTrading},!i)return this._ee.emit("change:status",t),B.DisabledTrading;let a=await i.getPublicKey(),s=await this._checkOrderlyKeyState(n.account_id,a);if(s&&s.orderly_key&&s.key_status==="ACTIVE"){let c=Date.now(),u=s.expiration;if(c>u)return this.keyStore.cleanKey(e,"orderlyKey"),B.DisabledTrading;let l={...this.stateValue,status:B.EnableTrading};return this._ee.emit("change:status",l),B.EnableTrading}return this.keyStore.cleanKey(e,"orderlyKey"),B.NotConnected}catch{}return B.NotSignedIn}async _checkAccountExist(e){let t=this.configStore.get("brokerId"),n=await this._simpleFetch(`/v1/get_account?address=${e}&broker_id=${t}`);return n.success?n.data:null}async createAccount(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let e=await this._getRegisterationNonce(),t=this.stateValue.address;if(!t)throw new Error("address is undefined");let[n,i]=Zt({registrationNonce:e,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId")}),a=await this.signTypedData(i),s=await this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:a,message:n,userAddress:t}),headers:{"Content-Type":"application/json"}});if(s.success){this.keyStore.setAccountId(t,s.data.account_id);let c={...this.stateValue,status:B.DisabledTrading,accountId:s.data.account_id,userId:s.data.user_id};return this._ee.emit("change:status",c),s}}async signTypedData(e){return this.walletClient?await this.walletClient.signTypedData(this.stateValue.address,JSON.stringify(e)):Promise.reject("walletClient is undefined")}async createOrderlyKey(e){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(!this.walletClient)throw new Error("walletClient is undefined");let t="AddOrderlyKey",n=this.keyStore.generateKey(),i=await n.getPublicKey(),[a,s]=Jt({publicKey:i,chainId:this.walletClient.chainId,primaryType:t,expiration:e,brokerId:this.configStore.get("brokerId")}),c=this.stateValue.address;if(!c)throw new Error("address is undefined");let u=await this.signTypedData(s),l=await this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:u,message:a,userAddress:c}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(l.success){this.keyStore.setKey(c,n);let p={...this.stateValue,status:B.EnableTrading};return this._ee.emit("change:status",p),l}else throw new Error(l.message)}async settle(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let e=await this._getSettleNonce(),t=this.stateValue.address,n=this.getDomain(!0),i="/v1/settle_pnl",[a,s]=Qt({settlePnlNonce:e,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId"),domain:n}),u={signature:await this.signTypedData(s),message:a,userAddress:t,verifyingContract:n.verifyingContract},l={method:"POST",url:i,data:u},p=await this.signer.sign(l),y=await this._simpleFetch(i,{method:"POST",body:JSON.stringify(u),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,...p}});if(y.success)return y;throw new Error(y.message)}async disconnect(){let e={...this.stateValue,status:B.NotConnected,accountId:void 0,userId:void 0,address:void 0};this._ee.emit("change:status",e)}async _checkOrderlyKeyState(e,t){let n=await this._simpleFetch(`/v1/get_orderly_key?account_id=${e}&orderly_key=${t}`);if(n.success)return n.data;throw new Error(n.message)}get signer(){return this._singer||(this._singer=new G(this.keyStore)),this._singer}get wallet(){return this.walletClient}async _getRegisterationNonce(){let e=await this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(e.success)return e.data?.registration_nonce;throw new Error(e.message)}async _getSettleNonce(){let e=Date.now().toString(),n=[e,"GET","/v1/settle_nonce"].join(""),i=this.signer,{publicKey:a,signature:s}=await i.signText(n),c=await this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":a,"orderly-timestamp":e,"orderly-signature":s}});if(c.success)return c.data?.settle_nonce;throw new Error(c.message)}async _simpleFetch(e,t={}){let n=`${this.configStore.get("apiBaseUrl")}${e}`;return fetch(n,t).then(i=>i.json())}getDomain(e){if(!this.walletClient)throw new Error("walletClient is undefined");return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:e?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)}};ke.instanceName="account";f();var hn={mainnet:{apiBaseUrl:"https://api-evm.orderly.org",publicWsUrl:"wss://ws-evm.orderly.org",privateWsUrl:"wss://ws-private-evm.orderly.org",operatorUrl:"https://operator-evm.orderly.org"},testnet:{apiBaseUrl:"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"}},it=class{constructor(e){let t=e.env||"prod",n=e.networkId||"mainnet",i=hn[n];this.map=new Map([["brokerId",e.brokerId],["env",t],["apiBaseUrl",i.apiBaseUrl],["publicWsUrl",i.publicWsUrl],["privateWsUrl",i.privateWsUrl],["operatorUrl",i.operatorUrl],["networkId",n]])}get(e){return this.map.get(e)}getOr(e,t){return this.map.get(e)??t}set(e,t){this.map.set(e,t)}clear(){throw new Error("Method not implemented.")}};f();f();import{BrowserProvider as fn,ethers as se,toNumber as gn}from"ethers-v6";import{getParsedEthersError as nr}from"@enzoferey/ethers-error-parser";var at=class{constructor(e){this._chainId=parseInt(e.chain.id,16),this.provider=new fn(e.provider,"any"),this._address=e.address}parseUnits(e){return se.parseUnits(e,6).toString()}formatUnits(e){return se.formatUnits(e,6)}getBalance(e){return this.provider.getBalance(e).then(t=>t,t=>{})}deposit(e,t,n){throw new Error("Method not implemented.")}async call(e,t,n,i){let a=await this.provider?.getSigner();return new se.Contract(e,i.abi,a)[t].apply(null,n).catch(c=>{throw nr(c)})}get chainId(){return this._chainId}get addresses(){return this._address}async send(e,t){return await this.provider?.send(e,t)}async sendTransaction(e,t,n,i){let a=await this.provider?.getSigner();if(!a)throw new Error("singer is not exist");let c=new se.Contract(e,i.abi,this.provider).interface.encodeFunctionData(t,n.data),u={from:n.from,to:n.to,data:c,value:n.value};try{return await a.sendTransaction(u)}catch(l){throw nr(l)}}async estimateGas(e){let t=await this.provider.estimateGas(e);return gn(t)}async signTypedData(e,t){return await this.provider?.send("eth_signTypedData_v4",[e,t])}async verify(e,t){let{domain:n,types:i,message:a}=e,s=se.verifyTypedData(n,i,a,t)}on(e,t){this.provider?.on(e,t)}off(e,t){this.provider?.off(e,t)}getContract(e,t){return new se.Contract(e,t,this.provider)}};export{ke as Account,qt as BaseConfigStore,pe as BaseContractManager,Te as BaseKeyStore,$ as BaseOrderlyKeyPair,G as BaseSigner,it as DefaultConfigStore,at as EtherAdapter,Yi as EventEmitter,ue as LocalStorageStore,Ce as MemoryConfigStore,le as MockKeyStore,yn as SimpleDI,cn as getDefaultSigner,on as getMockSigner,zt as utils};
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
ieee754/index.js:
|