@orderly.network/core 0.0.21 → 0.0.23
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 -0
- package/dist/index.d.ts +2 -0
- 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.d.mts
CHANGED
|
@@ -383,6 +383,7 @@ declare class Web3WalletAdapter implements WalletAdapter {
|
|
|
383
383
|
interface EtherAdapterOptions {
|
|
384
384
|
provider: any;
|
|
385
385
|
label?: string;
|
|
386
|
+
getAddresses?: (address: string) => string;
|
|
386
387
|
chain: {
|
|
387
388
|
id: string;
|
|
388
389
|
};
|
|
@@ -393,6 +394,7 @@ declare class EtherAdapter implements WalletAdapter {
|
|
|
393
394
|
constructor(options: EtherAdapterOptions);
|
|
394
395
|
getBalance(address: string): Promise<any>;
|
|
395
396
|
deposit(from: string, to: string, amount: string): Promise<any>;
|
|
397
|
+
getAddresses(address: string): string;
|
|
396
398
|
get chainId(): number;
|
|
397
399
|
send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
|
|
398
400
|
verify(data: {
|
package/dist/index.d.ts
CHANGED
|
@@ -383,6 +383,7 @@ declare class Web3WalletAdapter implements WalletAdapter {
|
|
|
383
383
|
interface EtherAdapterOptions {
|
|
384
384
|
provider: any;
|
|
385
385
|
label?: string;
|
|
386
|
+
getAddresses?: (address: string) => string;
|
|
386
387
|
chain: {
|
|
387
388
|
id: string;
|
|
388
389
|
};
|
|
@@ -393,6 +394,7 @@ declare class EtherAdapter implements WalletAdapter {
|
|
|
393
394
|
constructor(options: EtherAdapterOptions);
|
|
394
395
|
getBalance(address: string): Promise<any>;
|
|
395
396
|
deposit(from: string, to: string, amount: string): Promise<any>;
|
|
397
|
+
getAddresses(address: string): string;
|
|
396
398
|
get chainId(): number;
|
|
397
399
|
send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
|
|
398
400
|
verify(data: {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var wt=Object.create;var ie=Object.defineProperty,It=Object.defineProperties,_t=Object.getOwnPropertyDescriptor,Et=Object.getOwnPropertyDescriptors,bt=Object.getOwnPropertyNames,ve=Object.getOwnPropertySymbols,Bt=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty,At=Object.prototype.propertyIsEnumerable;var _=Math.pow,Ne=(d,i,c)=>i in d?ie(d,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):d[i]=c,L=(d,i)=>{for(var c in i||(i={}))Oe.call(i,c)&&Ne(d,c,i[c]);if(ve)for(var c of ve(i))At.call(i,c)&&Ne(d,c,i[c]);return d},j=(d,i)=>It(d,Et(i));var St=(d,i)=>{for(var c in i)ie(d,c,{get:i[c],enumerable:!0})},Me=(d,i,c,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let p of bt(i))!Oe.call(d,p)&&p!==c&&ie(d,p,{get:()=>i[p],enumerable:!(l=_t(i,p))||l.enumerable});return d};var we=(d,i,c)=>(c=d!=null?wt(Bt(d)):{},Me(i||!d||!d.__esModule?ie(c,"default",{value:d,enumerable:!0}):c,d)),xt=d=>Me(ie({},"__esModule",{value:!0}),d);var b=(d,i,c)=>new Promise((l,p)=>{var h=f=>{try{g(c.next(f))}catch(B){p(B)}},o=f=>{try{g(c.throw(f))}catch(B){p(B)}},g=f=>f.done?l(f.value):Promise.resolve(f.value).then(h,o);g((c=c.apply(d,i)).next())});var Ut={};St(Ut,{Account:()=>ue,BaseConfigStore:()=>Ie,BaseKeyStore:()=>ae,BaseOrderlyKeyPair:()=>q,BaseSigner:()=>J,Contract:()=>re,EtherAdapter:()=>he,EventEmitter:()=>Ze.default,LocalStorageStore:()=>ee,MemoryConfigStore:()=>ce,MockKeyStore:()=>te,SimpleDI:()=>He,Web3WalletAdapter:()=>pe,getDefaultSigner:()=>Xe,getMockSigner:()=>Ge});module.exports=xt(Ut);var oe={},Re=!1;function Ct(){if(Re)return oe;Re=!0,oe.byteLength=g,oe.toByteArray=B,oe.fromByteArray=V;for(var d=[],i=[],c=typeof Uint8Array!="undefined"?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,h=l.length;p<h;++p)d[p]=l[p],i[l.charCodeAt(p)]=p;i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63;function o(y){var w=y.length;if(w%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var E=y.indexOf("=");E===-1&&(E=w);var K=E===w?0:4-E%4;return[E,K]}function g(y){var w=o(y),E=w[0],K=w[1];return(E+K)*3/4-K}function f(y,w,E){return(w+E)*3/4-E}function B(y){var w,E=o(y),K=E[0],R=E[1],T=new c(f(y,K,R)),D=0,F=R>0?K-4:K,M;for(M=0;M<F;M+=4)w=i[y.charCodeAt(M)]<<18|i[y.charCodeAt(M+1)]<<12|i[y.charCodeAt(M+2)]<<6|i[y.charCodeAt(M+3)],T[D++]=w>>16&255,T[D++]=w>>8&255,T[D++]=w&255;return R===2&&(w=i[y.charCodeAt(M)]<<2|i[y.charCodeAt(M+1)]>>4,T[D++]=w&255),R===1&&(w=i[y.charCodeAt(M)]<<10|i[y.charCodeAt(M+1)]<<4|i[y.charCodeAt(M+2)]>>2,T[D++]=w>>8&255,T[D++]=w&255),T}function S(y){return d[y>>18&63]+d[y>>12&63]+d[y>>6&63]+d[y&63]}function k(y,w,E){for(var K,R=[],T=w;T<E;T+=3)K=(y[T]<<16&16711680)+(y[T+1]<<8&65280)+(y[T+2]&255),R.push(S(K));return R.join("")}function V(y){for(var w,E=y.length,K=E%3,R=[],T=16383,D=0,F=E-K;D<F;D+=T)R.push(k(y,D,D+T>F?F:D+T));return K===1?(w=y[E-1],R.push(d[w>>2]+d[w<<4&63]+"==")):K===2&&(w=(y[E-2]<<8)+y[E-1],R.push(d[w>>10]+d[w>>4&63]+d[w<<2&63]+"=")),R.join("")}return oe}var de={},De=!1;function Tt(){if(De)return de;De=!0;return de.read=function(d,i,c,l,p){var h,o,g=p*8-l-1,f=(1<<g)-1,B=f>>1,S=-7,k=c?p-1:0,V=c?-1:1,y=d[i+k];for(k+=V,h=y&(1<<-S)-1,y>>=-S,S+=g;S>0;h=h*256+d[i+k],k+=V,S-=8);for(o=h&(1<<-S)-1,h>>=-S,S+=l;S>0;o=o*256+d[i+k],k+=V,S-=8);if(h===0)h=1-B;else{if(h===f)return o?NaN:(y?-1:1)*(1/0);o=o+Math.pow(2,l),h=h-B}return(y?-1:1)*o*Math.pow(2,h-l)},de.write=function(d,i,c,l,p,h){var o,g,f,B=h*8-p-1,S=(1<<B)-1,k=S>>1,V=p===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=l?0:h-1,w=l?1:-1,E=i<0||i===0&&1/i<0?1:0;for(i=Math.abs(i),isNaN(i)||i===1/0?(g=isNaN(i)?1:0,o=S):(o=Math.floor(Math.log(i)/Math.LN2),i*(f=Math.pow(2,-o))<1&&(o--,f*=2),o+k>=1?i+=V/f:i+=V*Math.pow(2,1-k),i*f>=2&&(o++,f/=2),o+k>=S?(g=0,o=S):o+k>=1?(g=(i*f-1)*Math.pow(2,p),o=o+k):(g=i*Math.pow(2,k-1)*Math.pow(2,p),o=0));p>=8;d[c+y]=g&255,y+=w,g/=256,p-=8);for(o=o<<p|g,B+=p;B>0;d[c+y]=o&255,y+=w,o/=256,B-=8);d[c+y-w]|=E*128},de}var G={},$e=!1;function Pt(){if($e)return G;$e=!0;let d=Ct(),i=Tt(),c=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;G.Buffer=o,G.SlowBuffer=R,G.INSPECT_MAX_BYTES=50;let l=2147483647;G.kMaxLength=l,o.TYPED_ARRAY_SUPPORT=p(),!o.TYPED_ARRAY_SUPPORT&&typeof console!="undefined"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function p(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch(r){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>l)throw new RangeError('The value "'+r+'" is invalid for option "size"');let 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 S(r)}return g(r,e,t)}o.poolSize=8192;function g(r,e,t){if(typeof r=="string")return k(r,e);if(ArrayBuffer.isView(r))return y(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(W(r,ArrayBuffer)||r&&W(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(W(r,SharedArrayBuffer)||r&&W(r.buffer,SharedArrayBuffer)))return w(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return o.from(n,e,t);let s=E(r);if(s)return s;if(typeof Symbol!="undefined"&&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 g(r,e,t)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function f(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 B(r,e,t){return f(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 B(r,e,t)};function S(r){return f(r),h(r<0?0:K(r)|0)}o.allocUnsafe=function(r){return S(r)},o.allocUnsafeSlow=function(r){return S(r)};function k(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=T(r,e)|0,n=h(t),s=n.write(r,e);return s!==t&&(n=n.slice(0,s)),n}function V(r){let e=r.length<0?0:K(r.length)|0,t=h(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function y(r){if(W(r,Uint8Array)){let e=new Uint8Array(r);return w(e.buffer,e.byteOffset,e.byteLength)}return V(r)}function w(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let 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 E(r){if(o.isBuffer(r)){let e=K(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"||fe(r.length)?h(0):V(r);if(r.type==="Buffer"&&Array.isArray(r.data))return V(r.data)}function K(r){if(r>=l)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+l.toString(16)+" bytes");return r|0}function R(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(W(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),W(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;let n=e.length,s=t.length;for(let a=0,u=Math.min(n,s);a<u;++a)if(e[a]!==t[a]){n=e[a],s=t[a];break}return n<s?-1:s<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);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let s=o.allocUnsafe(t),a=0;for(n=0;n<e.length;++n){let u=e[n];if(W(u,Uint8Array))a+u.length>s.length?(o.isBuffer(u)||(u=o.from(u)),u.copy(s,a)):Uint8Array.prototype.set.call(s,u,a);else if(o.isBuffer(u))u.copy(s,a);else throw new TypeError('"list" argument must be an Array of Buffers');a+=u.length}return s};function T(r,e){if(o.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||W(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let s=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return me(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return ke(r).length;default:if(s)return n?-1:me(r).length;e=(""+e).toLowerCase(),s=!0}}o.byteLength=T;function D(r,e,t){let 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 ut(this,e,t);case"utf8":case"utf-8":return Be(this,e,t);case"ascii":return at(this,e,t);case"latin1":case"binary":return ct(this,e,t);case"base64":return ot(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lt(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}o.prototype._isBuffer=!0;function F(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}o.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)F(this,t,t+1);return this},o.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)F(this,t,t+3),F(this,t+1,t+2);return this},o.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)F(this,t,t+7),F(this,t+1,t+6),F(this,t+2,t+5),F(this,t+3,t+4);return this},o.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Be(this,0,e):D.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(){let e="",t=G.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},c&&(o.prototype[c]=o.prototype.inspect),o.prototype.compare=function(e,t,n,s,a){if(W(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),s===void 0&&(s=0),a===void 0&&(a=this.length),t<0||n>e.length||s<0||a>this.length)throw new RangeError("out of range index");if(s>=a&&t>=n)return 0;if(s>=a)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,s>>>=0,a>>>=0,this===e)return 0;let u=a-s,m=n-t,x=Math.min(u,m),A=this.slice(s,a),C=e.slice(t,n);for(let I=0;I<x;++I)if(A[I]!==C[I]){u=A[I],m=C[I];break}return u<m?-1:m<u?1:0};function M(r,e,t,n,s){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,fe(t)&&(t=s?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(s)return-1;t=r.length-1}else if(t<0)if(s)t=0;else return-1;if(typeof e=="string"&&(e=o.from(e,n)),o.isBuffer(e))return e.length===0?-1:be(r,e,t,n,s);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?s?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):be(r,[e],t,n,s);throw new TypeError("val must be string, number or Buffer")}function be(r,e,t,n,s){let a=1,u=r.length,m=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,u/=2,m/=2,t/=2}function x(C,I){return a===1?C[I]:C.readUInt16BE(I*a)}let A;if(s){let C=-1;for(A=t;A<u;A++)if(x(r,A)===x(e,C===-1?0:A-C)){if(C===-1&&(C=A),A-C+1===m)return C*a}else C!==-1&&(A-=A-C),C=-1}else for(t+m>u&&(t=u-m),A=t;A>=0;A--){let C=!0;for(let I=0;I<m;I++)if(x(r,A+I)!==x(e,I)){C=!1;break}if(C)return A}return-1}o.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1},o.prototype.indexOf=function(e,t,n){return M(this,e,t,n,!0)},o.prototype.lastIndexOf=function(e,t,n){return M(this,e,t,n,!1)};function et(r,e,t,n){t=Number(t)||0;let s=r.length-t;n?(n=Number(n),n>s&&(n=s)):n=s;let a=e.length;n>a/2&&(n=a/2);let u;for(u=0;u<n;++u){let m=parseInt(e.substr(u*2,2),16);if(fe(m))return u;r[t+u]=m}return u}function tt(r,e,t,n){return le(me(e,r.length-t),r,t,n)}function rt(r,e,t,n){return le(yt(e),r,t,n)}function nt(r,e,t,n){return le(ke(e),r,t,n)}function it(r,e,t,n){return le(gt(e,r.length-t),r,t,n)}o.prototype.write=function(e,t,n,s){if(t===void 0)s="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")s=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,s===void 0&&(s="utf8")):(s=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let 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");s||(s="utf8");let u=!1;for(;;)switch(s){case"hex":return et(this,e,t,n);case"utf8":case"utf-8":return tt(this,e,t,n);case"ascii":case"latin1":case"binary":return rt(this,e,t,n);case"base64":return nt(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return it(this,e,t,n);default:if(u)throw new TypeError("Unknown encoding: "+s);s=(""+s).toLowerCase(),u=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ot(r,e,t){return e===0&&t===r.length?d.fromByteArray(r):d.fromByteArray(r.slice(e,t))}function Be(r,e,t){t=Math.min(r.length,t);let n=[],s=e;for(;s<t;){let a=r[s],u=null,m=a>239?4:a>223?3:a>191?2:1;if(s+m<=t){let x,A,C,I;switch(m){case 1:a<128&&(u=a);break;case 2:x=r[s+1],(x&192)===128&&(I=(a&31)<<6|x&63,I>127&&(u=I));break;case 3:x=r[s+1],A=r[s+2],(x&192)===128&&(A&192)===128&&(I=(a&15)<<12|(x&63)<<6|A&63,I>2047&&(I<55296||I>57343)&&(u=I));break;case 4:x=r[s+1],A=r[s+2],C=r[s+3],(x&192)===128&&(A&192)===128&&(C&192)===128&&(I=(a&15)<<18|(x&63)<<12|(A&63)<<6|C&63,I>65535&&I<1114112&&(u=I))}}u===null?(u=65533,m=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|u&1023),n.push(u),s+=m}return st(n)}let Ae=4096;function st(r){let e=r.length;if(e<=Ae)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Ae));return t}function at(r,e,t){let n="";t=Math.min(r.length,t);for(let s=e;s<t;++s)n+=String.fromCharCode(r[s]&127);return n}function ct(r,e,t){let n="";t=Math.min(r.length,t);for(let s=e;s<t;++s)n+=String.fromCharCode(r[s]);return n}function ut(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let s="";for(let a=e;a<t;++a)s+=mt[r[a]];return s}function lt(r,e,t){let n=r.slice(e,t),s="";for(let a=0;a<n.length-1;a+=2)s+=String.fromCharCode(n[a]+n[a+1]*256);return s}o.prototype.slice=function(e,t){let 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);let s=this.subarray(e,t);return Object.setPrototypeOf(s,o.prototype),s};function U(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||U(e,t,this.length);let s=this[e],a=1,u=0;for(;++u<t&&(a*=256);)s+=this[e+u]*a;return s},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||U(e,t,this.length);let s=this[e+--t],a=1;for(;t>0&&(a*=256);)s+=this[e+--t]*a;return s},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e=e>>>0,t||U(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||U(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||U(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||U(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||U(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=Y(function(e){e=e>>>0,Q(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ne(e,this.length-8);let s=t+this[++e]*_(2,8)+this[++e]*_(2,16)+this[++e]*_(2,24),a=this[++e]+this[++e]*_(2,8)+this[++e]*_(2,16)+n*_(2,24);return BigInt(s)+(BigInt(a)<<BigInt(32))}),o.prototype.readBigUInt64BE=Y(function(e){e=e>>>0,Q(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ne(e,this.length-8);let s=t*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+this[++e],a=this[++e]*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+n;return(BigInt(s)<<BigInt(32))+BigInt(a)}),o.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||U(e,t,this.length);let s=this[e],a=1,u=0;for(;++u<t&&(a*=256);)s+=this[e+u]*a;return a*=128,s>=a&&(s-=Math.pow(2,8*t)),s},o.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||U(e,t,this.length);let s=t,a=1,u=this[e+--s];for(;s>0&&(a*=256);)u+=this[e+--s]*a;return a*=128,u>=a&&(u-=Math.pow(2,8*t)),u},o.prototype.readInt8=function(e,t){return e=e>>>0,t||U(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},o.prototype.readInt16LE=function(e,t){e=e>>>0,t||U(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n},o.prototype.readInt16BE=function(e,t){e=e>>>0,t||U(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n},o.prototype.readInt32LE=function(e,t){return e=e>>>0,t||U(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||U(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=Y(function(e){e=e>>>0,Q(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ne(e,this.length-8);let s=this[e+4]+this[e+5]*_(2,8)+this[e+6]*_(2,16)+(n<<24);return(BigInt(s)<<BigInt(32))+BigInt(t+this[++e]*_(2,8)+this[++e]*_(2,16)+this[++e]*_(2,24))}),o.prototype.readBigInt64BE=Y(function(e){e=e>>>0,Q(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ne(e,this.length-8);let s=(t<<24)+this[++e]*_(2,16)+this[++e]*_(2,8)+this[++e];return(BigInt(s)<<BigInt(32))+BigInt(this[++e]*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+n)}),o.prototype.readFloatLE=function(e,t){return e=e>>>0,t||U(e,4,this.length),i.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e=e>>>0,t||U(e,4,this.length),i.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||U(e,8,this.length),i.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||U(e,8,this.length),i.read(this,e,!1,52,8)};function $(r,e,t,n,s,a){if(!o.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>s||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,s){if(e=+e,t=t>>>0,n=n>>>0,!s){let m=Math.pow(2,8*n)-1;$(this,e,t,n,m,0)}let a=1,u=0;for(this[t]=e&255;++u<n&&(a*=256);)this[t+u]=e/a&255;return t+n},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,n,s){if(e=+e,t=t>>>0,n=n>>>0,!s){let m=Math.pow(2,8*n)-1;$(this,e,t,n,m,0)}let a=n-1,u=1;for(this[t+a]=e&255;--a>=0&&(u*=256);)this[t+a]=e/u&255;return t+n},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||$(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||$(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||$(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||$(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||$(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function Se(r,e,t,n,s){Ue(e,n,s,r,t,7);let a=Number(e&BigInt(4294967295));r[t++]=a,a=a>>8,r[t++]=a,a=a>>8,r[t++]=a,a=a>>8,r[t++]=a;let u=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=u,u=u>>8,r[t++]=u,u=u>>8,r[t++]=u,u=u>>8,r[t++]=u,t}function xe(r,e,t,n,s){Ue(e,n,s,r,t,7);let a=Number(e&BigInt(4294967295));r[t+7]=a,a=a>>8,r[t+6]=a,a=a>>8,r[t+5]=a,a=a>>8,r[t+4]=a;let u=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=u,u=u>>8,r[t+2]=u,u=u>>8,r[t+1]=u,u=u>>8,r[t]=u,t+8}o.prototype.writeBigUInt64LE=Y(function(e,t=0){return Se(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=Y(function(e,t=0){return xe(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(e,t,n,s){if(e=+e,t=t>>>0,!s){let x=Math.pow(2,8*n-1);$(this,e,t,n,x-1,-x)}let a=0,u=1,m=0;for(this[t]=e&255;++a<n&&(u*=256);)e<0&&m===0&&this[t+a-1]!==0&&(m=1),this[t+a]=(e/u>>0)-m&255;return t+n},o.prototype.writeIntBE=function(e,t,n,s){if(e=+e,t=t>>>0,!s){let x=Math.pow(2,8*n-1);$(this,e,t,n,x-1,-x)}let a=n-1,u=1,m=0;for(this[t+a]=e&255;--a>=0&&(u*=256);)e<0&&m===0&&this[t+a+1]!==0&&(m=1),this[t+a]=(e/u>>0)-m&255;return t+n},o.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||$(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||$(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||$(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||$(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||$(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},o.prototype.writeBigInt64LE=Y(function(e,t=0){return Se(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=Y(function(e,t=0){return xe(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ce(r,e,t,n,s,a){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Te(r,e,t,n,s){return e=+e,t=t>>>0,s||Ce(r,e,t,4),i.write(r,e,t,n,23,4),t+4}o.prototype.writeFloatLE=function(e,t,n){return Te(this,e,t,!0,n)},o.prototype.writeFloatBE=function(e,t,n){return Te(this,e,t,!1,n)};function Pe(r,e,t,n,s){return e=+e,t=t>>>0,s||Ce(r,e,t,8),i.write(r,e,t,n,52,8),t+8}o.prototype.writeDoubleLE=function(e,t,n){return Pe(this,e,t,!0,n)},o.prototype.writeDoubleBE=function(e,t,n){return Pe(this,e,t,!1,n)},o.prototype.copy=function(e,t,n,s){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!s&&s!==0&&(s=this.length),t>=e.length&&(t=e.length),t||(t=0),s>0&&s<n&&(s=n),s===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(s<0)throw new RangeError("sourceEnd out of bounds");s>this.length&&(s=this.length),e.length-t<s-n&&(s=e.length-t+n);let a=s-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,s):Uint8Array.prototype.set.call(e,this.subarray(n,s),t),a},o.prototype.fill=function(e,t,n,s){if(typeof e=="string"){if(typeof t=="string"?(s=t,t=0,n=this.length):typeof n=="string"&&(s=n,n=this.length),s!==void 0&&typeof s!="string")throw new TypeError("encoding must be a string");if(typeof s=="string"&&!o.isEncoding(s))throw new TypeError("Unknown encoding: "+s);if(e.length===1){let u=e.charCodeAt(0);(s==="utf8"&&u<128||s==="latin1")&&(e=u)}}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);let a;if(typeof e=="number")for(a=t;a<n;++a)this[a]=e;else{let u=o.isBuffer(e)?e:o.from(e,s),m=u.length;if(m===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(a=0;a<n-t;++a)this[a+t]=u[a%m]}return this};let H={};function ge(r,e,t){H[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(s){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:s,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}ge("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),ge("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),ge("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,s=t;return Number.isInteger(t)&&Math.abs(t)>_(2,32)?s=Ke(String(t)):typeof t=="bigint"&&(s=String(t),(t>_(BigInt(2),BigInt(32))||t<-_(BigInt(2),BigInt(32)))&&(s=Ke(s)),s+="n"),n+=` It must be ${e}. Received ${s}`,n},RangeError);function Ke(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function dt(r,e,t){Q(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&ne(e,r.length-(t+1))}function Ue(r,e,t,n,s,a){if(r>t||r<e){let u=typeof e=="bigint"?"n":"",m;throw a>3?e===0||e===BigInt(0)?m=`>= 0${u} and < 2${u} ** ${(a+1)*8}${u}`:m=`>= -(2${u} ** ${(a+1)*8-1}${u}) and < 2 ** ${(a+1)*8-1}${u}`:m=`>= ${e}${u} and <= ${t}${u}`,new H.ERR_OUT_OF_RANGE("value",m,r)}dt(n,s,a)}function Q(r,e){if(typeof r!="number")throw new H.ERR_INVALID_ARG_TYPE(e,"number",r)}function ne(r,e,t){throw Math.floor(r)!==r?(Q(r,t),new H.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new H.ERR_BUFFER_OUT_OF_BOUNDS:new H.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let pt=/[^+/0-9A-Za-z-_]/g;function ht(r){if(r=r.split("=")[0],r=r.trim().replace(pt,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function me(r,e){e=e||1/0;let t,n=r.length,s=null,a=[];for(let u=0;u<n;++u){if(t=r.charCodeAt(u),t>55295&&t<57344){if(!s){if(t>56319){(e-=3)>-1&&a.push(239,191,189);continue}else if(u+1===n){(e-=3)>-1&&a.push(239,191,189);continue}s=t;continue}if(t<56320){(e-=3)>-1&&a.push(239,191,189),s=t;continue}t=(s-55296<<10|t-56320)+65536}else s&&(e-=3)>-1&&a.push(239,191,189);if(s=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 yt(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function gt(r,e){let t,n,s,a=[];for(let u=0;u<r.length&&!((e-=2)<0);++u)t=r.charCodeAt(u),n=t>>8,s=t%256,a.push(s),a.push(n);return a}function ke(r){return d.toByteArray(ht(r))}function le(r,e,t,n){let s;for(s=0;s<n&&!(s+t>=e.length||s>=r.length);++s)e[s+t]=r[s];return s}function W(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function fe(r){return r!==r}let mt=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let s=0;s<16;++s)e[n+s]=r[t]+r[s]}return e}();function Y(r){return typeof BigInt=="undefined"?ft:r}function ft(){throw new Error("BigInt not supported")}return G}var X=Pt();X.Buffer;X.SlowBuffer;X.INSPECT_MAX_BYTES;X.kMaxLength;var P=X.Buffer,Nt=X.INSPECT_MAX_BYTES,Ot=X.kMaxLength;var se=require("bs58"),Z=we(require("@noble/ed25519"));var q=class d{static generateKey(){let i=Z.utils.randomPrivateKey(),c=(0,se.encode)(i);return new d(c)}constructor(i){this.secretKey=i;let c=(0,se.decode)(i);this.privateKey=P.from(c).toString("hex")}sign(i){return b(this,null,function*(){return yield Z.signAsync(i,this.privateKey)})}getPublicKey(){return b(this,null,function*(){let i=yield Z.getPublicKeyAsync(this.privateKey);return`ed25519:${(0,se.encode)(i)}`})}toString(){return this.privateKey}};var ae=class{constructor(i="testnet"){this.networkId=i}get keyPrefix(){return`orderly_${this.networkId}_`}},ee=class extends ae{getOrderlyKey(i){let c;if(i)c=this.getItem(i,"orderlyKey");else{let l=this.getAddress();if(!l)return null;c=this.getItem(l,"orderlyKey")}return c?new q(c):null}getAccountId(i){return this.getItem(i,"accountId")}setAccountId(i,c){this.setItem(i,{accountId:c})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(i){localStorage.setItem(`${this.keyPrefix}address`,i)}generateKey(){return q.generateKey()}setKey(i,c){this.setItem(i,{orderlyKey:c.secretKey})}cleanAllKey(i){localStorage.removeItem(`${this.keyPrefix}${i}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(i,c){let l=this.getItem(i);delete l[c],localStorage.setItem(`${this.keyPrefix}${i}`,JSON.stringify(l))}setItem(i,c){let l=`${this.keyPrefix}${i}`,p=localStorage.getItem(l);p?p=JSON.parse(p):p={},localStorage.setItem(l,JSON.stringify(L(L({},p),c)))}getItem(i,c){let l=`${this.keyPrefix}${i}`,p=localStorage.getItem(l);return p?p=JSON.parse(p):p={},typeof c=="undefined"?p:p[c]}},te=class{constructor(i){this.secretKey=i}generateKey(){return new q(this.secretKey)}getOrderlyKey(){return new q(this.secretKey)}getAccountId(){return""}setAccountId(i){}getAddress(){return""}setAddress(i){}setKey(i,c){}cleanAllKey(){}cleanKey(i){}};var z={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"}]},Le="0x004d88aa993fd2100d6c8beb6cdb6bc04f565b44",Fe="0x0C554dDb6a9010Ed1FD7e50d92559A06655dA482",Ve="0x8794E7260517B1766fc7b55cAfcd56e6bf08600e";var je=function(d){return d.replace(/\+/g,"-").replace(/\//g,"_")};function Kt(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function We(d,i){return{name:"Orderly",version:"1",chainId:d,verifyingContract:i?Kt():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function qe(d){let{chainId:i,registrationNonce:c}=d,l=Date.now(),p="Registration",h={brokerId:"woofi_dex",chainId:i,timestamp:l,registrationNonce:c},o={EIP712Domain:z.EIP712Domain,[p]:z[p]};return[h,{domain:We(i),message:h,primaryType:p,types:o}]}function Je(d){let{publicKey:i,chainId:c,primaryType:l,expiration:p=365}=d,h=Date.now(),o={brokerId:"woofi_dex",orderlyKey:i,scope:"read,trading",chainId:c,timestamp:h,expiration:h+1e3*60*60*24*p},g={EIP712Domain:z.EIP712Domain,[l]:z[l]},f={domain:We(c),message:o,primaryType:l,types:g};return[o,f]}function Ye(d){let{chainId:i,settlePnlNonce:c,domain:l}=d,p="SettlePnl",h=new Date().getTime(),o={EIP712Domain:z.EIP712Domain,[p]:z[p]},g={brokerId:"woofi_dex",chainId:i,timestamp:h,settleNonce:c};return[g,{domain:l,message:g,primaryType:p,types:o}]}var J=class{constructor(i){this.keyStore=i}sign(i){return b(this,null,function*(){let c=Date.now().toString(),l=[c,i.method.toUpperCase(),i.url].join("");i.data&&Object.keys(i.data).length&&(l+=JSON.stringify(i.data));let{signature:p,publicKey:h}=yield this.signText(l);return{"orderly-key":h,"orderly-timestamp":c,"orderly-signature":p}})}signText(i){return b(this,null,function*(){let c=this.keyStore.getOrderlyKey();if(!c)throw new Error("orderlyKeyPair is not defined");let l=P.from(i),p=yield c.sign(l),h=P.from(p).toString("base64");return{signature:je(h),publicKey:yield c.getPublicKey()}})}};var Ze=we(require("eventemitter3"));var ce=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://dev-api-v2.orderly.org"],["klineDataUrl","https://dev-api-v2.orderly.org"],["publicWsUrl","wss://dev-ws-v2.orderly.org"],["publicWebsocketKey","OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY"],["privateWsUrl","wss://dev-ws-private-v2.orderly.org"],["env","dev-evm"]])}get(i){return this.map.get(i)}set(i,c){this.map.set(i,c)}clear(){}},Ie=class extends ce{constructor(c){super();this.configMap=c}_restore(){let c=Object.entries(this.configMap);this.map=new Map(c)}};var Ge=d=>{let i=new te(d||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new J(i)},Xe=()=>{if(typeof window=="undefined")throw new Error("the default signer only supports browsers.");let d=new ee("");return new J(d)};var re=class{constructor(i){this.configStore=i}getContractInfoByEnv(){return{usdcAddress:Le,vaultAddress:Fe,verifyContractAddress:Ve}}};var _e=class{constructor(i=[],c={}){this.providers=i;this.services=c;this.injectProperties={}}register(...i){this.providers.push(...i),i.forEach(c=>{let l=c;l instanceof Function&&(l=new c),this.add(l)})}registerByName(i,c){let l=c;l instanceof Function&&(l=new c),this.addByName(i,l)}get(i){return this.services[i]}getAll(){return Object.assign({},this.services)}add(i){return this.addByName(i.constructor.name,i)}addByName(i,c){return this.services[i]=c,this.services[i.toLowerCase()]=c,this.injectIntoProperties(c,i),this.get(i)}inject(i,c,l){i&&l&&(i[c]=l)}injectIntoProperties(i,c=i.constructor.name){this.getInjectProperty(c.toLowerCase()).forEach(l=>{this.inject(l.target,l.propertyKey,i)})}getInjectProperty(i){return this.injectProperties[i]||(this.injectProperties[i]=[]),this.injectProperties[i]}},ze=_e;var Ee=class d{static getContainer(){return d.container||(d.container=new ze),d.container}static register(...i){this.getContainer().register(...i)}static registerByName(i,c){this.getContainer().registerByName(i,c)}static get(i){return this.getContainer().get(i)}static getAll(){return this.getContainer().getAll()}constructor(){}},He=Ee;var O=require("@orderly.network/types");var Qe=we(require("eventemitter3"));var ue=class{constructor(i,c,l){this.configStore=i;this.keyStore=c;this.walletAdapterClass=l;this._ee=new Qe.default;this._state={status:O.AccountStatusEnum.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.contract=new re(i),this._bindEvents()}login(i){if(!i)throw new Error("address is required")}logout(){}setAddress(i,c){return b(this,null,function*(){if(!i)throw new Error("address is required");console.log("setAddress",i,c),this.keyStore.setAddress(i);let l=j(L({},this.stateValue),{status:O.AccountStatusEnum.Connected,address:i});return this._ee.emit("change:status",l),c&&(this.walletClient=new this.walletAdapterClass(c)),yield this._checkAccount(i)})}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get address(){return this.stateValue.address}get chainId(){var i;return(i=this.walletClient)==null?void 0:i.chainId}set position(i){let c=j(L({},this.stateValue),{positon:i});this._ee.emit("change:status",c)}set orders(i){let c=j(L({},this.stateValue),{orders:i});this._ee.emit("change:status",c)}_bindEvents(){this._ee.addListener("change:status",i=>{console.log("change:status",i),this._state=i})}_checkAccount(i){return b(this,null,function*(){console.log("check account is esist",i);let c;try{let l=yield this._checkAccountExist(i);if(console.log("accountInfo:",l),l&&l.account_id)console.log("account is exist"),this.keyStore.setAccountId(i,l.account_id),c=j(L({},this.stateValue),{status:O.AccountStatusEnum.SignedIn,accountId:l.account_id,userId:l.user_id}),this._ee.emit("change:status",c);else return c=j(L({},this.stateValue),{status:O.AccountStatusEnum.NotSignedIn}),this._ee.emit("change:status",c),O.AccountStatusEnum.NotSignedIn;let p=this.keyStore.getOrderlyKey();if(console.log("orderlyKey:::::::",p),c=j(L({},this.stateValue),{status:O.AccountStatusEnum.DisabledTrading}),!p)return console.log("orderlyKey is null"),this._ee.emit("change:status",c),O.AccountStatusEnum.DisabledTrading;let h=yield p.getPublicKey(),o=yield this._checkOrderlyKeyState(l.account_id,h);if(console.log("orderlyKeyStatus:",o),o&&o.orderly_key&&o.key_status==="ACTIVE"){let g=Date.now(),f=o.expiration;if(g>f)return this.keyStore.cleanKey(i,"orderlyKey"),O.AccountStatusEnum.DisabledTrading;let B=j(L({},this.stateValue),{status:O.AccountStatusEnum.EnableTrading});return this._ee.emit("change:status",B),O.AccountStatusEnum.EnableTrading}return this.keyStore.cleanKey(i,"orderlyKey"),O.AccountStatusEnum.NotConnected}catch(l){console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:",l)}return O.AccountStatusEnum.NotSignedIn})}_checkAccountExist(i){return b(this,null,function*(){let c=yield this._simpleFetch(`/v1/get_account?address=${i}&broker_id=woofi_dex`);return c.success?c.data:null})}createAccount(){return b(this,null,function*(){let i=yield this._getRegisterationNonce(),c=this.stateValue.address;if(!c)throw new Error("address is undefined");let[l,p]=qe({registrationNonce:i,chainId:this.walletClient.chainId}),h=yield this.walletClient.send("eth_signTypedData_v4",[c,JSON.stringify(p)]),o=yield this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:h,message:l,userAddress:c}),headers:{"Content-Type":"application/json"}});if(o.success){this.keyStore.setAccountId(c,o.data.account_id);let g=j(L({},this.stateValue),{status:O.AccountStatusEnum.DisabledTrading,accountId:o.data.account_id,userId:o.data.user_id});return this._ee.emit("change:status",g),o}})}createOrderlyKey(i){return b(this,null,function*(){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(this.walletClient===void 0)throw new Error("walletClient is undefined");let c="AddOrderlyKey",l=this.keyStore.generateKey(),p=yield l.getPublicKey(),[h,o]=Je({publicKey:p,chainId:this.walletClient.chainId,primaryType:c,expiration:i}),g=this.stateValue.address;if(!g)throw new Error("address is undefined");let f=yield this.walletClient.send("eth_signTypedData_v4",[g,JSON.stringify(o)]),B=yield this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:f,message:h,userAddress:g}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(B.success){this.keyStore.setKey(g,l);let S=j(L({},this.stateValue),{status:O.AccountStatusEnum.EnableTrading});return this._ee.emit("change:status",S),B}else throw new Error(B.message)})}settlement(){return b(this,null,function*(){var B;let i=yield this._getSettleNonce(),c=this.stateValue.address,l=this.getDomain(!0);console.log("domain:::::::::",l);let[p,h]=Ye({settlePnlNonce:i,chainId:this.walletClient.chainId,domain:l}),o=yield this.walletClient.send("eth_signTypedData_v4",[c,JSON.stringify(h)]);console.log("settlement:",c,p,h,o);let g=yield(B=this.keyStore.getOrderlyKey())==null?void 0:B.getPublicKey(),f=yield this._simpleFetch("/v1/settle_pnl",{method:"POST",body:JSON.stringify({signature:o,message:p,userAddress:c,verifyingContract:l.verifyingContract}),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,"orderly-key":g,"orderly-timestamp":p.timestamp.toString(),"orderly-signature":o}});if(console.log("#########",f),f.success)return f;throw new Error(f.message)})}disconnect(){return b(this,null,function*(){let i=j(L({},this.stateValue),{status:O.AccountStatusEnum.NotConnected,accountId:void 0,userId:void 0,address:void 0});this._ee.emit("change:status",i)})}_checkOrderlyKeyState(i,c){return b(this,null,function*(){let l=yield this._simpleFetch(`/v1/get_orderly_key?account_id=${i}&orderly_key=${c}`);if(l.success)return l.data;throw new Error(l.message)})}get signer(){return this._singer||(this._singer=new J(this.keyStore)),this._singer}get wallet(){return this.walletClient}_getRegisterationNonce(){return b(this,null,function*(){var c;let i=yield this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(console.log("getRegisterationNonce:",i),i.success)return(c=i.data)==null?void 0:c.registration_nonce;throw new Error(i.message)})}_getSettleNonce(){return b(this,null,function*(){var f;let i=Date.now().toString(),l=[i,"GET","/v1/settle_nonce"].join(""),p=this.signer,{publicKey:h,signature:o}=yield p.signText(l),g=yield this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":h,"orderly-timestamp":i,"orderly-signature":o}});if(g.success)return(f=g.data)==null?void 0:f.settle_nonce;throw new Error(g.message)})}_simpleFetch(l){return b(this,arguments,function*(i,c={}){let p=`${this.configStore.get("apiBaseUrl")}${i}`;return fetch(p,c).then(h=>h.json())})}getDomain(i){return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:i?this.contract.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}get on(){return this._ee.on.bind(this._ee)}get once(){return this._ee.once.bind(this._ee)}get off(){return this._ee.off.bind(this._ee)}};ue.instanceName="account";var pe=class{constructor(i){this.web3=i}getBalance(i){return b(this,null,function*(){return yield this.web3.eth.getBalance(i)})}deposit(i,c,l){return b(this,null,function*(){return yield this.web3.eth.sendTransaction({from:i,to:c,value:l})})}send(i,c){return b(this,null,function*(){})}};var ye=require("ethers");var he=class{constructor(i){console.log("EtherAdapter constructor",i),this._chainId=parseInt(i.chain.id,16),this.provider=new ye.BrowserProvider(i.provider,"any")}getBalance(i){throw new Error("Method not implemented.")}deposit(i,c,l){throw new Error("Method not implemented.")}get chainId(){return this._chainId}send(i,c){return b(this,null,function*(){var l;return yield(l=this.provider)==null?void 0:l.send(i,c)})}verify(i,c){return b(this,null,function*(){let{domain:l,types:p,message:h}=i,o=ye.ethers.verifyTypedData(l,p,h,c);console.log("recovered",o)})}};0&&(module.exports={Account,BaseConfigStore,BaseKeyStore,BaseOrderlyKeyPair,BaseSigner,Contract,EtherAdapter,EventEmitter,LocalStorageStore,MemoryConfigStore,MockKeyStore,SimpleDI,Web3WalletAdapter,getDefaultSigner,getMockSigner});
|
|
1
|
+
"use strict";var wt=Object.create;var oe=Object.defineProperty,It=Object.defineProperties,_t=Object.getOwnPropertyDescriptor,Et=Object.getOwnPropertyDescriptors,bt=Object.getOwnPropertyNames,ve=Object.getOwnPropertySymbols,Bt=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty,At=Object.prototype.propertyIsEnumerable;var _=Math.pow,Ne=(d,i,c)=>i in d?oe(d,i,{enumerable:!0,configurable:!0,writable:!0,value:c}):d[i]=c,L=(d,i)=>{for(var c in i||(i={}))Oe.call(i,c)&&Ne(d,c,i[c]);if(ve)for(var c of ve(i))At.call(i,c)&&Ne(d,c,i[c]);return d},j=(d,i)=>It(d,Et(i));var St=(d,i)=>{for(var c in i)oe(d,c,{get:i[c],enumerable:!0})},Me=(d,i,c,l)=>{if(i&&typeof i=="object"||typeof i=="function")for(let p of bt(i))!Oe.call(d,p)&&p!==c&&oe(d,p,{get:()=>i[p],enumerable:!(l=_t(i,p))||l.enumerable});return d};var we=(d,i,c)=>(c=d!=null?wt(Bt(d)):{},Me(i||!d||!d.__esModule?oe(c,"default",{value:d,enumerable:!0}):c,d)),xt=d=>Me(oe({},"__esModule",{value:!0}),d);var b=(d,i,c)=>new Promise((l,p)=>{var h=f=>{try{g(c.next(f))}catch(B){p(B)}},o=f=>{try{g(c.throw(f))}catch(B){p(B)}},g=f=>f.done?l(f.value):Promise.resolve(f.value).then(h,o);g((c=c.apply(d,i)).next())});var Ut={};St(Ut,{Account:()=>le,BaseConfigStore:()=>Ie,BaseKeyStore:()=>ce,BaseOrderlyKeyPair:()=>q,BaseSigner:()=>J,Contract:()=>re,EtherAdapter:()=>ye,EventEmitter:()=>Ze.default,LocalStorageStore:()=>ee,MemoryConfigStore:()=>ue,MockKeyStore:()=>te,SimpleDI:()=>He,Web3WalletAdapter:()=>he,getDefaultSigner:()=>Xe,getMockSigner:()=>Ge});module.exports=xt(Ut);var se={},Re=!1;function Ct(){if(Re)return se;Re=!0,se.byteLength=g,se.toByteArray=B,se.fromByteArray=V;for(var d=[],i=[],c=typeof Uint8Array!="undefined"?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,h=l.length;p<h;++p)d[p]=l[p],i[l.charCodeAt(p)]=p;i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63;function o(y){var w=y.length;if(w%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var E=y.indexOf("=");E===-1&&(E=w);var K=E===w?0:4-E%4;return[E,K]}function g(y){var w=o(y),E=w[0],K=w[1];return(E+K)*3/4-K}function f(y,w,E){return(w+E)*3/4-E}function B(y){var w,E=o(y),K=E[0],R=E[1],T=new c(f(y,K,R)),D=0,F=R>0?K-4:K,M;for(M=0;M<F;M+=4)w=i[y.charCodeAt(M)]<<18|i[y.charCodeAt(M+1)]<<12|i[y.charCodeAt(M+2)]<<6|i[y.charCodeAt(M+3)],T[D++]=w>>16&255,T[D++]=w>>8&255,T[D++]=w&255;return R===2&&(w=i[y.charCodeAt(M)]<<2|i[y.charCodeAt(M+1)]>>4,T[D++]=w&255),R===1&&(w=i[y.charCodeAt(M)]<<10|i[y.charCodeAt(M+1)]<<4|i[y.charCodeAt(M+2)]>>2,T[D++]=w>>8&255,T[D++]=w&255),T}function S(y){return d[y>>18&63]+d[y>>12&63]+d[y>>6&63]+d[y&63]}function k(y,w,E){for(var K,R=[],T=w;T<E;T+=3)K=(y[T]<<16&16711680)+(y[T+1]<<8&65280)+(y[T+2]&255),R.push(S(K));return R.join("")}function V(y){for(var w,E=y.length,K=E%3,R=[],T=16383,D=0,F=E-K;D<F;D+=T)R.push(k(y,D,D+T>F?F:D+T));return K===1?(w=y[E-1],R.push(d[w>>2]+d[w<<4&63]+"==")):K===2&&(w=(y[E-2]<<8)+y[E-1],R.push(d[w>>10]+d[w>>4&63]+d[w<<2&63]+"=")),R.join("")}return se}var pe={},De=!1;function Tt(){if(De)return pe;De=!0;return pe.read=function(d,i,c,l,p){var h,o,g=p*8-l-1,f=(1<<g)-1,B=f>>1,S=-7,k=c?p-1:0,V=c?-1:1,y=d[i+k];for(k+=V,h=y&(1<<-S)-1,y>>=-S,S+=g;S>0;h=h*256+d[i+k],k+=V,S-=8);for(o=h&(1<<-S)-1,h>>=-S,S+=l;S>0;o=o*256+d[i+k],k+=V,S-=8);if(h===0)h=1-B;else{if(h===f)return o?NaN:(y?-1:1)*(1/0);o=o+Math.pow(2,l),h=h-B}return(y?-1:1)*o*Math.pow(2,h-l)},pe.write=function(d,i,c,l,p,h){var o,g,f,B=h*8-p-1,S=(1<<B)-1,k=S>>1,V=p===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=l?0:h-1,w=l?1:-1,E=i<0||i===0&&1/i<0?1:0;for(i=Math.abs(i),isNaN(i)||i===1/0?(g=isNaN(i)?1:0,o=S):(o=Math.floor(Math.log(i)/Math.LN2),i*(f=Math.pow(2,-o))<1&&(o--,f*=2),o+k>=1?i+=V/f:i+=V*Math.pow(2,1-k),i*f>=2&&(o++,f/=2),o+k>=S?(g=0,o=S):o+k>=1?(g=(i*f-1)*Math.pow(2,p),o=o+k):(g=i*Math.pow(2,k-1)*Math.pow(2,p),o=0));p>=8;d[c+y]=g&255,y+=w,g/=256,p-=8);for(o=o<<p|g,B+=p;B>0;d[c+y]=o&255,y+=w,o/=256,B-=8);d[c+y-w]|=E*128},pe}var G={},$e=!1;function Pt(){if($e)return G;$e=!0;let d=Ct(),i=Tt(),c=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;G.Buffer=o,G.SlowBuffer=R,G.INSPECT_MAX_BYTES=50;let l=2147483647;G.kMaxLength=l,o.TYPED_ARRAY_SUPPORT=p(),!o.TYPED_ARRAY_SUPPORT&&typeof console!="undefined"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function p(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch(r){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>l)throw new RangeError('The value "'+r+'" is invalid for option "size"');let 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 S(r)}return g(r,e,t)}o.poolSize=8192;function g(r,e,t){if(typeof r=="string")return k(r,e);if(ArrayBuffer.isView(r))return y(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(W(r,ArrayBuffer)||r&&W(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer!="undefined"&&(W(r,SharedArrayBuffer)||r&&W(r.buffer,SharedArrayBuffer)))return w(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return o.from(n,e,t);let s=E(r);if(s)return s;if(typeof Symbol!="undefined"&&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 g(r,e,t)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function f(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 B(r,e,t){return f(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 B(r,e,t)};function S(r){return f(r),h(r<0?0:K(r)|0)}o.allocUnsafe=function(r){return S(r)},o.allocUnsafeSlow=function(r){return S(r)};function k(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!o.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=T(r,e)|0,n=h(t),s=n.write(r,e);return s!==t&&(n=n.slice(0,s)),n}function V(r){let e=r.length<0?0:K(r.length)|0,t=h(e);for(let n=0;n<e;n+=1)t[n]=r[n]&255;return t}function y(r){if(W(r,Uint8Array)){let e=new Uint8Array(r);return w(e.buffer,e.byteOffset,e.byteLength)}return V(r)}function w(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let 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 E(r){if(o.isBuffer(r)){let e=K(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"||fe(r.length)?h(0):V(r);if(r.type==="Buffer"&&Array.isArray(r.data))return V(r.data)}function K(r){if(r>=l)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+l.toString(16)+" bytes");return r|0}function R(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(W(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),W(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;let n=e.length,s=t.length;for(let a=0,u=Math.min(n,s);a<u;++a)if(e[a]!==t[a]){n=e[a],s=t[a];break}return n<s?-1:s<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);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let s=o.allocUnsafe(t),a=0;for(n=0;n<e.length;++n){let u=e[n];if(W(u,Uint8Array))a+u.length>s.length?(o.isBuffer(u)||(u=o.from(u)),u.copy(s,a)):Uint8Array.prototype.set.call(s,u,a);else if(o.isBuffer(u))u.copy(s,a);else throw new TypeError('"list" argument must be an Array of Buffers');a+=u.length}return s};function T(r,e){if(o.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||W(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let s=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return me(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return ke(r).length;default:if(s)return n?-1:me(r).length;e=(""+e).toLowerCase(),s=!0}}o.byteLength=T;function D(r,e,t){let 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 ut(this,e,t);case"utf8":case"utf-8":return Be(this,e,t);case"ascii":return at(this,e,t);case"latin1":case"binary":return ct(this,e,t);case"base64":return ot(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return lt(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}o.prototype._isBuffer=!0;function F(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}o.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)F(this,t,t+1);return this},o.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)F(this,t,t+3),F(this,t+1,t+2);return this},o.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)F(this,t,t+7),F(this,t+1,t+6),F(this,t+2,t+5),F(this,t+3,t+4);return this},o.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?Be(this,0,e):D.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(){let e="",t=G.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},c&&(o.prototype[c]=o.prototype.inspect),o.prototype.compare=function(e,t,n,s,a){if(W(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),s===void 0&&(s=0),a===void 0&&(a=this.length),t<0||n>e.length||s<0||a>this.length)throw new RangeError("out of range index");if(s>=a&&t>=n)return 0;if(s>=a)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,s>>>=0,a>>>=0,this===e)return 0;let u=a-s,m=n-t,x=Math.min(u,m),A=this.slice(s,a),C=e.slice(t,n);for(let I=0;I<x;++I)if(A[I]!==C[I]){u=A[I],m=C[I];break}return u<m?-1:m<u?1:0};function M(r,e,t,n,s){if(r.length===0)return-1;if(typeof t=="string"?(n=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,fe(t)&&(t=s?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(s)return-1;t=r.length-1}else if(t<0)if(s)t=0;else return-1;if(typeof e=="string"&&(e=o.from(e,n)),o.isBuffer(e))return e.length===0?-1:be(r,e,t,n,s);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?s?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):be(r,[e],t,n,s);throw new TypeError("val must be string, number or Buffer")}function be(r,e,t,n,s){let a=1,u=r.length,m=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,u/=2,m/=2,t/=2}function x(C,I){return a===1?C[I]:C.readUInt16BE(I*a)}let A;if(s){let C=-1;for(A=t;A<u;A++)if(x(r,A)===x(e,C===-1?0:A-C)){if(C===-1&&(C=A),A-C+1===m)return C*a}else C!==-1&&(A-=A-C),C=-1}else for(t+m>u&&(t=u-m),A=t;A>=0;A--){let C=!0;for(let I=0;I<m;I++)if(x(r,A+I)!==x(e,I)){C=!1;break}if(C)return A}return-1}o.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1},o.prototype.indexOf=function(e,t,n){return M(this,e,t,n,!0)},o.prototype.lastIndexOf=function(e,t,n){return M(this,e,t,n,!1)};function et(r,e,t,n){t=Number(t)||0;let s=r.length-t;n?(n=Number(n),n>s&&(n=s)):n=s;let a=e.length;n>a/2&&(n=a/2);let u;for(u=0;u<n;++u){let m=parseInt(e.substr(u*2,2),16);if(fe(m))return u;r[t+u]=m}return u}function tt(r,e,t,n){return de(me(e,r.length-t),r,t,n)}function rt(r,e,t,n){return de(yt(e),r,t,n)}function nt(r,e,t,n){return de(ke(e),r,t,n)}function it(r,e,t,n){return de(gt(e,r.length-t),r,t,n)}o.prototype.write=function(e,t,n,s){if(t===void 0)s="utf8",n=this.length,t=0;else if(n===void 0&&typeof t=="string")s=t,n=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(n)?(n=n>>>0,s===void 0&&(s="utf8")):(s=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let 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");s||(s="utf8");let u=!1;for(;;)switch(s){case"hex":return et(this,e,t,n);case"utf8":case"utf-8":return tt(this,e,t,n);case"ascii":case"latin1":case"binary":return rt(this,e,t,n);case"base64":return nt(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return it(this,e,t,n);default:if(u)throw new TypeError("Unknown encoding: "+s);s=(""+s).toLowerCase(),u=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ot(r,e,t){return e===0&&t===r.length?d.fromByteArray(r):d.fromByteArray(r.slice(e,t))}function Be(r,e,t){t=Math.min(r.length,t);let n=[],s=e;for(;s<t;){let a=r[s],u=null,m=a>239?4:a>223?3:a>191?2:1;if(s+m<=t){let x,A,C,I;switch(m){case 1:a<128&&(u=a);break;case 2:x=r[s+1],(x&192)===128&&(I=(a&31)<<6|x&63,I>127&&(u=I));break;case 3:x=r[s+1],A=r[s+2],(x&192)===128&&(A&192)===128&&(I=(a&15)<<12|(x&63)<<6|A&63,I>2047&&(I<55296||I>57343)&&(u=I));break;case 4:x=r[s+1],A=r[s+2],C=r[s+3],(x&192)===128&&(A&192)===128&&(C&192)===128&&(I=(a&15)<<18|(x&63)<<12|(A&63)<<6|C&63,I>65535&&I<1114112&&(u=I))}}u===null?(u=65533,m=1):u>65535&&(u-=65536,n.push(u>>>10&1023|55296),u=56320|u&1023),n.push(u),s+=m}return st(n)}let Ae=4096;function st(r){let e=r.length;if(e<=Ae)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Ae));return t}function at(r,e,t){let n="";t=Math.min(r.length,t);for(let s=e;s<t;++s)n+=String.fromCharCode(r[s]&127);return n}function ct(r,e,t){let n="";t=Math.min(r.length,t);for(let s=e;s<t;++s)n+=String.fromCharCode(r[s]);return n}function ut(r,e,t){let n=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>n)&&(t=n);let s="";for(let a=e;a<t;++a)s+=mt[r[a]];return s}function lt(r,e,t){let n=r.slice(e,t),s="";for(let a=0;a<n.length-1;a+=2)s+=String.fromCharCode(n[a]+n[a+1]*256);return s}o.prototype.slice=function(e,t){let 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);let s=this.subarray(e,t);return Object.setPrototypeOf(s,o.prototype),s};function U(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||U(e,t,this.length);let s=this[e],a=1,u=0;for(;++u<t&&(a*=256);)s+=this[e+u]*a;return s},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||U(e,t,this.length);let s=this[e+--t],a=1;for(;t>0&&(a*=256);)s+=this[e+--t]*a;return s},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e=e>>>0,t||U(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||U(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||U(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||U(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||U(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=Y(function(e){e=e>>>0,Q(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ie(e,this.length-8);let s=t+this[++e]*_(2,8)+this[++e]*_(2,16)+this[++e]*_(2,24),a=this[++e]+this[++e]*_(2,8)+this[++e]*_(2,16)+n*_(2,24);return BigInt(s)+(BigInt(a)<<BigInt(32))}),o.prototype.readBigUInt64BE=Y(function(e){e=e>>>0,Q(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ie(e,this.length-8);let s=t*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+this[++e],a=this[++e]*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+n;return(BigInt(s)<<BigInt(32))+BigInt(a)}),o.prototype.readIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||U(e,t,this.length);let s=this[e],a=1,u=0;for(;++u<t&&(a*=256);)s+=this[e+u]*a;return a*=128,s>=a&&(s-=Math.pow(2,8*t)),s},o.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||U(e,t,this.length);let s=t,a=1,u=this[e+--s];for(;s>0&&(a*=256);)u+=this[e+--s]*a;return a*=128,u>=a&&(u-=Math.pow(2,8*t)),u},o.prototype.readInt8=function(e,t){return e=e>>>0,t||U(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},o.prototype.readInt16LE=function(e,t){e=e>>>0,t||U(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n},o.prototype.readInt16BE=function(e,t){e=e>>>0,t||U(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n},o.prototype.readInt32LE=function(e,t){return e=e>>>0,t||U(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||U(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=Y(function(e){e=e>>>0,Q(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ie(e,this.length-8);let s=this[e+4]+this[e+5]*_(2,8)+this[e+6]*_(2,16)+(n<<24);return(BigInt(s)<<BigInt(32))+BigInt(t+this[++e]*_(2,8)+this[++e]*_(2,16)+this[++e]*_(2,24))}),o.prototype.readBigInt64BE=Y(function(e){e=e>>>0,Q(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&ie(e,this.length-8);let s=(t<<24)+this[++e]*_(2,16)+this[++e]*_(2,8)+this[++e];return(BigInt(s)<<BigInt(32))+BigInt(this[++e]*_(2,24)+this[++e]*_(2,16)+this[++e]*_(2,8)+n)}),o.prototype.readFloatLE=function(e,t){return e=e>>>0,t||U(e,4,this.length),i.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e=e>>>0,t||U(e,4,this.length),i.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||U(e,8,this.length),i.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||U(e,8,this.length),i.read(this,e,!1,52,8)};function $(r,e,t,n,s,a){if(!o.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>s||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,s){if(e=+e,t=t>>>0,n=n>>>0,!s){let m=Math.pow(2,8*n)-1;$(this,e,t,n,m,0)}let a=1,u=0;for(this[t]=e&255;++u<n&&(a*=256);)this[t+u]=e/a&255;return t+n},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,n,s){if(e=+e,t=t>>>0,n=n>>>0,!s){let m=Math.pow(2,8*n)-1;$(this,e,t,n,m,0)}let a=n-1,u=1;for(this[t+a]=e&255;--a>=0&&(u*=256);)this[t+a]=e/u&255;return t+n},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||$(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||$(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||$(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||$(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||$(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function Se(r,e,t,n,s){Ue(e,n,s,r,t,7);let a=Number(e&BigInt(4294967295));r[t++]=a,a=a>>8,r[t++]=a,a=a>>8,r[t++]=a,a=a>>8,r[t++]=a;let u=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=u,u=u>>8,r[t++]=u,u=u>>8,r[t++]=u,u=u>>8,r[t++]=u,t}function xe(r,e,t,n,s){Ue(e,n,s,r,t,7);let a=Number(e&BigInt(4294967295));r[t+7]=a,a=a>>8,r[t+6]=a,a=a>>8,r[t+5]=a,a=a>>8,r[t+4]=a;let u=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=u,u=u>>8,r[t+2]=u,u=u>>8,r[t+1]=u,u=u>>8,r[t]=u,t+8}o.prototype.writeBigUInt64LE=Y(function(e,t=0){return Se(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=Y(function(e,t=0){return xe(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(e,t,n,s){if(e=+e,t=t>>>0,!s){let x=Math.pow(2,8*n-1);$(this,e,t,n,x-1,-x)}let a=0,u=1,m=0;for(this[t]=e&255;++a<n&&(u*=256);)e<0&&m===0&&this[t+a-1]!==0&&(m=1),this[t+a]=(e/u>>0)-m&255;return t+n},o.prototype.writeIntBE=function(e,t,n,s){if(e=+e,t=t>>>0,!s){let x=Math.pow(2,8*n-1);$(this,e,t,n,x-1,-x)}let a=n-1,u=1,m=0;for(this[t+a]=e&255;--a>=0&&(u*=256);)e<0&&m===0&&this[t+a+1]!==0&&(m=1),this[t+a]=(e/u>>0)-m&255;return t+n},o.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||$(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||$(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||$(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||$(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||$(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},o.prototype.writeBigInt64LE=Y(function(e,t=0){return Se(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=Y(function(e,t=0){return xe(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ce(r,e,t,n,s,a){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function Te(r,e,t,n,s){return e=+e,t=t>>>0,s||Ce(r,e,t,4),i.write(r,e,t,n,23,4),t+4}o.prototype.writeFloatLE=function(e,t,n){return Te(this,e,t,!0,n)},o.prototype.writeFloatBE=function(e,t,n){return Te(this,e,t,!1,n)};function Pe(r,e,t,n,s){return e=+e,t=t>>>0,s||Ce(r,e,t,8),i.write(r,e,t,n,52,8),t+8}o.prototype.writeDoubleLE=function(e,t,n){return Pe(this,e,t,!0,n)},o.prototype.writeDoubleBE=function(e,t,n){return Pe(this,e,t,!1,n)},o.prototype.copy=function(e,t,n,s){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!s&&s!==0&&(s=this.length),t>=e.length&&(t=e.length),t||(t=0),s>0&&s<n&&(s=n),s===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(s<0)throw new RangeError("sourceEnd out of bounds");s>this.length&&(s=this.length),e.length-t<s-n&&(s=e.length-t+n);let a=s-n;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,n,s):Uint8Array.prototype.set.call(e,this.subarray(n,s),t),a},o.prototype.fill=function(e,t,n,s){if(typeof e=="string"){if(typeof t=="string"?(s=t,t=0,n=this.length):typeof n=="string"&&(s=n,n=this.length),s!==void 0&&typeof s!="string")throw new TypeError("encoding must be a string");if(typeof s=="string"&&!o.isEncoding(s))throw new TypeError("Unknown encoding: "+s);if(e.length===1){let u=e.charCodeAt(0);(s==="utf8"&&u<128||s==="latin1")&&(e=u)}}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);let a;if(typeof e=="number")for(a=t;a<n;++a)this[a]=e;else{let u=o.isBuffer(e)?e:o.from(e,s),m=u.length;if(m===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(a=0;a<n-t;++a)this[a+t]=u[a%m]}return this};let H={};function ge(r,e,t){H[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(s){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:s,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}ge("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),ge("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),ge("ERR_OUT_OF_RANGE",function(r,e,t){let n=`The value of "${r}" is out of range.`,s=t;return Number.isInteger(t)&&Math.abs(t)>_(2,32)?s=Ke(String(t)):typeof t=="bigint"&&(s=String(t),(t>_(BigInt(2),BigInt(32))||t<-_(BigInt(2),BigInt(32)))&&(s=Ke(s)),s+="n"),n+=` It must be ${e}. Received ${s}`,n},RangeError);function Ke(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function dt(r,e,t){Q(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&ie(e,r.length-(t+1))}function Ue(r,e,t,n,s,a){if(r>t||r<e){let u=typeof e=="bigint"?"n":"",m;throw a>3?e===0||e===BigInt(0)?m=`>= 0${u} and < 2${u} ** ${(a+1)*8}${u}`:m=`>= -(2${u} ** ${(a+1)*8-1}${u}) and < 2 ** ${(a+1)*8-1}${u}`:m=`>= ${e}${u} and <= ${t}${u}`,new H.ERR_OUT_OF_RANGE("value",m,r)}dt(n,s,a)}function Q(r,e){if(typeof r!="number")throw new H.ERR_INVALID_ARG_TYPE(e,"number",r)}function ie(r,e,t){throw Math.floor(r)!==r?(Q(r,t),new H.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new H.ERR_BUFFER_OUT_OF_BOUNDS:new H.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let pt=/[^+/0-9A-Za-z-_]/g;function ht(r){if(r=r.split("=")[0],r=r.trim().replace(pt,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function me(r,e){e=e||1/0;let t,n=r.length,s=null,a=[];for(let u=0;u<n;++u){if(t=r.charCodeAt(u),t>55295&&t<57344){if(!s){if(t>56319){(e-=3)>-1&&a.push(239,191,189);continue}else if(u+1===n){(e-=3)>-1&&a.push(239,191,189);continue}s=t;continue}if(t<56320){(e-=3)>-1&&a.push(239,191,189),s=t;continue}t=(s-55296<<10|t-56320)+65536}else s&&(e-=3)>-1&&a.push(239,191,189);if(s=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 yt(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function gt(r,e){let t,n,s,a=[];for(let u=0;u<r.length&&!((e-=2)<0);++u)t=r.charCodeAt(u),n=t>>8,s=t%256,a.push(s),a.push(n);return a}function ke(r){return d.toByteArray(ht(r))}function de(r,e,t,n){let s;for(s=0;s<n&&!(s+t>=e.length||s>=r.length);++s)e[s+t]=r[s];return s}function W(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function fe(r){return r!==r}let mt=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let s=0;s<16;++s)e[n+s]=r[t]+r[s]}return e}();function Y(r){return typeof BigInt=="undefined"?ft:r}function ft(){throw new Error("BigInt not supported")}return G}var X=Pt();X.Buffer;X.SlowBuffer;X.INSPECT_MAX_BYTES;X.kMaxLength;var P=X.Buffer,Nt=X.INSPECT_MAX_BYTES,Ot=X.kMaxLength;var ae=require("bs58"),Z=we(require("@noble/ed25519"));var q=class d{static generateKey(){let i=Z.utils.randomPrivateKey(),c=(0,ae.encode)(i);return new d(c)}constructor(i){this.secretKey=i;let c=(0,ae.decode)(i);this.privateKey=P.from(c).toString("hex")}sign(i){return b(this,null,function*(){return yield Z.signAsync(i,this.privateKey)})}getPublicKey(){return b(this,null,function*(){let i=yield Z.getPublicKeyAsync(this.privateKey);return`ed25519:${(0,ae.encode)(i)}`})}toString(){return this.privateKey}};var ce=class{constructor(i="testnet"){this.networkId=i}get keyPrefix(){return`orderly_${this.networkId}_`}},ee=class extends ce{getOrderlyKey(i){let c;if(i)c=this.getItem(i,"orderlyKey");else{let l=this.getAddress();if(!l)return null;c=this.getItem(l,"orderlyKey")}return c?new q(c):null}getAccountId(i){return this.getItem(i,"accountId")}setAccountId(i,c){this.setItem(i,{accountId:c})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(i){localStorage.setItem(`${this.keyPrefix}address`,i)}generateKey(){return q.generateKey()}setKey(i,c){this.setItem(i,{orderlyKey:c.secretKey})}cleanAllKey(i){localStorage.removeItem(`${this.keyPrefix}${i}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(i,c){let l=this.getItem(i);delete l[c],localStorage.setItem(`${this.keyPrefix}${i}`,JSON.stringify(l))}setItem(i,c){let l=`${this.keyPrefix}${i}`,p=localStorage.getItem(l);p?p=JSON.parse(p):p={},localStorage.setItem(l,JSON.stringify(L(L({},p),c)))}getItem(i,c){let l=`${this.keyPrefix}${i}`,p=localStorage.getItem(l);return p?p=JSON.parse(p):p={},typeof c=="undefined"?p:p[c]}},te=class{constructor(i){this.secretKey=i}generateKey(){return new q(this.secretKey)}getOrderlyKey(){return new q(this.secretKey)}getAccountId(){return""}setAccountId(i){}getAddress(){return""}setAddress(i){}setKey(i,c){}cleanAllKey(){}cleanKey(i){}};var z={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"}]},Le="0x004d88aa993fd2100d6c8beb6cdb6bc04f565b44",Fe="0x0C554dDb6a9010Ed1FD7e50d92559A06655dA482",Ve="0x8794E7260517B1766fc7b55cAfcd56e6bf08600e";var je=function(d){return d.replace(/\+/g,"-").replace(/\//g,"_")};function Kt(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function We(d,i){return{name:"Orderly",version:"1",chainId:d,verifyingContract:i?Kt():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function qe(d){let{chainId:i,registrationNonce:c}=d,l=Date.now(),p="Registration",h={brokerId:"woofi_dex",chainId:i,timestamp:l,registrationNonce:c},o={EIP712Domain:z.EIP712Domain,[p]:z[p]};return[h,{domain:We(i),message:h,primaryType:p,types:o}]}function Je(d){let{publicKey:i,chainId:c,primaryType:l,expiration:p=365}=d,h=Date.now(),o={brokerId:"woofi_dex",orderlyKey:i,scope:"read,trading",chainId:c,timestamp:h,expiration:h+1e3*60*60*24*p},g={EIP712Domain:z.EIP712Domain,[l]:z[l]},f={domain:We(c),message:o,primaryType:l,types:g};return[o,f]}function Ye(d){let{chainId:i,settlePnlNonce:c,domain:l}=d,p="SettlePnl",h=new Date().getTime(),o={EIP712Domain:z.EIP712Domain,[p]:z[p]},g={brokerId:"woofi_dex",chainId:i,timestamp:h,settleNonce:c};return[g,{domain:l,message:g,primaryType:p,types:o}]}var J=class{constructor(i){this.keyStore=i}sign(i){return b(this,null,function*(){let c=Date.now().toString(),l=[c,i.method.toUpperCase(),i.url].join("");i.data&&Object.keys(i.data).length&&(l+=JSON.stringify(i.data));let{signature:p,publicKey:h}=yield this.signText(l);return{"orderly-key":h,"orderly-timestamp":c,"orderly-signature":p}})}signText(i){return b(this,null,function*(){let c=this.keyStore.getOrderlyKey();if(!c)throw new Error("orderlyKeyPair is not defined");let l=P.from(i),p=yield c.sign(l),h=P.from(p).toString("base64");return{signature:je(h),publicKey:yield c.getPublicKey()}})}};var Ze=we(require("eventemitter3"));var ue=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://dev-api-v2.orderly.org"],["klineDataUrl","https://dev-api-v2.orderly.org"],["publicWsUrl","wss://dev-ws-v2.orderly.org"],["publicWebsocketKey","OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY"],["privateWsUrl","wss://dev-ws-private-v2.orderly.org"],["env","dev-evm"]])}get(i){return this.map.get(i)}set(i,c){this.map.set(i,c)}clear(){}},Ie=class extends ue{constructor(c){super();this.configMap=c}_restore(){let c=Object.entries(this.configMap);this.map=new Map(c)}};var Ge=d=>{let i=new te(d||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new J(i)},Xe=()=>{if(typeof window=="undefined")throw new Error("the default signer only supports browsers.");let d=new ee("");return new J(d)};var re=class{constructor(i){this.configStore=i}getContractInfoByEnv(){return{usdcAddress:Le,vaultAddress:Fe,verifyContractAddress:Ve}}};var _e=class{constructor(i=[],c={}){this.providers=i;this.services=c;this.injectProperties={}}register(...i){this.providers.push(...i),i.forEach(c=>{let l=c;l instanceof Function&&(l=new c),this.add(l)})}registerByName(i,c){let l=c;l instanceof Function&&(l=new c),this.addByName(i,l)}get(i){return this.services[i]}getAll(){return Object.assign({},this.services)}add(i){return this.addByName(i.constructor.name,i)}addByName(i,c){return this.services[i]=c,this.services[i.toLowerCase()]=c,this.injectIntoProperties(c,i),this.get(i)}inject(i,c,l){i&&l&&(i[c]=l)}injectIntoProperties(i,c=i.constructor.name){this.getInjectProperty(c.toLowerCase()).forEach(l=>{this.inject(l.target,l.propertyKey,i)})}getInjectProperty(i){return this.injectProperties[i]||(this.injectProperties[i]=[]),this.injectProperties[i]}},ze=_e;var Ee=class d{static getContainer(){return d.container||(d.container=new ze),d.container}static register(...i){this.getContainer().register(...i)}static registerByName(i,c){this.getContainer().registerByName(i,c)}static get(i){return this.getContainer().get(i)}static getAll(){return this.getContainer().getAll()}constructor(){}},He=Ee;var O=require("@orderly.network/types");var Qe=we(require("eventemitter3"));var le=class{constructor(i,c,l){this.configStore=i;this.keyStore=c;this.walletAdapterClass=l;this._ee=new Qe.default;this._state={status:O.AccountStatusEnum.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.contract=new re(i),this._bindEvents()}login(i){if(!i)throw new Error("address is required")}logout(){}setAddress(i,c){return b(this,null,function*(){if(!i)throw new Error("address is required");console.log("setAddress",i,c),this.keyStore.setAddress(i);let l=j(L({},this.stateValue),{status:O.AccountStatusEnum.Connected,address:i});return this._ee.emit("change:status",l),c&&(this.walletClient=new this.walletAdapterClass(c)),yield this._checkAccount(i)})}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get address(){return this.stateValue.address}get chainId(){var i;return(i=this.walletClient)==null?void 0:i.chainId}set position(i){let c=j(L({},this.stateValue),{positon:i});this._ee.emit("change:status",c)}set orders(i){let c=j(L({},this.stateValue),{orders:i});this._ee.emit("change:status",c)}_bindEvents(){this._ee.addListener("change:status",i=>{console.log("change:status",i),this._state=i})}_checkAccount(i){return b(this,null,function*(){console.log("check account is esist",i);let c;try{let l=yield this._checkAccountExist(i);if(console.log("accountInfo:",l),l&&l.account_id)console.log("account is exist"),this.keyStore.setAccountId(i,l.account_id),c=j(L({},this.stateValue),{status:O.AccountStatusEnum.SignedIn,accountId:l.account_id,userId:l.user_id}),this._ee.emit("change:status",c);else return c=j(L({},this.stateValue),{status:O.AccountStatusEnum.NotSignedIn}),this._ee.emit("change:status",c),O.AccountStatusEnum.NotSignedIn;let p=this.keyStore.getOrderlyKey();if(console.log("orderlyKey:::::::",p),c=j(L({},this.stateValue),{status:O.AccountStatusEnum.DisabledTrading}),!p)return console.log("orderlyKey is null"),this._ee.emit("change:status",c),O.AccountStatusEnum.DisabledTrading;let h=yield p.getPublicKey(),o=yield this._checkOrderlyKeyState(l.account_id,h);if(console.log("orderlyKeyStatus:",o),o&&o.orderly_key&&o.key_status==="ACTIVE"){let g=Date.now(),f=o.expiration;if(g>f)return this.keyStore.cleanKey(i,"orderlyKey"),O.AccountStatusEnum.DisabledTrading;let B=j(L({},this.stateValue),{status:O.AccountStatusEnum.EnableTrading});return this._ee.emit("change:status",B),O.AccountStatusEnum.EnableTrading}return this.keyStore.cleanKey(i,"orderlyKey"),O.AccountStatusEnum.NotConnected}catch(l){console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:",l)}return O.AccountStatusEnum.NotSignedIn})}_checkAccountExist(i){return b(this,null,function*(){let c=yield this._simpleFetch(`/v1/get_account?address=${i}&broker_id=woofi_dex`);return c.success?c.data:null})}createAccount(){return b(this,null,function*(){let i=yield this._getRegisterationNonce(),c=this.stateValue.address;if(!c)throw new Error("address is undefined");let[l,p]=qe({registrationNonce:i,chainId:this.walletClient.chainId}),h=yield this.walletClient.send("eth_signTypedData_v4",[c,JSON.stringify(p)]),o=yield this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:h,message:l,userAddress:c}),headers:{"Content-Type":"application/json"}});if(o.success){this.keyStore.setAccountId(c,o.data.account_id);let g=j(L({},this.stateValue),{status:O.AccountStatusEnum.DisabledTrading,accountId:o.data.account_id,userId:o.data.user_id});return this._ee.emit("change:status",g),o}})}createOrderlyKey(i){return b(this,null,function*(){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(this.walletClient===void 0)throw new Error("walletClient is undefined");let c="AddOrderlyKey",l=this.keyStore.generateKey(),p=yield l.getPublicKey(),[h,o]=Je({publicKey:p,chainId:this.walletClient.chainId,primaryType:c,expiration:i}),g=this.stateValue.address;if(!g)throw new Error("address is undefined");let f=yield this.walletClient.send("eth_signTypedData_v4",[g,JSON.stringify(o)]),B=yield this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:f,message:h,userAddress:g}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(B.success){this.keyStore.setKey(g,l);let S=j(L({},this.stateValue),{status:O.AccountStatusEnum.EnableTrading});return this._ee.emit("change:status",S),B}else throw new Error(B.message)})}settlement(){return b(this,null,function*(){var B;let i=yield this._getSettleNonce(),c=this.stateValue.address,l=this.getDomain(!0);console.log("domain:::::::::",l);let[p,h]=Ye({settlePnlNonce:i,chainId:this.walletClient.chainId,domain:l}),o=yield this.walletClient.send("eth_signTypedData_v4",[c,JSON.stringify(h)]);console.log("settlement:",c,p,h,o);let g=yield(B=this.keyStore.getOrderlyKey())==null?void 0:B.getPublicKey(),f=yield this._simpleFetch("/v1/settle_pnl",{method:"POST",body:JSON.stringify({signature:o,message:p,userAddress:c,verifyingContract:l.verifyingContract}),headers:{"Content-Type":"application/json","x-account-id":this.stateValue.accountId,"orderly-key":g,"orderly-timestamp":p.timestamp.toString(),"orderly-signature":o}});if(f.success)return f;throw new Error(f.message)})}disconnect(){return b(this,null,function*(){let i=j(L({},this.stateValue),{status:O.AccountStatusEnum.NotConnected,accountId:void 0,userId:void 0,address:void 0});this._ee.emit("change:status",i)})}_checkOrderlyKeyState(i,c){return b(this,null,function*(){let l=yield this._simpleFetch(`/v1/get_orderly_key?account_id=${i}&orderly_key=${c}`);if(l.success)return l.data;throw new Error(l.message)})}get signer(){return this._singer||(this._singer=new J(this.keyStore)),this._singer}get wallet(){return this.walletClient}_getRegisterationNonce(){return b(this,null,function*(){var c;let i=yield this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(console.log("getRegisterationNonce:",i),i.success)return(c=i.data)==null?void 0:c.registration_nonce;throw new Error(i.message)})}_getSettleNonce(){return b(this,null,function*(){var f;let i=Date.now().toString(),l=[i,"GET","/v1/settle_nonce"].join(""),p=this.signer,{publicKey:h,signature:o}=yield p.signText(l),g=yield this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":h,"orderly-timestamp":i,"orderly-signature":o}});if(g.success)return(f=g.data)==null?void 0:f.settle_nonce;throw new Error(g.message)})}_simpleFetch(l){return b(this,arguments,function*(i,c={}){let p=`${this.configStore.get("apiBaseUrl")}${i}`;return fetch(p,c).then(h=>h.json())})}getDomain(i){return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:i?this.contract.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)}};le.instanceName="account";var he=class{constructor(i){this.web3=i}getBalance(i){return b(this,null,function*(){return yield this.web3.eth.getBalance(i)})}deposit(i,c,l){return b(this,null,function*(){return yield this.web3.eth.sendTransaction({from:i,to:c,value:l})})}send(i,c){return b(this,null,function*(){})}};var ne=require("ethers");var ye=class{constructor(i){console.log("EtherAdapter constructor",i),this._chainId=parseInt(i.chain.id,16),this.provider=new ne.BrowserProvider(i.provider,"any")}getBalance(i){throw new Error("Method not implemented.")}deposit(i,c,l){throw new Error("Method not implemented.")}getAddresses(i){return(0,ne.getAddress)(i)}get chainId(){return this._chainId}send(i,c){return b(this,null,function*(){var l;return yield(l=this.provider)==null?void 0:l.send(i,c)})}verify(i,c){return b(this,null,function*(){let{domain:l,types:p,message:h}=i,o=ne.ethers.verifyTypedData(l,p,h,c);console.log("recovered",o)})}};0&&(module.exports={Account,BaseConfigStore,BaseKeyStore,BaseOrderlyKeyPair,BaseSigner,Contract,EtherAdapter,EventEmitter,LocalStorageStore,MemoryConfigStore,MockKeyStore,SimpleDI,Web3WalletAdapter,getDefaultSigner,getMockSigner});
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
@jspm/core/nodelibs/browser/buffer.js:
|