@orderly.network/core 0.0.53 → 0.0.54
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 +50 -12
- package/dist/index.d.ts +50 -12
- 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
|
@@ -135,6 +135,38 @@ declare class BaseConfigStore extends MemoryConfigStore {
|
|
|
135
135
|
protected _restore(): void;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
type SignatureDomain = {
|
|
139
|
+
name: string;
|
|
140
|
+
version: string;
|
|
141
|
+
chainId: number;
|
|
142
|
+
verifyingContract: string;
|
|
143
|
+
};
|
|
144
|
+
declare const base64url: (aStr: string) => string;
|
|
145
|
+
declare function parseBrokerHash(brokerId: string): string;
|
|
146
|
+
declare function parseAccountId(userAddress: string, brokerId: string): string;
|
|
147
|
+
declare function parseTokenHash(tokenSymbol: string): string;
|
|
148
|
+
declare function calculateStringHash(input: string): string;
|
|
149
|
+
declare function formatByUnits(amount: string, unit?: number | "ether" | "gwei"): string;
|
|
150
|
+
|
|
151
|
+
type utils_SignatureDomain = SignatureDomain;
|
|
152
|
+
declare const utils_base64url: typeof base64url;
|
|
153
|
+
declare const utils_calculateStringHash: typeof calculateStringHash;
|
|
154
|
+
declare const utils_formatByUnits: typeof formatByUnits;
|
|
155
|
+
declare const utils_parseAccountId: typeof parseAccountId;
|
|
156
|
+
declare const utils_parseBrokerHash: typeof parseBrokerHash;
|
|
157
|
+
declare const utils_parseTokenHash: typeof parseTokenHash;
|
|
158
|
+
declare namespace utils {
|
|
159
|
+
export {
|
|
160
|
+
utils_SignatureDomain as SignatureDomain,
|
|
161
|
+
utils_base64url as base64url,
|
|
162
|
+
utils_calculateStringHash as calculateStringHash,
|
|
163
|
+
utils_formatByUnits as formatByUnits,
|
|
164
|
+
utils_parseAccountId as parseAccountId,
|
|
165
|
+
utils_parseBrokerHash as parseBrokerHash,
|
|
166
|
+
utils_parseTokenHash as parseTokenHash,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
138
170
|
declare const getMockSigner: (secretKey?: string) => BaseSigner;
|
|
139
171
|
declare const getDefaultSigner: () => BaseSigner;
|
|
140
172
|
|
|
@@ -320,13 +352,15 @@ interface WalletAdapter {
|
|
|
320
352
|
get chainId(): number;
|
|
321
353
|
get addresses(): string;
|
|
322
354
|
parseUnits: (amount: string) => string;
|
|
323
|
-
|
|
355
|
+
formatUnits: (amount: string) => string;
|
|
324
356
|
send: (method: string, params: Array<any> | Record<string, any>) => Promise<any>;
|
|
325
357
|
signTypedData: (address: string, data: any) => Promise<string>;
|
|
326
358
|
getBalance: (userAddress: string) => Promise<any>;
|
|
327
359
|
call(address: string, method: string, params: any, options: {
|
|
328
360
|
abi: any;
|
|
329
361
|
}): Promise<any>;
|
|
362
|
+
on(eventName: any, listener: any): void;
|
|
363
|
+
off(eventName: any, listener: any): void;
|
|
330
364
|
}
|
|
331
365
|
type WalletAdapterOptions = {
|
|
332
366
|
provider: any;
|
|
@@ -337,13 +371,6 @@ type WalletAdapterOptions = {
|
|
|
337
371
|
};
|
|
338
372
|
type getWalletAdapterFunc = (options: WalletAdapterOptions) => WalletAdapter;
|
|
339
373
|
|
|
340
|
-
type SignatureDomain = {
|
|
341
|
-
name: string;
|
|
342
|
-
version: string;
|
|
343
|
-
chainId: number;
|
|
344
|
-
verifyingContract: string;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
374
|
declare class Assets {
|
|
348
375
|
private readonly configStore;
|
|
349
376
|
private readonly contractManger;
|
|
@@ -356,13 +383,21 @@ declare class Assets {
|
|
|
356
383
|
}): Promise<any>;
|
|
357
384
|
private _generateWithdrawMessage;
|
|
358
385
|
private getWithdrawalNonce;
|
|
359
|
-
getNativeBalance(
|
|
386
|
+
getNativeBalance(options?: {
|
|
387
|
+
decimals?: number;
|
|
388
|
+
}): Promise<string>;
|
|
360
389
|
getBalance(address?: string): Promise<string>;
|
|
361
390
|
getBalanceByAddress(address: string): Promise<string>;
|
|
362
391
|
getAllowance(address?: string): Promise<string>;
|
|
363
|
-
approve(amount?: string): Promise<any>;
|
|
392
|
+
approve(address?: string, amount?: string): Promise<any>;
|
|
393
|
+
approveByAddress(inputs: {
|
|
394
|
+
amount?: string;
|
|
395
|
+
address: string;
|
|
396
|
+
}): Promise<any>;
|
|
397
|
+
private _approve;
|
|
364
398
|
deposit(amount: string): Promise<any>;
|
|
365
399
|
private _simpleFetch;
|
|
400
|
+
get usdcAddress(): string;
|
|
366
401
|
}
|
|
367
402
|
|
|
368
403
|
interface AccountState {
|
|
@@ -418,6 +453,7 @@ declare class Account {
|
|
|
418
453
|
}): Promise<AccountStatusEnum>;
|
|
419
454
|
get stateValue(): AccountState;
|
|
420
455
|
get accountId(): string | undefined;
|
|
456
|
+
get accountIdHashStr(): string | undefined;
|
|
421
457
|
get address(): string | undefined;
|
|
422
458
|
get chainId(): number | string | undefined;
|
|
423
459
|
/**
|
|
@@ -451,7 +487,7 @@ declare class EtherAdapter implements WalletAdapter {
|
|
|
451
487
|
private _address;
|
|
452
488
|
constructor(options: WalletAdapterOptions);
|
|
453
489
|
parseUnits(amount: string): string;
|
|
454
|
-
|
|
490
|
+
formatUnits(amount: string): string;
|
|
455
491
|
getBalance(userAddress: string): Promise<any>;
|
|
456
492
|
deposit(from: string, to: string, amount: string): Promise<any>;
|
|
457
493
|
call(address: string, method: string, params: any[], options: {
|
|
@@ -466,6 +502,8 @@ declare class EtherAdapter implements WalletAdapter {
|
|
|
466
502
|
message: any;
|
|
467
503
|
types: any;
|
|
468
504
|
}, signature: string): Promise<void>;
|
|
505
|
+
on(eventName: any, listener: any): void;
|
|
506
|
+
off(eventName: any, listener: any): void;
|
|
469
507
|
}
|
|
470
508
|
|
|
471
|
-
export { Account, AccountState, BaseConfigStore, BaseContract as BaseContractManager, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigKey, ConfigStore, EtherAdapter, IContract, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WalletAdapter, getDefaultSigner, getMockSigner, getWalletAdapterFunc };
|
|
509
|
+
export { Account, AccountState, BaseConfigStore, BaseContract as BaseContractManager, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigKey, ConfigStore, EtherAdapter, IContract, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WalletAdapter, getDefaultSigner, getMockSigner, getWalletAdapterFunc, utils };
|
package/dist/index.d.ts
CHANGED
|
@@ -135,6 +135,38 @@ declare class BaseConfigStore extends MemoryConfigStore {
|
|
|
135
135
|
protected _restore(): void;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
type SignatureDomain = {
|
|
139
|
+
name: string;
|
|
140
|
+
version: string;
|
|
141
|
+
chainId: number;
|
|
142
|
+
verifyingContract: string;
|
|
143
|
+
};
|
|
144
|
+
declare const base64url: (aStr: string) => string;
|
|
145
|
+
declare function parseBrokerHash(brokerId: string): string;
|
|
146
|
+
declare function parseAccountId(userAddress: string, brokerId: string): string;
|
|
147
|
+
declare function parseTokenHash(tokenSymbol: string): string;
|
|
148
|
+
declare function calculateStringHash(input: string): string;
|
|
149
|
+
declare function formatByUnits(amount: string, unit?: number | "ether" | "gwei"): string;
|
|
150
|
+
|
|
151
|
+
type utils_SignatureDomain = SignatureDomain;
|
|
152
|
+
declare const utils_base64url: typeof base64url;
|
|
153
|
+
declare const utils_calculateStringHash: typeof calculateStringHash;
|
|
154
|
+
declare const utils_formatByUnits: typeof formatByUnits;
|
|
155
|
+
declare const utils_parseAccountId: typeof parseAccountId;
|
|
156
|
+
declare const utils_parseBrokerHash: typeof parseBrokerHash;
|
|
157
|
+
declare const utils_parseTokenHash: typeof parseTokenHash;
|
|
158
|
+
declare namespace utils {
|
|
159
|
+
export {
|
|
160
|
+
utils_SignatureDomain as SignatureDomain,
|
|
161
|
+
utils_base64url as base64url,
|
|
162
|
+
utils_calculateStringHash as calculateStringHash,
|
|
163
|
+
utils_formatByUnits as formatByUnits,
|
|
164
|
+
utils_parseAccountId as parseAccountId,
|
|
165
|
+
utils_parseBrokerHash as parseBrokerHash,
|
|
166
|
+
utils_parseTokenHash as parseTokenHash,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
138
170
|
declare const getMockSigner: (secretKey?: string) => BaseSigner;
|
|
139
171
|
declare const getDefaultSigner: () => BaseSigner;
|
|
140
172
|
|
|
@@ -320,13 +352,15 @@ interface WalletAdapter {
|
|
|
320
352
|
get chainId(): number;
|
|
321
353
|
get addresses(): string;
|
|
322
354
|
parseUnits: (amount: string) => string;
|
|
323
|
-
|
|
355
|
+
formatUnits: (amount: string) => string;
|
|
324
356
|
send: (method: string, params: Array<any> | Record<string, any>) => Promise<any>;
|
|
325
357
|
signTypedData: (address: string, data: any) => Promise<string>;
|
|
326
358
|
getBalance: (userAddress: string) => Promise<any>;
|
|
327
359
|
call(address: string, method: string, params: any, options: {
|
|
328
360
|
abi: any;
|
|
329
361
|
}): Promise<any>;
|
|
362
|
+
on(eventName: any, listener: any): void;
|
|
363
|
+
off(eventName: any, listener: any): void;
|
|
330
364
|
}
|
|
331
365
|
type WalletAdapterOptions = {
|
|
332
366
|
provider: any;
|
|
@@ -337,13 +371,6 @@ type WalletAdapterOptions = {
|
|
|
337
371
|
};
|
|
338
372
|
type getWalletAdapterFunc = (options: WalletAdapterOptions) => WalletAdapter;
|
|
339
373
|
|
|
340
|
-
type SignatureDomain = {
|
|
341
|
-
name: string;
|
|
342
|
-
version: string;
|
|
343
|
-
chainId: number;
|
|
344
|
-
verifyingContract: string;
|
|
345
|
-
};
|
|
346
|
-
|
|
347
374
|
declare class Assets {
|
|
348
375
|
private readonly configStore;
|
|
349
376
|
private readonly contractManger;
|
|
@@ -356,13 +383,21 @@ declare class Assets {
|
|
|
356
383
|
}): Promise<any>;
|
|
357
384
|
private _generateWithdrawMessage;
|
|
358
385
|
private getWithdrawalNonce;
|
|
359
|
-
getNativeBalance(
|
|
386
|
+
getNativeBalance(options?: {
|
|
387
|
+
decimals?: number;
|
|
388
|
+
}): Promise<string>;
|
|
360
389
|
getBalance(address?: string): Promise<string>;
|
|
361
390
|
getBalanceByAddress(address: string): Promise<string>;
|
|
362
391
|
getAllowance(address?: string): Promise<string>;
|
|
363
|
-
approve(amount?: string): Promise<any>;
|
|
392
|
+
approve(address?: string, amount?: string): Promise<any>;
|
|
393
|
+
approveByAddress(inputs: {
|
|
394
|
+
amount?: string;
|
|
395
|
+
address: string;
|
|
396
|
+
}): Promise<any>;
|
|
397
|
+
private _approve;
|
|
364
398
|
deposit(amount: string): Promise<any>;
|
|
365
399
|
private _simpleFetch;
|
|
400
|
+
get usdcAddress(): string;
|
|
366
401
|
}
|
|
367
402
|
|
|
368
403
|
interface AccountState {
|
|
@@ -418,6 +453,7 @@ declare class Account {
|
|
|
418
453
|
}): Promise<AccountStatusEnum>;
|
|
419
454
|
get stateValue(): AccountState;
|
|
420
455
|
get accountId(): string | undefined;
|
|
456
|
+
get accountIdHashStr(): string | undefined;
|
|
421
457
|
get address(): string | undefined;
|
|
422
458
|
get chainId(): number | string | undefined;
|
|
423
459
|
/**
|
|
@@ -451,7 +487,7 @@ declare class EtherAdapter implements WalletAdapter {
|
|
|
451
487
|
private _address;
|
|
452
488
|
constructor(options: WalletAdapterOptions);
|
|
453
489
|
parseUnits(amount: string): string;
|
|
454
|
-
|
|
490
|
+
formatUnits(amount: string): string;
|
|
455
491
|
getBalance(userAddress: string): Promise<any>;
|
|
456
492
|
deposit(from: string, to: string, amount: string): Promise<any>;
|
|
457
493
|
call(address: string, method: string, params: any[], options: {
|
|
@@ -466,6 +502,8 @@ declare class EtherAdapter implements WalletAdapter {
|
|
|
466
502
|
message: any;
|
|
467
503
|
types: any;
|
|
468
504
|
}, signature: string): Promise<void>;
|
|
505
|
+
on(eventName: any, listener: any): void;
|
|
506
|
+
off(eventName: any, listener: any): void;
|
|
469
507
|
}
|
|
470
508
|
|
|
471
|
-
export { Account, AccountState, BaseConfigStore, BaseContract as BaseContractManager, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigKey, ConfigStore, EtherAdapter, IContract, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WalletAdapter, getDefaultSigner, getMockSigner, getWalletAdapterFunc };
|
|
509
|
+
export { Account, AccountState, BaseConfigStore, BaseContract as BaseContractManager, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigKey, ConfigStore, EtherAdapter, IContract, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WalletAdapter, getDefaultSigner, getMockSigner, getWalletAdapterFunc, utils };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var wn=Object.create;var Te=Object.defineProperty;var bn=Object.getOwnPropertyDescriptor;var An=Object.getOwnPropertyNames;var In=Object.getPrototypeOf,En=Object.prototype.hasOwnProperty;var fe=(o,n)=>()=>(o&&(n=o(o=0)),n);var lt=(o,n)=>()=>(n||o((n={exports:{}}).exports,n),n.exports),vn=(o,n)=>{for(var s in n)Te(o,s,{get:n[s],enumerable:!0})},dt=(o,n,s,u)=>{if(n&&typeof n=="object"||typeof n=="function")for(let d of An(n))!En.call(o,d)&&d!==s&&Te(o,d,{get:()=>n[d],enumerable:!(u=bn(n,d))||u.enumerable});return o};var Re=(o,n,s)=>(s=o!=null?wn(In(o)):{},dt(n||!o||!o.__esModule?Te(s,"default",{value:o,enumerable:!0}):s,o)),Tn=o=>dt(Te({},"__esModule",{value:!0}),o);var E=fe(()=>{"use strict"});function Bn(o,n){this.fun=o,this.array=n}function pt(o){var n=Math.floor((Date.now()-te.now())*.001),s=te.now()*.001,u=Math.floor(s)+n,d=Math.floor(s%1*1e9);return o&&(u=u-o[0],d=d-o[1],d<0&&(u--,d+=Fe)),[u,d]}var zn,te,De,Fe,yt=fe(()=>{"use strict";E();T();v();Bn.prototype.run=function(){this.fun.apply(null,this.array)};zn={PATH:"/usr/bin",LANG:navigator.language+".UTF-8",PWD:"/",HOME:"/home",TMP:"/tmp"},te={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0};te.now===void 0&&(De=Date.now(),te.timing&&te.timing.navigationStart&&(De=te.timing.navigationStart),te.now=()=>Date.now()-De);Fe=1e9;pt.bigint=function(o){var n=pt(o);return typeof BigInt>"u"?n[0]*Fe+n[1]:BigInt(n[0]*Fe)+BigInt(n[1])}});var v=fe(()=>{"use strict";yt()});function xn(){if(ht)return me;ht=!0,me.byteLength=g,me.toByteArray=I,me.fromByteArray=_;for(var o=[],n=[],s=typeof Uint8Array<"u"?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=0,p=u.length;d<p;++d)o[d]=u[d],n[u.charCodeAt(d)]=d;n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63;function a(h){var m=h.length;if(m%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var B=h.indexOf("=");B===-1&&(B=m);var x=B===m?0:4-B%4;return[B,x]}function g(h){var m=a(h),B=m[0],x=m[1];return(B+x)*3/4-x}function w(h,m,B){return(m+B)*3/4-B}function I(h){var m,B=a(h),x=B[0],k=B[1],C=new s(w(h,x,k)),U=0,M=k>0?x-4:x,K;for(K=0;K<M;K+=4)m=n[h.charCodeAt(K)]<<18|n[h.charCodeAt(K+1)]<<12|n[h.charCodeAt(K+2)]<<6|n[h.charCodeAt(K+3)],C[U++]=m>>16&255,C[U++]=m>>8&255,C[U++]=m&255;return k===2&&(m=n[h.charCodeAt(K)]<<2|n[h.charCodeAt(K+1)]>>4,C[U++]=m&255),k===1&&(m=n[h.charCodeAt(K)]<<10|n[h.charCodeAt(K+1)]<<4|n[h.charCodeAt(K+2)]>>2,C[U++]=m>>8&255,C[U++]=m&255),C}function f(h){return o[h>>18&63]+o[h>>12&63]+o[h>>6&63]+o[h&63]}function A(h,m,B){for(var x,k=[],C=m;C<B;C+=3)x=(h[C]<<16&16711680)+(h[C+1]<<8&65280)+(h[C+2]&255),k.push(f(x));return k.join("")}function _(h){for(var m,B=h.length,x=B%3,k=[],C=16383,U=0,M=B-x;U<M;U+=C)k.push(A(h,U,U+C>M?M:U+C));return x===1?(m=h[B-1],k.push(o[m>>2]+o[m<<4&63]+"==")):x===2&&(m=(h[B-2]<<8)+h[B-1],k.push(o[m>>10]+o[m>>4&63]+o[m<<2&63]+"=")),k.join("")}return me}function Sn(){if(gt)return Be;gt=!0;return Be.read=function(o,n,s,u,d){var p,a,g=d*8-u-1,w=(1<<g)-1,I=w>>1,f=-7,A=s?d-1:0,_=s?-1:1,h=o[n+A];for(A+=_,p=h&(1<<-f)-1,h>>=-f,f+=g;f>0;p=p*256+o[n+A],A+=_,f-=8);for(a=p&(1<<-f)-1,p>>=-f,f+=u;f>0;a=a*256+o[n+A],A+=_,f-=8);if(p===0)p=1-I;else{if(p===w)return a?NaN:(h?-1:1)*(1/0);a=a+Math.pow(2,u),p=p-I}return(h?-1:1)*a*Math.pow(2,p-u)},Be.write=function(o,n,s,u,d,p){var a,g,w,I=p*8-d-1,f=(1<<I)-1,A=f>>1,_=d===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=u?0:p-1,m=u?1:-1,B=n<0||n===0&&1/n<0?1:0;for(n=Math.abs(n),isNaN(n)||n===1/0?(g=isNaN(n)?1:0,a=f):(a=Math.floor(Math.log(n)/Math.LN2),n*(w=Math.pow(2,-a))<1&&(a--,w*=2),a+A>=1?n+=_/w:n+=_*Math.pow(2,1-A),n*w>=2&&(a++,w/=2),a+A>=f?(g=0,a=f):a+A>=1?(g=(n*w-1)*Math.pow(2,d),a=a+A):(g=n*Math.pow(2,A-1)*Math.pow(2,d),a=0));d>=8;o[s+h]=g&255,h+=m,g/=256,d-=8);for(a=a<<d|g,I+=d;I>0;o[s+h]=a&255,h+=m,a/=256,I-=8);o[s+h-m]|=B*128},Be}function Cn(){if(ft)return ne;ft=!0;let o=xn(),n=Sn(),s=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ne.Buffer=a,ne.SlowBuffer=k,ne.INSPECT_MAX_BYTES=50;let u=2147483647;ne.kMaxLength=u,a.TYPED_ARRAY_SUPPORT=d(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function d(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function p(r){if(r>u)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,a.prototype),e}function a(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return f(r)}return g(r,e,t)}a.poolSize=8192;function g(r,e,t){if(typeof r=="string")return A(r,e);if(ArrayBuffer.isView(r))return h(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(Y(r,ArrayBuffer)||r&&Y(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Y(r,SharedArrayBuffer)||r&&Y(r.buffer,SharedArrayBuffer)))return m(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=r.valueOf&&r.valueOf();if(i!=null&&i!==r)return a.from(i,e,t);let c=B(r);if(c)return c;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return a.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}a.from=function(r,e,t){return g(r,e,t)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function w(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function I(r,e,t){return w(r),r<=0?p(r):e!==void 0?typeof t=="string"?p(r).fill(e,t):p(r).fill(e):p(r)}a.alloc=function(r,e,t){return I(r,e,t)};function f(r){return w(r),p(r<0?0:x(r)|0)}a.allocUnsafe=function(r){return f(r)},a.allocUnsafeSlow=function(r){return f(r)};function A(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!a.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=C(r,e)|0,i=p(t),c=i.write(r,e);return c!==t&&(i=i.slice(0,c)),i}function _(r){let e=r.length<0?0:x(r.length)|0,t=p(e);for(let i=0;i<e;i+=1)t[i]=r[i]&255;return t}function h(r){if(Y(r,Uint8Array)){let e=new Uint8Array(r);return m(e.buffer,e.byteOffset,e.byteLength)}return _(r)}function m(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let i;return e===void 0&&t===void 0?i=new Uint8Array(r):t===void 0?i=new Uint8Array(r,e):i=new Uint8Array(r,e,t),Object.setPrototypeOf(i,a.prototype),i}function B(r){if(a.isBuffer(r)){let e=x(r.length)|0,t=p(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Oe(r.length)?p(0):_(r);if(r.type==="Buffer"&&Array.isArray(r.data))return _(r.data)}function x(r){if(r>=u)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u.toString(16)+" bytes");return r|0}function k(r){return+r!=r&&(r=0),a.alloc(+r)}a.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==a.prototype},a.compare=function(e,t){if(Y(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),Y(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(e)||!a.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,c=t.length;for(let l=0,y=Math.min(i,c);l<y;++l)if(e[l]!==t[l]){i=e[l],c=t[l];break}return i<c?-1:c<i?1:0},a.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return a.alloc(0);let i;if(t===void 0)for(t=0,i=0;i<e.length;++i)t+=e[i].length;let c=a.allocUnsafe(t),l=0;for(i=0;i<e.length;++i){let y=e[i];if(Y(y,Uint8Array))l+y.length>c.length?(a.isBuffer(y)||(y=a.from(y)),y.copy(c,l)):Uint8Array.prototype.set.call(c,y,l);else if(a.isBuffer(y))y.copy(c,l);else throw new TypeError('"list" argument must be an Array of Buffers');l+=y.length}return c};function C(r,e){if(a.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||Y(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&t===0)return 0;let c=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Ne(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return ut(r).length;default:if(c)return i?-1:Ne(r).length;e=(""+e).toLowerCase(),c=!0}}a.byteLength=C;function U(r,e,t){let i=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return un(this,e,t);case"utf8":case"utf-8":return et(this,e,t);case"ascii":return on(this,e,t);case"latin1":case"binary":return cn(this,e,t);case"base64":return sn(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ln(this,e,t);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),i=!0}}a.prototype._isBuffer=!0;function M(r,e,t){let i=r[e];r[e]=r[t],r[t]=i}a.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)M(this,t,t+1);return this},a.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)M(this,t,t+3),M(this,t+1,t+2);return this},a.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)M(this,t,t+7),M(this,t+1,t+6),M(this,t+2,t+5),M(this,t+3,t+4);return this},a.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?et(this,0,e):U.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(e){if(!a.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:a.compare(this,e)===0},a.prototype.inspect=function(){let e="",t=ne.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},s&&(a.prototype[s]=a.prototype.inspect),a.prototype.compare=function(e,t,i,c,l){if(Y(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),i===void 0&&(i=e?e.length:0),c===void 0&&(c=0),l===void 0&&(l=this.length),t<0||i>e.length||c<0||l>this.length)throw new RangeError("out of range index");if(c>=l&&t>=i)return 0;if(c>=l)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,c>>>=0,l>>>=0,this===e)return 0;let y=l-c,S=i-t,R=Math.min(y,S),N=this.slice(c,l),D=e.slice(t,i);for(let P=0;P<R;++P)if(N[P]!==D[P]){y=N[P],S=D[P];break}return y<S?-1:S<y?1:0};function K(r,e,t,i,c){if(r.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Oe(t)&&(t=c?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(c)return-1;t=r.length-1}else if(t<0)if(c)t=0;else return-1;if(typeof e=="string"&&(e=a.from(e,i)),a.isBuffer(e))return e.length===0?-1:H(r,e,t,i,c);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?c?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):H(r,[e],t,i,c);throw new TypeError("val must be string, number or Buffer")}function H(r,e,t,i,c){let l=1,y=r.length,S=e.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(r.length<2||e.length<2)return-1;l=2,y/=2,S/=2,t/=2}function R(D,P){return l===1?D[P]:D.readUInt16BE(P*l)}let N;if(c){let D=-1;for(N=t;N<y;N++)if(R(r,N)===R(e,D===-1?0:N-D)){if(D===-1&&(D=N),N-D+1===S)return D*l}else D!==-1&&(N-=N-D),D=-1}else for(t+S>y&&(t=y-S),N=t;N>=0;N--){let D=!0;for(let P=0;P<S;P++)if(R(r,N+P)!==R(e,P)){D=!1;break}if(D)return N}return-1}a.prototype.includes=function(e,t,i){return this.indexOf(e,t,i)!==-1},a.prototype.indexOf=function(e,t,i){return K(this,e,t,i,!0)},a.prototype.lastIndexOf=function(e,t,i){return K(this,e,t,i,!1)};function q(r,e,t,i){t=Number(t)||0;let c=r.length-t;i?(i=Number(i),i>c&&(i=c)):i=c;let l=e.length;i>l/2&&(i=l/2);let y;for(y=0;y<i;++y){let S=parseInt(e.substr(y*2,2),16);if(Oe(S))return y;r[t+y]=S}return y}function oe(r,e,t,i){return ve(Ne(e,r.length-t),r,t,i)}function tn(r,e,t,i){return ve(hn(e),r,t,i)}function nn(r,e,t,i){return ve(ut(e),r,t,i)}function rn(r,e,t,i){return ve(gn(e,r.length-t),r,t,i)}a.prototype.write=function(e,t,i,c){if(t===void 0)c="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")c=t,i=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(i)?(i=i>>>0,c===void 0&&(c="utf8")):(c=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let l=this.length-t;if((i===void 0||i>l)&&(i=l),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");c||(c="utf8");let y=!1;for(;;)switch(c){case"hex":return q(this,e,t,i);case"utf8":case"utf-8":return oe(this,e,t,i);case"ascii":case"latin1":case"binary":return tn(this,e,t,i);case"base64":return nn(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return rn(this,e,t,i);default:if(y)throw new TypeError("Unknown encoding: "+c);c=(""+c).toLowerCase(),y=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function sn(r,e,t){return e===0&&t===r.length?o.fromByteArray(r):o.fromByteArray(r.slice(e,t))}function et(r,e,t){t=Math.min(r.length,t);let i=[],c=e;for(;c<t;){let l=r[c],y=null,S=l>239?4:l>223?3:l>191?2:1;if(c+S<=t){let R,N,D,P;switch(S){case 1:l<128&&(y=l);break;case 2:R=r[c+1],(R&192)===128&&(P=(l&31)<<6|R&63,P>127&&(y=P));break;case 3:R=r[c+1],N=r[c+2],(R&192)===128&&(N&192)===128&&(P=(l&15)<<12|(R&63)<<6|N&63,P>2047&&(P<55296||P>57343)&&(y=P));break;case 4:R=r[c+1],N=r[c+2],D=r[c+3],(R&192)===128&&(N&192)===128&&(D&192)===128&&(P=(l&15)<<18|(R&63)<<12|(N&63)<<6|D&63,P>65535&&P<1114112&&(y=P))}}y===null?(y=65533,S=1):y>65535&&(y-=65536,i.push(y>>>10&1023|55296),y=56320|y&1023),i.push(y),c+=S}return an(i)}let tt=4096;function an(r){let e=r.length;if(e<=tt)return String.fromCharCode.apply(String,r);let t="",i=0;for(;i<e;)t+=String.fromCharCode.apply(String,r.slice(i,i+=tt));return t}function on(r,e,t){let i="";t=Math.min(r.length,t);for(let c=e;c<t;++c)i+=String.fromCharCode(r[c]&127);return i}function cn(r,e,t){let i="";t=Math.min(r.length,t);for(let c=e;c<t;++c)i+=String.fromCharCode(r[c]);return i}function un(r,e,t){let i=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>i)&&(t=i);let c="";for(let l=e;l<t;++l)c+=fn[r[l]];return c}function ln(r,e,t){let i=r.slice(e,t),c="";for(let l=0;l<i.length-1;l+=2)c+=String.fromCharCode(i[l]+i[l+1]*256);return c}a.prototype.slice=function(e,t){let i=this.length;e=~~e,t=t===void 0?i:~~t,e<0?(e+=i,e<0&&(e=0)):e>i&&(e=i),t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),t<e&&(t=e);let c=this.subarray(e,t);return Object.setPrototypeOf(c,a.prototype),c};function V(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let c=this[e],l=1,y=0;for(;++y<t&&(l*=256);)c+=this[e+y]*l;return c},a.prototype.readUintBE=a.prototype.readUIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let c=this[e+--t],l=1;for(;t>0&&(l*=256);)c+=this[e+--t]*l;return c},a.prototype.readUint8=a.prototype.readUInt8=function(e,t){return e=e>>>0,t||V(e,1,this.length),this[e]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||V(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||V(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||V(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readBigUInt64LE=Q(function(e){e=e>>>0,ue(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&ge(e,this.length-8);let c=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,l=this[++e]+this[++e]*2**8+this[++e]*2**16+i*2**24;return BigInt(c)+(BigInt(l)<<BigInt(32))}),a.prototype.readBigUInt64BE=Q(function(e){e=e>>>0,ue(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&ge(e,this.length-8);let c=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],l=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i;return(BigInt(c)<<BigInt(32))+BigInt(l)}),a.prototype.readIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let c=this[e],l=1,y=0;for(;++y<t&&(l*=256);)c+=this[e+y]*l;return l*=128,c>=l&&(c-=Math.pow(2,8*t)),c},a.prototype.readIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let c=t,l=1,y=this[e+--c];for(;c>0&&(l*=256);)y+=this[e+--c]*l;return l*=128,y>=l&&(y-=Math.pow(2,8*t)),y},a.prototype.readInt8=function(e,t){return e=e>>>0,t||V(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},a.prototype.readInt16LE=function(e,t){e=e>>>0,t||V(e,2,this.length);let i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i},a.prototype.readInt16BE=function(e,t){e=e>>>0,t||V(e,2,this.length);let i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i},a.prototype.readInt32LE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readBigInt64LE=Q(function(e){e=e>>>0,ue(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&ge(e,this.length-8);let c=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(i<<24);return(BigInt(c)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),a.prototype.readBigInt64BE=Q(function(e){e=e>>>0,ue(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&ge(e,this.length-8);let c=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(c)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i)}),a.prototype.readFloatLE=function(e,t){return e=e>>>0,t||V(e,4,this.length),n.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e=e>>>0,t||V(e,4,this.length),n.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||V(e,8,this.length),n.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||V(e,8,this.length),n.read(this,e,!1,52,8)};function z(r,e,t,i,c,l){if(!a.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>c||e<l)throw new RangeError('"value" argument is out of bounds');if(t+i>r.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(e,t,i,c){if(e=+e,t=t>>>0,i=i>>>0,!c){let S=Math.pow(2,8*i)-1;z(this,e,t,i,S,0)}let l=1,y=0;for(this[t]=e&255;++y<i&&(l*=256);)this[t+y]=e/l&255;return t+i},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(e,t,i,c){if(e=+e,t=t>>>0,i=i>>>0,!c){let S=Math.pow(2,8*i)-1;z(this,e,t,i,S,0)}let l=i-1,y=1;for(this[t+l]=e&255;--l>=0&&(y*=256);)this[t+l]=e/y&255;return t+i},a.prototype.writeUint8=a.prototype.writeUInt8=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,1,255,0),this[t]=e&255,t+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||z(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 nt(r,e,t,i,c){ct(e,i,c,r,t,7);let l=Number(e&BigInt(4294967295));r[t++]=l,l=l>>8,r[t++]=l,l=l>>8,r[t++]=l,l=l>>8,r[t++]=l;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,t}function rt(r,e,t,i,c){ct(e,i,c,r,t,7);let l=Number(e&BigInt(4294967295));r[t+7]=l,l=l>>8,r[t+6]=l,l=l>>8,r[t+5]=l,l=l>>8,r[t+4]=l;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=y,y=y>>8,r[t+2]=y,y=y>>8,r[t+1]=y,y=y>>8,r[t]=y,t+8}a.prototype.writeBigUInt64LE=Q(function(e,t=0){return nt(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Q(function(e,t=0){return rt(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(e,t,i,c){if(e=+e,t=t>>>0,!c){let R=Math.pow(2,8*i-1);z(this,e,t,i,R-1,-R)}let l=0,y=1,S=0;for(this[t]=e&255;++l<i&&(y*=256);)e<0&&S===0&&this[t+l-1]!==0&&(S=1),this[t+l]=(e/y>>0)-S&255;return t+i},a.prototype.writeIntBE=function(e,t,i,c){if(e=+e,t=t>>>0,!c){let R=Math.pow(2,8*i-1);z(this,e,t,i,R-1,-R)}let l=i-1,y=1,S=0;for(this[t+l]=e&255;--l>=0&&(y*=256);)e<0&&S===0&&this[t+l+1]!==0&&(S=1),this[t+l]=(e/y>>0)-S&255;return t+i},a.prototype.writeInt8=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},a.prototype.writeInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},a.prototype.writeInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},a.prototype.writeBigInt64LE=Q(function(e,t=0){return nt(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Q(function(e,t=0){return rt(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function it(r,e,t,i,c,l){if(t+i>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function st(r,e,t,i,c){return e=+e,t=t>>>0,c||it(r,e,t,4),n.write(r,e,t,i,23,4),t+4}a.prototype.writeFloatLE=function(e,t,i){return st(this,e,t,!0,i)},a.prototype.writeFloatBE=function(e,t,i){return st(this,e,t,!1,i)};function at(r,e,t,i,c){return e=+e,t=t>>>0,c||it(r,e,t,8),n.write(r,e,t,i,52,8),t+8}a.prototype.writeDoubleLE=function(e,t,i){return at(this,e,t,!0,i)},a.prototype.writeDoubleBE=function(e,t,i){return at(this,e,t,!1,i)},a.prototype.copy=function(e,t,i,c){if(!a.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),!c&&c!==0&&(c=this.length),t>=e.length&&(t=e.length),t||(t=0),c>0&&c<i&&(c=i),c===i||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(c<0)throw new RangeError("sourceEnd out of bounds");c>this.length&&(c=this.length),e.length-t<c-i&&(c=e.length-t+i);let l=c-i;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,i,c):Uint8Array.prototype.set.call(e,this.subarray(i,c),t),l},a.prototype.fill=function(e,t,i,c){if(typeof e=="string"){if(typeof t=="string"?(c=t,t=0,i=this.length):typeof i=="string"&&(c=i,i=this.length),c!==void 0&&typeof c!="string")throw new TypeError("encoding must be a string");if(typeof c=="string"&&!a.isEncoding(c))throw new TypeError("Unknown encoding: "+c);if(e.length===1){let y=e.charCodeAt(0);(c==="utf8"&&y<128||c==="latin1")&&(e=y)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;t=t>>>0,i=i===void 0?this.length:i>>>0,e||(e=0);let l;if(typeof e=="number")for(l=t;l<i;++l)this[l]=e;else{let y=a.isBuffer(e)?e:a.from(e,c),S=y.length;if(S===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(l=0;l<i-t;++l)this[l+t]=y[l%S]}return this};let ce={};function Ke(r,e,t){ce[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(c){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:c,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Ke("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Ke("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),Ke("ERR_OUT_OF_RANGE",function(r,e,t){let i=`The value of "${r}" is out of range.`,c=t;return Number.isInteger(t)&&Math.abs(t)>2**32?c=ot(String(t)):typeof t=="bigint"&&(c=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(c=ot(c)),c+="n"),i+=` It must be ${e}. Received ${c}`,i},RangeError);function ot(r){let e="",t=r.length,i=r[0]==="-"?1:0;for(;t>=i+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function dn(r,e,t){ue(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&ge(e,r.length-(t+1))}function ct(r,e,t,i,c,l){if(r>t||r<e){let y=typeof e=="bigint"?"n":"",S;throw l>3?e===0||e===BigInt(0)?S=`>= 0${y} and < 2${y} ** ${(l+1)*8}${y}`:S=`>= -(2${y} ** ${(l+1)*8-1}${y}) and < 2 ** ${(l+1)*8-1}${y}`:S=`>= ${e}${y} and <= ${t}${y}`,new ce.ERR_OUT_OF_RANGE("value",S,r)}dn(i,c,l)}function ue(r,e){if(typeof r!="number")throw new ce.ERR_INVALID_ARG_TYPE(e,"number",r)}function ge(r,e,t){throw Math.floor(r)!==r?(ue(r,t),new ce.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new ce.ERR_BUFFER_OUT_OF_BOUNDS:new ce.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let pn=/[^+/0-9A-Za-z-_]/g;function yn(r){if(r=r.split("=")[0],r=r.trim().replace(pn,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Ne(r,e){e=e||1/0;let t,i=r.length,c=null,l=[];for(let y=0;y<i;++y){if(t=r.charCodeAt(y),t>55295&&t<57344){if(!c){if(t>56319){(e-=3)>-1&&l.push(239,191,189);continue}else if(y+1===i){(e-=3)>-1&&l.push(239,191,189);continue}c=t;continue}if(t<56320){(e-=3)>-1&&l.push(239,191,189),c=t;continue}t=(c-55296<<10|t-56320)+65536}else c&&(e-=3)>-1&&l.push(239,191,189);if(c=null,t<128){if((e-=1)<0)break;l.push(t)}else if(t<2048){if((e-=2)<0)break;l.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;l.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;l.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return l}function hn(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function gn(r,e){let t,i,c,l=[];for(let y=0;y<r.length&&!((e-=2)<0);++y)t=r.charCodeAt(y),i=t>>8,c=t%256,l.push(c),l.push(i);return l}function ut(r){return o.toByteArray(yn(r))}function ve(r,e,t,i){let c;for(c=0;c<i&&!(c+t>=e.length||c>=r.length);++c)e[c+t]=r[c];return c}function Y(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Oe(r){return r!==r}let fn=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let i=t*16;for(let c=0;c<16;++c)e[i+c]=r[t]+r[c]}return e}();function Q(r){return typeof BigInt>"u"?mn:r}function mn(){throw new Error("BigInt not supported")}return ne}var me,ht,Be,gt,ne,ft,re,O,Jn,Qn,Le=fe(()=>{"use strict";E();T();v();me={},ht=!1;Be={},gt=!1;ne={},ft=!1;re=Cn();re.Buffer;re.SlowBuffer;re.INSPECT_MAX_BYTES;re.kMaxLength;O=re.Buffer,Jn=re.INSPECT_MAX_BYTES,Qn=re.kMaxLength});var T=fe(()=>{"use strict";Le()});var wt=lt((ar,mt)=>{"use strict";E();T();v();function _n(o){if(o.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var u=0;u<o.length;u++){var d=o.charAt(u),p=d.charCodeAt(0);if(n[p]!==255)throw new TypeError(d+" is ambiguous");n[p]=u}var a=o.length,g=o.charAt(0),w=Math.log(a)/Math.log(256),I=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,B=0,x=0,k=h.length;x!==k&&h[x]===0;)x++,m++;for(var C=(k-x)*I+1>>>0,U=new Uint8Array(C);x!==k;){for(var M=h[x],K=0,H=C-1;(M!==0||K<B)&&H!==-1;H--,K++)M+=256*U[H]>>>0,U[H]=M%a>>>0,M=M/a>>>0;if(M!==0)throw new Error("Non-zero carry");B=K,x++}for(var q=C-B;q!==C&&U[q]===0;)q++;for(var oe=g.repeat(m);q<C;++q)oe+=o.charAt(U[q]);return oe}function A(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var m=0,B=0,x=0;h[m]===g;)B++,m++;for(var k=(h.length-m)*w+1>>>0,C=new Uint8Array(k);h[m];){var U=n[h.charCodeAt(m)];if(U===255)return;for(var M=0,K=k-1;(U!==0||M<x)&&K!==-1;K--,M++)U+=a*C[K]>>>0,C[K]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");x=M,m++}for(var H=k-x;H!==k&&C[H]===0;)H++;for(var q=new Uint8Array(B+(k-H)),oe=B;H!==k;)q[oe++]=C[H++];return q}function _(h){var m=A(h);if(m)return m;throw new Error("Non-base"+a+" character")}return{encode:f,decodeUnsafe:A,decode:_}}mt.exports=_n});var At=lt((lr,bt)=>{"use strict";E();T();v();var kn=wt(),Un="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";bt.exports=kn(Un)});var Hn={};vn(Hn,{Account:()=>Ee,BaseConfigStore:()=>Xe,BaseContractManager:()=>Ue,BaseKeyStore:()=>Ae,BaseOrderlyKeyPair:()=>Z,BaseSigner:()=>J,EtherAdapter:()=>Me,EventEmitter:()=>en.default,LocalStorageStore:()=>pe,MemoryConfigStore:()=>Ie,MockKeyStore:()=>ye,SimpleDI:()=>Xt,getDefaultSigner:()=>qt,getMockSigner:()=>zt});module.exports=Tn(Hn);E();T();v();E();T();v();E();T();v();var be=Re(At());E();T();v();var $=2n**255n-19n,le=2n**252n+27742317777372353535851937790883648493n,Ve=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,$e=0x6666666666666666666666666666666666666666666666666666666666666658n,xe={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:$,n:le,h:8,Gx:Ve,Gy:$e},j=(o="")=>{throw new Error(o)},Bt=o=>typeof o=="string",_e=(o,n)=>!(o instanceof Uint8Array)||typeof n=="number"&&n>0&&o.length!==n?j("Uint8Array expected"):o,de=o=>new Uint8Array(o),ke=(o,n)=>_e(Bt(o)?je(o):de(o),n),b=(o,n=$)=>{let s=o%n;return s>=0n?s:n+s},It=o=>o instanceof ee?o:j("Point expected"),Et,ee=class o{constructor(n,s,u,d){this.ex=n,this.ey=s,this.ez=u,this.et=d}static fromAffine(n){return new o(n.x,n.y,1n,b(n.x*n.y))}static fromHex(n,s=!0){let{d:u}=xe;n=ke(n,32);let d=n.slice();d[31]=n[31]&-129;let p=Ct(d);p===0n||(s&&!(0n<p&&p<$)&&j("bad y coord 1"),!s&&!(0n<p&&p<2n**256n)&&j("bad y coord 2"));let a=b(p*p),g=b(a-1n),w=b(u*a+1n),{isValid:I,value:f}=Mn(g,w);I||j("bad y coordinate 3");let A=(f&1n)===1n;return(n[31]&128)!==0!==A&&(f=b(-f)),new o(f,p,1n,b(f*p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(n){let{ex:s,ey:u,ez:d}=this,{ex:p,ey:a,ez:g}=It(n),w=b(s*g),I=b(p*d),f=b(u*g),A=b(a*d);return w===I&&f===A}is0(){return this.equals(Se)}negate(){return new o(b(-this.ex),this.ey,this.ez,b(-this.et))}double(){let{ex:n,ey:s,ez:u}=this,{a:d}=xe,p=b(n*n),a=b(s*s),g=b(2n*b(u*u)),w=b(d*p),I=n+s,f=b(b(I*I)-p-a),A=w+a,_=A-g,h=w-a,m=b(f*_),B=b(A*h),x=b(f*h),k=b(_*A);return new o(m,B,k,x)}add(n){let{ex:s,ey:u,ez:d,et:p}=this,{ex:a,ey:g,ez:w,et:I}=It(n),{a:f,d:A}=xe,_=b(s*a),h=b(u*g),m=b(p*A*I),B=b(d*w),x=b((s+u)*(a+g)-_-h),k=b(B-m),C=b(B+m),U=b(h-f*_),M=b(x*k),K=b(C*U),H=b(x*U),q=b(k*C);return new o(M,K,q,H)}mul(n,s=!0){if(n===0n)return s===!0?j("cannot multiply by 0"):Se;if(typeof n=="bigint"&&0n<n&&n<le||j("invalid scalar, must be < L"),!s&&this.is0()||n===1n)return this;if(this.equals(se))return Dn(n).p;let u=Se,d=se;for(let p=this;n>0n;p=p.double(),n>>=1n)n&1n?u=u.add(p):s&&(d=d.add(p));return u}multiply(n){return this.mul(n)}clearCofactor(){return this.mul(BigInt(xe.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let n=this.mul(le/2n,!1).double();return le%2n&&(n=n.add(this)),n.is0()}toAffine(){let{ex:n,ey:s,ez:u}=this;if(this.is0())return{x:0n,y:0n};let d=_t(u);return b(u*d)!==1n&&j("invalid inverse"),{x:b(n*d),y:b(s*d)}}toRawBytes(){let{x:n,y:s}=this.toAffine(),u=St(s);return u[31]|=n&1n?128:0,u}toHex(){return We(this.toRawBytes())}};ee.BASE=new ee(Ve,$e,1n,b(Ve*$e));ee.ZERO=new ee(0n,1n,1n,0n);var{BASE:se,ZERO:Se}=ee,xt=(o,n)=>o.toString(16).padStart(n,"0"),We=o=>Array.from(o).map(n=>xt(n,2)).join(""),je=o=>{let n=o.length;(!Bt(o)||n%2)&&j("hex invalid 1");let s=de(n/2);for(let u=0;u<s.length;u++){let d=u*2,p=o.slice(d,d+2),a=Number.parseInt(p,16);(Number.isNaN(a)||a<0)&&j("hex invalid 2"),s[u]=a}return s},St=o=>je(xt(o,32*2)).reverse(),Ct=o=>BigInt("0x"+We(de(_e(o)).reverse())),Ce=(...o)=>{let n=de(o.reduce((u,d)=>u+_e(d).length,0)),s=0;return o.forEach(u=>{n.set(u,s),s+=u.length}),n},_t=(o,n=$)=>{(o===0n||n<=0n)&&j("no inverse n="+o+" mod="+n);let s=b(o,n),u=n,d=0n,p=1n,a=1n,g=0n;for(;s!==0n;){let w=u/s,I=u%s,f=d-a*w,A=p-g*w;u=s,s=I,d=a,p=g,a=f,g=A}return u===1n?b(d,n):j("no inverse")},G=(o,n)=>{let s=o;for(;n-- >0n;)s*=s,s%=$;return s},Pn=o=>{let s=o*o%$*o%$,u=G(s,2n)*s%$,d=G(u,1n)*o%$,p=G(d,5n)*d%$,a=G(p,10n)*p%$,g=G(a,20n)*a%$,w=G(g,40n)*g%$,I=G(w,80n)*w%$,f=G(I,80n)*w%$,A=G(f,10n)*p%$;return{pow_p_5_8:G(A,2n)*o%$,b2:s}},vt=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Mn=(o,n)=>{let s=b(n*n*n),u=b(s*s*n),d=Pn(o*u).pow_p_5_8,p=b(o*s*d),a=b(n*p*p),g=p,w=b(p*vt),I=a===o,f=a===b(-o),A=a===b(-o*vt);return I&&(p=g),(f||A)&&(p=w),(b(p)&1n)===1n&&(p=b(-p)),{isValid:I||f,value:p}},He=o=>b(Ct(o),le),we,ze=(...o)=>Ye.sha512Async(...o),kt=(...o)=>typeof we=="function"?we(...o):j("etc.sha512Sync not set"),Ut=o=>{let n=o.slice(0,32);n[0]&=248,n[31]&=127,n[31]|=64;let s=o.slice(32,64),u=He(n),d=se.mul(u),p=d.toRawBytes();return{head:n,prefix:s,scalar:u,point:d,pointBytes:p}},qe=o=>ze(ke(o,32)).then(Ut),Kn=o=>Ut(kt(ke(o,32))),Pt=o=>qe(o).then(n=>n.pointBytes);function Nn(o,n){return o?ze(n.hashable).then(n.finish):n.finish(kt(n.hashable))}var On=(o,n,s)=>{let{pointBytes:u,scalar:d}=o,p=He(n),a=se.mul(p).toRawBytes();return{hashable:Ce(a,u,s),finish:I=>{let f=b(p+He(I)*d,le);return _e(Ce(a,St(f)),64)}}},Mt=async(o,n)=>{let s=ke(o),u=await qe(n),d=await ze(u.prefix,s);return Nn(!0,On(u,d,s))};var Tt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Ye={bytesToHex:We,hexToBytes:je,concatBytes:Ce,mod:b,invert:_t,randomBytes:o=>{let n=Tt();return n||j("crypto.getRandomValues must be defined"),n.getRandomValues(de(o))},sha512Async:async(...o)=>{let n=Tt();n||j("crypto.subtle or etc.sha512Async must be defined");let s=Ce(...o);return de(await n.subtle.digest("SHA-512",s.buffer))},sha512Sync:void 0};Object.defineProperties(Ye,{sha512Sync:{configurable:!1,get(){return we},set(o){we||(we=o)}}});var Kt={getExtendedPublicKeyAsync:qe,getExtendedPublicKey:Kn,randomPrivateKey:()=>Ye.randomBytes(32),precompute(o=8,n=se){return n.multiply(3n),n}},ie=8,Rn=()=>{let o=[],n=256/ie+1,s=se,u=s;for(let d=0;d<n;d++){u=s,o.push(u);for(let p=1;p<2**(ie-1);p++)u=u.add(s),o.push(u);s=u.double()}return o},Dn=o=>{let n=Et||(Et=Rn()),s=(f,A)=>{let _=A.negate();return f?_:A},u=Se,d=se,p=1+256/ie,a=2**(ie-1),g=BigInt(2**ie-1),w=2**ie,I=BigInt(ie);for(let f=0;f<p;f++){let A=f*a,_=Number(o&g);o>>=I,_>a&&(_-=w,o+=1n);let h=A,m=A+Math.abs(_)-1,B=f%2!==0,x=_<0;_===0?d=d.add(s(B,n[h])):u=u.add(s(x,n[m]))}return{p:u,f:d}};var Z=class o{static generateKey(){let n,s;do n=Kt.randomPrivateKey(),s=(0,be.encode)(n);while(s.length!==44);return new o(s)}constructor(n){this.secretKey=n;let s=(0,be.decode)(n);this.privateKey=O.from(s).toString("hex")}async sign(n){return await Mt(n,this.privateKey)}async getPublicKey(){let n=await Pt(this.privateKey);return`ed25519:${(0,be.encode)(n)}`}toString(){return this.privateKey}};var Ae=class{constructor(n="testnet"){this.networkId=n}get keyPrefix(){return`orderly_${this.networkId}_`}},pe=class extends Ae{getOrderlyKey(n){let s;if(n)s=this.getItem(n,"orderlyKey");else{let u=this.getAddress();if(!u)return null;s=this.getItem(u,"orderlyKey")}return s?new Z(s):null}getAccountId(n){return this.getItem(n,"accountId")}setAccountId(n,s){this.setItem(n,{accountId:s})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(n){localStorage.setItem(`${this.keyPrefix}address`,n)}generateKey(){return Z.generateKey()}setKey(n,s){this.setItem(n,{orderlyKey:s.secretKey})}cleanAllKey(n){localStorage.removeItem(`${this.keyPrefix}${n}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(n,s){let u=this.getItem(n);delete u[s],localStorage.setItem(`${this.keyPrefix}${n}`,JSON.stringify(u))}setItem(n,s){let u=`${this.keyPrefix}${n}`,d=localStorage.getItem(u);d?d=JSON.parse(d):d={},localStorage.setItem(u,JSON.stringify({...d,...s}))}getItem(n,s){let u=`${this.keyPrefix}${n}`,d=localStorage.getItem(u);return d?d=JSON.parse(d):d={},typeof s>"u"?d:d[s]}},ye=class{constructor(n){this.secretKey=n}generateKey(){return new Z(this.secretKey)}getOrderlyKey(){return new Z(this.secretKey)}getAccountId(){return""}setAccountId(n){}getAddress(){return""}setAddress(n){}setKey(n,s){}cleanAllKey(){}cleanKey(n){}};E();T();v();E();T();v();E();T();v();var X={EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],Registration:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"timestamp",type:"uint64"},{name:"registrationNonce",type:"uint256"}],Withdraw:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"receiver",type:"address"},{name:"token",type:"string"},{name:"amount",type:"uint256"},{name:"withdrawNonce",type:"uint64"},{name:"timestamp",type:"uint64"}],AddOrderlyKey:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"orderlyKey",type:"string"},{name:"scope",type:"string"},{name:"timestamp",type:"uint64"},{name:"expiration",type:"uint64"}],SettlePnl:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"settleNonce",type:"uint64"},{name:"timestamp",type:"uint64"}]},Nt="0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291",Ot="0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D",Rt="0x1826B75e2ef249173FC735149AE4B8e9ea10abff";var he=require("ethers"),Dt=function(o){return o.replace(/\+/g,"-").replace(/\//g,"_")};function Ln(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function Ft(o,n){return{name:"Orderly",version:"1",chainId:o,verifyingContract:n?Ln():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function Lt(o){let{chainId:n,registrationNonce:s,brokerId:u}=o,d=Date.now(),p="Registration",a={brokerId:u,chainId:n,timestamp:d,registrationNonce:s},g={EIP712Domain:X.EIP712Domain,[p]:X[p]};return[a,{domain:Ft(n),message:a,primaryType:p,types:g}]}function Vt(o){let{publicKey:n,chainId:s,primaryType:u,brokerId:d,expiration:p=365}=o,a=Date.now(),g={brokerId:d,orderlyKey:n,scope:"read,trading",chainId:s,timestamp:a,expiration:a+1e3*60*60*24*p},w={EIP712Domain:X.EIP712Domain,[u]:X[u]},I={domain:Ft(s),message:g,primaryType:u,types:w};return[g,I]}function $t(o){let{chainId:n,settlePnlNonce:s,domain:u,brokerId:d}=o,p="SettlePnl",a=new Date().getTime(),g={EIP712Domain:X.EIP712Domain,[p]:X[p]},w={brokerId:d,chainId:n,timestamp:a,settleNonce:s};return[w,{domain:u,message:w,primaryType:p,types:g}]}function Ge(o){return jt(o)}function Ht(o,n){let s=he.AbiCoder.defaultAbiCoder();return(0,he.keccak256)(s.encode(["address","bytes32"],[o,Ge(n)]))}function Wt(o){return jt(o)}function jt(o){return(0,he.solidityPackedKeccak256)(["string"],[o])}Le();var J=class{constructor(n){this.keyStore=n}async sign(n){let s=Date.now().toString(),u=[s,n.method.toUpperCase(),n.url].join("");n.data&&Object.keys(n.data).length&&(u+=JSON.stringify(n.data));let{signature:d,publicKey:p}=await this.signText(u);return{"orderly-key":p,"orderly-timestamp":s,"orderly-signature":d}}async signText(n){let s=this.keyStore.getOrderlyKey();if(!s)throw new Error("orderlyKeyPair is not defined");let u=O.from(n),d=await s.sign(u),p=O.from(d).toString("base64");return{signature:Dt(p),publicKey:await s.getPublicKey()}}};var en=Re(require("eventemitter3"));E();T();v();E();T();v();var Ie=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://dev-api-iap-v2.orderly.org"],["klineDataUrl","https://testnet-api-evm.orderly.org"],["publicWsUrl","wss://dev-ws-v2.orderly.org"],["publicWebsocketKey","OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY"],["privateWsUrl","wss://dev-ws-private-v2.orderly.org"],["operatorUrl","https://testnet-operator-evm.orderly.org"],["swapSupportApiUrl","https://woofi-api.mer1in.com"],["brokerId","woofi_dex"],["env","dev-evm"]])}get(n){return this.map.get(n)}set(n,s){this.map.set(n,s)}clear(){}},Xe=class extends Ie{constructor(s){super();this.configMap=s}_restore(){let s=Object.entries(this.configMap);this.map=new Map(s)}};var zt=o=>{let n=new ye(o||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new J(n)},qt=()=>{if(typeof window>"u")throw new Error("the default signer only supports browsers.");let o=new pe("");return new J(o)};E();T();v();var Ze=[{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"},{internalType:"uint8",name:"decimals_",type:"uint8"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"issue",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_to",type:"address"},{internalType:"uint256",name:"_amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"_paused",type:"bool"}],name:"pauseTransfers",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}];var Yt=[{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 Ue=class{constructor(n){this.configStore=n}getContractInfoByEnv(){return{usdcAddress:Nt,usdcAbi:Ze,vaultAddress:Ot,vaultAbi:Yt,verifyContractAddress:Rt,erc20Abi:Ze}}};E();T();v();E();T();v();var Je=class{constructor(n=[],s={}){this.providers=n;this.services=s;this.injectProperties={}}register(...n){this.providers.push(...n),n.forEach(s=>{let u=s;u instanceof Function&&(u=new s),this.add(u)})}registerByName(n,s){let u=s;u instanceof Function&&(u=new s),this.addByName(n,u)}get(n){return this.services[n]}getAll(){return Object.assign({},this.services)}add(n){return this.addByName(n.constructor.name,n)}addByName(n,s){return this.services[n]=s,this.services[n.toLowerCase()]=s,this.injectIntoProperties(s,n),this.get(n)}inject(n,s,u){n&&u&&(n[s]=u)}injectIntoProperties(n,s=n.constructor.name){this.getInjectProperty(s.toLowerCase()).forEach(u=>{this.inject(u.target,u.propertyKey,n)})}getInjectProperty(n){return this.injectProperties[n]||(this.injectProperties[n]=[]),this.injectProperties[n]}},Gt=Je;var Qe=class o{static getContainer(){return o.container||(o.container=new Gt),o.container}static register(...n){this.getContainer().register(...n)}static registerByName(n,s){this.getContainer().registerByName(n,s)}static get(n){return this.getContainer().get(n)}static getAll(){return this.getContainer().getAll()}constructor(){}},Xt=Qe;E();T();v();var W=require("@orderly.network/types");var Jt=Re(require("eventemitter3"));E();T();v();var Zt=require("ethers");var Pe=class{constructor(n,s,u){this.configStore=n;this.contractManger=s;this.account=u}async withdraw(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");if(!this.account.stateValue.address)throw new Error("account address is rqeuired");let{chainId:s,token:u,amount:d}=n,p="/v1/withdraw_request",a=await this.getWithdrawalNonce(),g=this.account.getDomain(!0),[w,I]=this._generateWithdrawMessage({chainId:s,receiver:this.account.stateValue.address,token:u,amount:this.account.walletClient.parseUnits(d.toString()),nonce:a,domain:g}),A={signature:await this.account.signTypedData(I),message:w,userAddress:this.account.stateValue.address,verifyingContract:g.verifyingContract},_={method:"POST",url:p,data:A},h=await this.account.signer.sign(_);return await this._simpleFetch(p,{method:"POST",body:JSON.stringify(A),headers:{"Content-Type":"application/json","orderly-account-id":this.account.stateValue.accountId,...h}})}_generateWithdrawMessage(n){let{chainId:s,receiver:u,token:d,amount:p,domain:a,nonce:g}=n,w="Withdraw",I=Date.now(),f={EIP712Domain:X.EIP712Domain,[w]:X[w]},A={brokerId:this.configStore.get("brokerId"),chainId:s,receiver:u,token:d,amount:p,timestamp:I,withdrawNonce:g};return[A,{domain:a,message:A,primaryType:w,types:f}]}async getWithdrawalNonce(){let n=Date.now().toString(),s="/v1/withdraw_nonce",u=[n,"GET",s].join(""),d=this.account.signer,{publicKey:p,signature:a}=await d.signText(u),g=await this._simpleFetch(s,{headers:{"orderly-account-id":this.account.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.withdraw_nonce;throw new Error(g.message)}async getNativeBalance(){console.log("getNativeBalance",this.account.stateValue.address);let n=await this.account.walletClient?.getBalance(this.account.stateValue.address);return this.account.walletClient.fromUnits(n)}async getBalance(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),u=await this.account.walletClient?.call(n??s.usdcAddress,"balanceOf",[this.account.stateValue.address],{abi:s.usdcAbi});return console.log("-----*****-----",u),this.account.walletClient?.fromUnits(u)}async getBalanceByAddress(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv();console.log("address:::::",n);let u=await this.account.walletClient?.call(n,"balanceOf",[this.account.stateValue.address],{abi:s.erc20Abi});return this.account.walletClient?.fromUnits(u)}async getAllowance(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),u=await this.account.walletClient?.call(n??s.usdcAddress,"allowance",[this.account.stateValue.address,s.vaultAddress],{abi:s.usdcAbi});return this.account.walletClient?.fromUnits(u)}async approve(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");let s=this.contractManger.getContractInfoByEnv(),u=typeof n<"u"&&n!==""?this.account.walletClient.parseUnits(n):Zt.ethers.MaxUint256.toString(),d=await this.account.walletClient?.call(s.usdcAddress,"approve",[s.vaultAddress,u],{abi:s.usdcAbi});return console.log("-----*****-----",d),d}async deposit(n){console.log("deposit amount:",n);let s=this.configStore.get("brokerId");if(!s)throw new Error("brokerId is required");let u=this.contractManger.getContractInfoByEnv(),d={accountId:Ht(this.account.stateValue.address,s),brokerHash:Ge(s),tokenHash:Wt("USDC"),tokenAmount:this.account.walletClient?.parseUnits(n)};return await this.account.walletClient?.call(u.vaultAddress,"deposit",[d],{abi:u.vaultAbi})}async _simpleFetch(n,s={}){let u=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(u,s).then(d=>d.json())}};var Ee=class{constructor(n,s,u,d){this.configStore=n;this.keyStore=s;this.contractManger=u;this.getWalletAdapter=d;this._ee=new Jt.default;this._state={status:W.AccountStatusEnum.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.assetsManager=new Pe(n,u,this),this._bindEvents()}login(n){if(!n)throw new Error("address is required")}logout(){}async setAddress(n,s){if(!n)throw new Error("address is required");this.keyStore.setAddress(n);let u={...this.stateValue,status:W.AccountStatusEnum.Connected,address:n,connectWallet:s?.wallet};return this._ee.emit("change:status",u),s&&(this.walletClient=this.getWalletAdapter({...s,address:n})),await this._checkAccount(n)}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get address(){return this.stateValue.address}get chainId(){return this.walletClient?.chainId}set position(n){let s={...this.stateValue,positon:n};this._ee.emit("change:status",s)}set orders(n){let s={...this.stateValue,orders:n};this._ee.emit("change:status",s)}_bindEvents(){this._ee.addListener("change:status",n=>{console.log("change:status",n),this._state=n})}async _checkAccount(n){let s;try{let u=await this._checkAccountExist(n);if(u&&u.account_id)console.log("account is exist"),this.keyStore.setAccountId(n,u.account_id),s={...this.stateValue,status:W.AccountStatusEnum.SignedIn,accountId:u.account_id,userId:u.user_id},this._ee.emit("change:status",s);else return s={...this.stateValue,status:W.AccountStatusEnum.NotSignedIn},this._ee.emit("change:status",s),W.AccountStatusEnum.NotSignedIn;let d=this.keyStore.getOrderlyKey();if(s={...this.stateValue,status:W.AccountStatusEnum.DisabledTrading},!d)return console.log("orderlyKey is null"),this._ee.emit("change:status",s),W.AccountStatusEnum.DisabledTrading;let p=await d.getPublicKey(),a=await this._checkOrderlyKeyState(u.account_id,p);if(a&&a.orderly_key&&a.key_status==="ACTIVE"){let g=Date.now(),w=a.expiration;if(g>w)return this.keyStore.cleanKey(n,"orderlyKey"),W.AccountStatusEnum.DisabledTrading;let I={...this.stateValue,status:W.AccountStatusEnum.EnableTrading};return this._ee.emit("change:status",I),W.AccountStatusEnum.EnableTrading}return this.keyStore.cleanKey(n,"orderlyKey"),W.AccountStatusEnum.NotConnected}catch(u){console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:",u)}return W.AccountStatusEnum.NotSignedIn}async _checkAccountExist(n){let s=await this._simpleFetch(`/v1/get_account?address=${n}&broker_id=woofi_dex`);return s.success?s.data:null}async createAccount(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getRegisterationNonce(),s=this.stateValue.address;if(!s)throw new Error("address is undefined");let[u,d]=Lt({registrationNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId")}),p=await this.signTypedData(d),a=await this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:p,message:u,userAddress:s}),headers:{"Content-Type":"application/json"}});if(a.success){this.keyStore.setAccountId(s,a.data.account_id);let g={...this.stateValue,status:W.AccountStatusEnum.DisabledTrading,accountId:a.data.account_id,userId:a.data.user_id};return this._ee.emit("change:status",g),a}}async signTypedData(n){return this.walletClient?await this.walletClient.signTypedData(this.stateValue.address,JSON.stringify(n)):Promise.reject("walletClient is undefined")}async createOrderlyKey(n){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(!this.walletClient)throw new Error("walletClient is undefined");let s="AddOrderlyKey",u=this.keyStore.generateKey(),d=await u.getPublicKey(),[p,a]=Vt({publicKey:d,chainId:this.walletClient.chainId,primaryType:s,expiration:n,brokerId:this.configStore.get("brokerId")}),g=this.stateValue.address;if(!g)throw new Error("address is undefined");let w=await this.signTypedData(a),I=await this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:w,message:p,userAddress:g}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(I.success){this.keyStore.setKey(g,u);let f={...this.stateValue,status:W.AccountStatusEnum.EnableTrading};return this._ee.emit("change:status",f),I}else throw new Error(I.message)}async settle(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getSettleNonce(),s=this.stateValue.address,u=this.getDomain(!0),d="/v1/settle_pnl",[p,a]=$t({settlePnlNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId"),domain:u}),w={signature:await this.signTypedData(a),message:p,userAddress:s,verifyingContract:u.verifyingContract},I={method:"POST",url:d,data:w},f=await this.signer.sign(I),A=await this._simpleFetch(d,{method:"POST",body:JSON.stringify(w),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,...f}});if(A.success)return A;throw new Error(A.message)}async disconnect(){let n={...this.stateValue,status:W.AccountStatusEnum.NotConnected,accountId:void 0,userId:void 0,address:void 0};this._ee.emit("change:status",n)}async _checkOrderlyKeyState(n,s){let u=await this._simpleFetch(`/v1/get_orderly_key?account_id=${n}&orderly_key=${s}`);if(u.success)return u.data;throw new Error(u.message)}get signer(){return this._singer||(this._singer=new J(this.keyStore)),this._singer}get wallet(){return this.walletClient}async _getRegisterationNonce(){let n=await this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(n.success)return n.data?.registration_nonce;throw new Error(n.message)}async _getSettleNonce(){let n=Date.now().toString(),u=[n,"GET","/v1/settle_nonce"].join(""),d=this.signer,{publicKey:p,signature:a}=await d.signText(u),g=await this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.settle_nonce;throw new Error(g.message)}async _simpleFetch(n,s={}){let u=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(u,s).then(d=>d.json())}getDomain(n){if(!this.walletClient)throw new Error("walletClient is undefined");return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:n?this.contractManger.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}get on(){return this._ee.on.bind(this._ee)}get once(){return this._ee.once.bind(this._ee)}get off(){return this._ee.off.bind(this._ee)}};Ee.instanceName="account";E();T();v();E();T();v();var ae=require("ethers"),Qt=require("@enzoferey/ethers-error-parser"),Me=class{constructor(n){console.log("EtherAdapter constructor",n),this._chainId=parseInt(n.chain.id,16),this.provider=new ae.BrowserProvider(n.provider,"any"),this._address=n.address}parseUnits(n){return ae.ethers.parseUnits(n,6).toString()}fromUnits(n){return ae.ethers.formatUnits(n,6)}getBalance(n){return console.log("*********",n),this.provider.getBalance(n).then(s=>(console.log("getBalance",s),s),s=>{console.log("get native token balance error",s)})}deposit(n,s,u){throw new Error("Method not implemented.")}async call(n,s,u,d){let p=await this.provider?.getSigner();return new ae.ethers.Contract(n,d.abi,p)[s].apply(null,u).catch(g=>{throw(0,Qt.getParsedEthersError)(g)})}get chainId(){return this._chainId}get addresses(){return this._address}async send(n,s){return await this.provider?.send(n,s)}async signTypedData(n,s){return await this.provider?.send("eth_signTypedData_v4",[n,s])}async verify(n,s){let{domain:u,types:d,message:p}=n,a=ae.ethers.verifyTypedData(u,d,p,s);console.log("recovered",a)}};0&&(module.exports={Account,BaseConfigStore,BaseContractManager,BaseKeyStore,BaseOrderlyKeyPair,BaseSigner,EtherAdapter,EventEmitter,LocalStorageStore,MemoryConfigStore,MockKeyStore,SimpleDI,getDefaultSigner,getMockSigner});
|
|
1
|
+
"use strict";var In=Object.create;var Te=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var vn=Object.getOwnPropertyNames;var Tn=Object.getPrototypeOf,Bn=Object.prototype.hasOwnProperty;var fe=(o,n)=>()=>(o&&(n=o(o=0)),n);var mt=(o,n)=>()=>(n||o((n={exports:{}}).exports,n),n.exports),wt=(o,n)=>{for(var s in n)Te(o,s,{get:n[s],enumerable:!0})},bt=(o,n,s,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let d of vn(n))!Bn.call(o,d)&&d!==s&&Te(o,d,{get:()=>n[d],enumerable:!(c=En(n,d))||c.enumerable});return o};var De=(o,n,s)=>(s=o!=null?In(Tn(o)):{},bt(n||!o||!o.__esModule?Te(s,"default",{value:o,enumerable:!0}):s,o)),xn=o=>bt(Te({},"__esModule",{value:!0}),o);var E=fe(()=>{"use strict"});function Sn(o,n){this.fun=o,this.array=n}function At(o){var n=Math.floor((Date.now()-ne.now())*.001),s=ne.now()*.001,c=Math.floor(s)+n,d=Math.floor(s%1*1e9);return o&&(c=c-o[0],d=d-o[1],d<0&&(c--,d+=Le)),[c,d]}var Yn,ne,Fe,Le,It=fe(()=>{"use strict";E();T();v();Sn.prototype.run=function(){this.fun.apply(null,this.array)};Yn={PATH:"/usr/bin",LANG:navigator.language+".UTF-8",PWD:"/",HOME:"/home",TMP:"/tmp"},ne={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0};ne.now===void 0&&(Fe=Date.now(),ne.timing&&ne.timing.navigationStart&&(Fe=ne.timing.navigationStart),ne.now=()=>Date.now()-Fe);Le=1e9;At.bigint=function(o){var n=At(o);return typeof BigInt>"u"?n[0]*Le+n[1]:BigInt(n[0]*Le)+BigInt(n[1])}});var v=fe(()=>{"use strict";It()});function Cn(){if(Et)return me;Et=!0,me.byteLength=g,me.toByteArray=I,me.fromByteArray=_;for(var o=[],n=[],s=typeof Uint8Array<"u"?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=0,p=c.length;d<p;++d)o[d]=c[d],n[c.charCodeAt(d)]=d;n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63;function a(h){var m=h.length;if(m%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var B=h.indexOf("=");B===-1&&(B=m);var x=B===m?0:4-B%4;return[B,x]}function g(h){var m=a(h),B=m[0],x=m[1];return(B+x)*3/4-x}function w(h,m,B){return(m+B)*3/4-B}function I(h){var m,B=a(h),x=B[0],k=B[1],C=new s(w(h,x,k)),U=0,M=k>0?x-4:x,K;for(K=0;K<M;K+=4)m=n[h.charCodeAt(K)]<<18|n[h.charCodeAt(K+1)]<<12|n[h.charCodeAt(K+2)]<<6|n[h.charCodeAt(K+3)],C[U++]=m>>16&255,C[U++]=m>>8&255,C[U++]=m&255;return k===2&&(m=n[h.charCodeAt(K)]<<2|n[h.charCodeAt(K+1)]>>4,C[U++]=m&255),k===1&&(m=n[h.charCodeAt(K)]<<10|n[h.charCodeAt(K+1)]<<4|n[h.charCodeAt(K+2)]>>2,C[U++]=m>>8&255,C[U++]=m&255),C}function f(h){return o[h>>18&63]+o[h>>12&63]+o[h>>6&63]+o[h&63]}function A(h,m,B){for(var x,k=[],C=m;C<B;C+=3)x=(h[C]<<16&16711680)+(h[C+1]<<8&65280)+(h[C+2]&255),k.push(f(x));return k.join("")}function _(h){for(var m,B=h.length,x=B%3,k=[],C=16383,U=0,M=B-x;U<M;U+=C)k.push(A(h,U,U+C>M?M:U+C));return x===1?(m=h[B-1],k.push(o[m>>2]+o[m<<4&63]+"==")):x===2&&(m=(h[B-2]<<8)+h[B-1],k.push(o[m>>10]+o[m>>4&63]+o[m<<2&63]+"=")),k.join("")}return me}function _n(){if(vt)return Be;vt=!0;return Be.read=function(o,n,s,c,d){var p,a,g=d*8-c-1,w=(1<<g)-1,I=w>>1,f=-7,A=s?d-1:0,_=s?-1:1,h=o[n+A];for(A+=_,p=h&(1<<-f)-1,h>>=-f,f+=g;f>0;p=p*256+o[n+A],A+=_,f-=8);for(a=p&(1<<-f)-1,p>>=-f,f+=c;f>0;a=a*256+o[n+A],A+=_,f-=8);if(p===0)p=1-I;else{if(p===w)return a?NaN:(h?-1:1)*(1/0);a=a+Math.pow(2,c),p=p-I}return(h?-1:1)*a*Math.pow(2,p-c)},Be.write=function(o,n,s,c,d,p){var a,g,w,I=p*8-d-1,f=(1<<I)-1,A=f>>1,_=d===23?Math.pow(2,-24)-Math.pow(2,-77):0,h=c?0:p-1,m=c?1:-1,B=n<0||n===0&&1/n<0?1:0;for(n=Math.abs(n),isNaN(n)||n===1/0?(g=isNaN(n)?1:0,a=f):(a=Math.floor(Math.log(n)/Math.LN2),n*(w=Math.pow(2,-a))<1&&(a--,w*=2),a+A>=1?n+=_/w:n+=_*Math.pow(2,1-A),n*w>=2&&(a++,w/=2),a+A>=f?(g=0,a=f):a+A>=1?(g=(n*w-1)*Math.pow(2,d),a=a+A):(g=n*Math.pow(2,A-1)*Math.pow(2,d),a=0));d>=8;o[s+h]=g&255,h+=m,g/=256,d-=8);for(a=a<<d|g,I+=d;I>0;o[s+h]=a&255,h+=m,a/=256,I-=8);o[s+h-m]|=B*128},Be}function kn(){if(Tt)return re;Tt=!0;let o=Cn(),n=_n(),s=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;re.Buffer=a,re.SlowBuffer=k,re.INSPECT_MAX_BYTES=50;let c=2147483647;re.kMaxLength=c,a.TYPED_ARRAY_SUPPORT=d(),!a.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function d(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(a.prototype,"parent",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.buffer}}),Object.defineProperty(a.prototype,"offset",{enumerable:!0,get:function(){if(a.isBuffer(this))return this.byteOffset}});function p(r){if(r>c)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,a.prototype),e}function a(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return f(r)}return g(r,e,t)}a.poolSize=8192;function g(r,e,t){if(typeof r=="string")return A(r,e);if(ArrayBuffer.isView(r))return h(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(Y(r,ArrayBuffer)||r&&Y(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(Y(r,SharedArrayBuffer)||r&&Y(r.buffer,SharedArrayBuffer)))return m(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let i=r.valueOf&&r.valueOf();if(i!=null&&i!==r)return a.from(i,e,t);let u=B(r);if(u)return u;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return a.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}a.from=function(r,e,t){return g(r,e,t)},Object.setPrototypeOf(a.prototype,Uint8Array.prototype),Object.setPrototypeOf(a,Uint8Array);function w(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function I(r,e,t){return w(r),r<=0?p(r):e!==void 0?typeof t=="string"?p(r).fill(e,t):p(r).fill(e):p(r)}a.alloc=function(r,e,t){return I(r,e,t)};function f(r){return w(r),p(r<0?0:x(r)|0)}a.allocUnsafe=function(r){return f(r)},a.allocUnsafeSlow=function(r){return f(r)};function A(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!a.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=C(r,e)|0,i=p(t),u=i.write(r,e);return u!==t&&(i=i.slice(0,u)),i}function _(r){let e=r.length<0?0:x(r.length)|0,t=p(e);for(let i=0;i<e;i+=1)t[i]=r[i]&255;return t}function h(r){if(Y(r,Uint8Array)){let e=new Uint8Array(r);return m(e.buffer,e.byteOffset,e.byteLength)}return _(r)}function m(r,e,t){if(e<0||r.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(r.byteLength<e+(t||0))throw new RangeError('"length" is outside of buffer bounds');let i;return e===void 0&&t===void 0?i=new Uint8Array(r):t===void 0?i=new Uint8Array(r,e):i=new Uint8Array(r,e,t),Object.setPrototypeOf(i,a.prototype),i}function B(r){if(a.isBuffer(r)){let e=x(r.length)|0,t=p(e);return t.length===0||r.copy(t,0,0,e),t}if(r.length!==void 0)return typeof r.length!="number"||Re(r.length)?p(0):_(r);if(r.type==="Buffer"&&Array.isArray(r.data))return _(r.data)}function x(r){if(r>=c)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+c.toString(16)+" bytes");return r|0}function k(r){return+r!=r&&(r=0),a.alloc(+r)}a.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==a.prototype},a.compare=function(e,t){if(Y(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),Y(t,Uint8Array)&&(t=a.from(t,t.offset,t.byteLength)),!a.isBuffer(e)||!a.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let i=e.length,u=t.length;for(let l=0,y=Math.min(i,u);l<y;++l)if(e[l]!==t[l]){i=e[l],u=t[l];break}return i<u?-1:u<i?1:0},a.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return a.alloc(0);let i;if(t===void 0)for(t=0,i=0;i<e.length;++i)t+=e[i].length;let u=a.allocUnsafe(t),l=0;for(i=0;i<e.length;++i){let y=e[i];if(Y(y,Uint8Array))l+y.length>u.length?(a.isBuffer(y)||(y=a.from(y)),y.copy(u,l)):Uint8Array.prototype.set.call(u,y,l);else if(a.isBuffer(y))y.copy(u,l);else throw new TypeError('"list" argument must be an Array of Buffers');l+=y.length}return u};function C(r,e){if(a.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||Y(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,i=arguments.length>2&&arguments[2]===!0;if(!i&&t===0)return 0;let u=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return Oe(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return ft(r).length;default:if(u)return i?-1:Oe(r).length;e=(""+e).toLowerCase(),u=!0}}a.byteLength=C;function U(r,e,t){let i=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return pn(this,e,t);case"utf8":case"utf-8":return ot(this,e,t);case"ascii":return ln(this,e,t);case"latin1":case"binary":return dn(this,e,t);case"base64":return cn(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return yn(this,e,t);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),i=!0}}a.prototype._isBuffer=!0;function M(r,e,t){let i=r[e];r[e]=r[t],r[t]=i}a.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)M(this,t,t+1);return this},a.prototype.swap32=function(){let e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)M(this,t,t+3),M(this,t+1,t+2);return this},a.prototype.swap64=function(){let e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)M(this,t,t+7),M(this,t+1,t+6),M(this,t+2,t+5),M(this,t+3,t+4);return this},a.prototype.toString=function(){let e=this.length;return e===0?"":arguments.length===0?ot(this,0,e):U.apply(this,arguments)},a.prototype.toLocaleString=a.prototype.toString,a.prototype.equals=function(e){if(!a.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:a.compare(this,e)===0},a.prototype.inspect=function(){let e="",t=re.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},s&&(a.prototype[s]=a.prototype.inspect),a.prototype.compare=function(e,t,i,u,l){if(Y(e,Uint8Array)&&(e=a.from(e,e.offset,e.byteLength)),!a.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),i===void 0&&(i=e?e.length:0),u===void 0&&(u=0),l===void 0&&(l=this.length),t<0||i>e.length||u<0||l>this.length)throw new RangeError("out of range index");if(u>=l&&t>=i)return 0;if(u>=l)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,u>>>=0,l>>>=0,this===e)return 0;let y=l-u,S=i-t,R=Math.min(y,S),N=this.slice(u,l),D=e.slice(t,i);for(let P=0;P<R;++P)if(N[P]!==D[P]){y=N[P],S=D[P];break}return y<S?-1:S<y?1:0};function K(r,e,t,i,u){if(r.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,Re(t)&&(t=u?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(u)return-1;t=r.length-1}else if(t<0)if(u)t=0;else return-1;if(typeof e=="string"&&(e=a.from(e,i)),a.isBuffer(e))return e.length===0?-1:H(r,e,t,i,u);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?u?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):H(r,[e],t,i,u);throw new TypeError("val must be string, number or Buffer")}function H(r,e,t,i,u){let l=1,y=r.length,S=e.length;if(i!==void 0&&(i=String(i).toLowerCase(),i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le")){if(r.length<2||e.length<2)return-1;l=2,y/=2,S/=2,t/=2}function R(D,P){return l===1?D[P]:D.readUInt16BE(P*l)}let N;if(u){let D=-1;for(N=t;N<y;N++)if(R(r,N)===R(e,D===-1?0:N-D)){if(D===-1&&(D=N),N-D+1===S)return D*l}else D!==-1&&(N-=N-D),D=-1}else for(t+S>y&&(t=y-S),N=t;N>=0;N--){let D=!0;for(let P=0;P<S;P++)if(R(r,N+P)!==R(e,P)){D=!1;break}if(D)return N}return-1}a.prototype.includes=function(e,t,i){return this.indexOf(e,t,i)!==-1},a.prototype.indexOf=function(e,t,i){return K(this,e,t,i,!0)},a.prototype.lastIndexOf=function(e,t,i){return K(this,e,t,i,!1)};function q(r,e,t,i){t=Number(t)||0;let u=r.length-t;i?(i=Number(i),i>u&&(i=u)):i=u;let l=e.length;i>l/2&&(i=l/2);let y;for(y=0;y<i;++y){let S=parseInt(e.substr(y*2,2),16);if(Re(S))return y;r[t+y]=S}return y}function ce(r,e,t,i){return ve(Oe(e,r.length-t),r,t,i)}function sn(r,e,t,i){return ve(mn(e),r,t,i)}function an(r,e,t,i){return ve(ft(e),r,t,i)}function on(r,e,t,i){return ve(wn(e,r.length-t),r,t,i)}a.prototype.write=function(e,t,i,u){if(t===void 0)u="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")u=t,i=this.length,t=0;else if(isFinite(t))t=t>>>0,isFinite(i)?(i=i>>>0,u===void 0&&(u="utf8")):(u=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let l=this.length-t;if((i===void 0||i>l)&&(i=l),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");u||(u="utf8");let y=!1;for(;;)switch(u){case"hex":return q(this,e,t,i);case"utf8":case"utf-8":return ce(this,e,t,i);case"ascii":case"latin1":case"binary":return sn(this,e,t,i);case"base64":return an(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return on(this,e,t,i);default:if(y)throw new TypeError("Unknown encoding: "+u);u=(""+u).toLowerCase(),y=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function cn(r,e,t){return e===0&&t===r.length?o.fromByteArray(r):o.fromByteArray(r.slice(e,t))}function ot(r,e,t){t=Math.min(r.length,t);let i=[],u=e;for(;u<t;){let l=r[u],y=null,S=l>239?4:l>223?3:l>191?2:1;if(u+S<=t){let R,N,D,P;switch(S){case 1:l<128&&(y=l);break;case 2:R=r[u+1],(R&192)===128&&(P=(l&31)<<6|R&63,P>127&&(y=P));break;case 3:R=r[u+1],N=r[u+2],(R&192)===128&&(N&192)===128&&(P=(l&15)<<12|(R&63)<<6|N&63,P>2047&&(P<55296||P>57343)&&(y=P));break;case 4:R=r[u+1],N=r[u+2],D=r[u+3],(R&192)===128&&(N&192)===128&&(D&192)===128&&(P=(l&15)<<18|(R&63)<<12|(N&63)<<6|D&63,P>65535&&P<1114112&&(y=P))}}y===null?(y=65533,S=1):y>65535&&(y-=65536,i.push(y>>>10&1023|55296),y=56320|y&1023),i.push(y),u+=S}return un(i)}let ct=4096;function un(r){let e=r.length;if(e<=ct)return String.fromCharCode.apply(String,r);let t="",i=0;for(;i<e;)t+=String.fromCharCode.apply(String,r.slice(i,i+=ct));return t}function ln(r,e,t){let i="";t=Math.min(r.length,t);for(let u=e;u<t;++u)i+=String.fromCharCode(r[u]&127);return i}function dn(r,e,t){let i="";t=Math.min(r.length,t);for(let u=e;u<t;++u)i+=String.fromCharCode(r[u]);return i}function pn(r,e,t){let i=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>i)&&(t=i);let u="";for(let l=e;l<t;++l)u+=bn[r[l]];return u}function yn(r,e,t){let i=r.slice(e,t),u="";for(let l=0;l<i.length-1;l+=2)u+=String.fromCharCode(i[l]+i[l+1]*256);return u}a.prototype.slice=function(e,t){let i=this.length;e=~~e,t=t===void 0?i:~~t,e<0?(e+=i,e<0&&(e=0)):e>i&&(e=i),t<0?(t+=i,t<0&&(t=0)):t>i&&(t=i),t<e&&(t=e);let u=this.subarray(e,t);return Object.setPrototypeOf(u,a.prototype),u};function V(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}a.prototype.readUintLE=a.prototype.readUIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let u=this[e],l=1,y=0;for(;++y<t&&(l*=256);)u+=this[e+y]*l;return u},a.prototype.readUintBE=a.prototype.readUIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let u=this[e+--t],l=1;for(;t>0&&(l*=256);)u+=this[e+--t]*l;return u},a.prototype.readUint8=a.prototype.readUInt8=function(e,t){return e=e>>>0,t||V(e,1,this.length),this[e]},a.prototype.readUint16LE=a.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||V(e,2,this.length),this[e]|this[e+1]<<8},a.prototype.readUint16BE=a.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||V(e,2,this.length),this[e]<<8|this[e+1]},a.prototype.readUint32LE=a.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||V(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},a.prototype.readUint32BE=a.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},a.prototype.readBigUInt64LE=Q(function(e){e=e>>>0,le(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&ge(e,this.length-8);let u=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,l=this[++e]+this[++e]*2**8+this[++e]*2**16+i*2**24;return BigInt(u)+(BigInt(l)<<BigInt(32))}),a.prototype.readBigUInt64BE=Q(function(e){e=e>>>0,le(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&ge(e,this.length-8);let u=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],l=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i;return(BigInt(u)<<BigInt(32))+BigInt(l)}),a.prototype.readIntLE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let u=this[e],l=1,y=0;for(;++y<t&&(l*=256);)u+=this[e+y]*l;return l*=128,u>=l&&(u-=Math.pow(2,8*t)),u},a.prototype.readIntBE=function(e,t,i){e=e>>>0,t=t>>>0,i||V(e,t,this.length);let u=t,l=1,y=this[e+--u];for(;u>0&&(l*=256);)y+=this[e+--u]*l;return l*=128,y>=l&&(y-=Math.pow(2,8*t)),y},a.prototype.readInt8=function(e,t){return e=e>>>0,t||V(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},a.prototype.readInt16LE=function(e,t){e=e>>>0,t||V(e,2,this.length);let i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i},a.prototype.readInt16BE=function(e,t){e=e>>>0,t||V(e,2,this.length);let i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i},a.prototype.readInt32LE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},a.prototype.readInt32BE=function(e,t){return e=e>>>0,t||V(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},a.prototype.readBigInt64LE=Q(function(e){e=e>>>0,le(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&ge(e,this.length-8);let u=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(i<<24);return(BigInt(u)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),a.prototype.readBigInt64BE=Q(function(e){e=e>>>0,le(e,"offset");let t=this[e],i=this[e+7];(t===void 0||i===void 0)&&ge(e,this.length-8);let u=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(u)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+i)}),a.prototype.readFloatLE=function(e,t){return e=e>>>0,t||V(e,4,this.length),n.read(this,e,!0,23,4)},a.prototype.readFloatBE=function(e,t){return e=e>>>0,t||V(e,4,this.length),n.read(this,e,!1,23,4)},a.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||V(e,8,this.length),n.read(this,e,!0,52,8)},a.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||V(e,8,this.length),n.read(this,e,!1,52,8)};function z(r,e,t,i,u,l){if(!a.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>u||e<l)throw new RangeError('"value" argument is out of bounds');if(t+i>r.length)throw new RangeError("Index out of range")}a.prototype.writeUintLE=a.prototype.writeUIntLE=function(e,t,i,u){if(e=+e,t=t>>>0,i=i>>>0,!u){let S=Math.pow(2,8*i)-1;z(this,e,t,i,S,0)}let l=1,y=0;for(this[t]=e&255;++y<i&&(l*=256);)this[t+y]=e/l&255;return t+i},a.prototype.writeUintBE=a.prototype.writeUIntBE=function(e,t,i,u){if(e=+e,t=t>>>0,i=i>>>0,!u){let S=Math.pow(2,8*i)-1;z(this,e,t,i,S,0)}let l=i-1,y=1;for(this[t+l]=e&255;--l>=0&&(y*=256);)this[t+l]=e/y&255;return t+i},a.prototype.writeUint8=a.prototype.writeUInt8=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,1,255,0),this[t]=e&255,t+1},a.prototype.writeUint16LE=a.prototype.writeUInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeUint16BE=a.prototype.writeUInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeUint32LE=a.prototype.writeUInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},a.prototype.writeUint32BE=a.prototype.writeUInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||z(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 ut(r,e,t,i,u){gt(e,i,u,r,t,7);let l=Number(e&BigInt(4294967295));r[t++]=l,l=l>>8,r[t++]=l,l=l>>8,r[t++]=l,l=l>>8,r[t++]=l;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,y=y>>8,r[t++]=y,t}function lt(r,e,t,i,u){gt(e,i,u,r,t,7);let l=Number(e&BigInt(4294967295));r[t+7]=l,l=l>>8,r[t+6]=l,l=l>>8,r[t+5]=l,l=l>>8,r[t+4]=l;let y=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=y,y=y>>8,r[t+2]=y,y=y>>8,r[t+1]=y,y=y>>8,r[t]=y,t+8}a.prototype.writeBigUInt64LE=Q(function(e,t=0){return ut(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeBigUInt64BE=Q(function(e,t=0){return lt(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),a.prototype.writeIntLE=function(e,t,i,u){if(e=+e,t=t>>>0,!u){let R=Math.pow(2,8*i-1);z(this,e,t,i,R-1,-R)}let l=0,y=1,S=0;for(this[t]=e&255;++l<i&&(y*=256);)e<0&&S===0&&this[t+l-1]!==0&&(S=1),this[t+l]=(e/y>>0)-S&255;return t+i},a.prototype.writeIntBE=function(e,t,i,u){if(e=+e,t=t>>>0,!u){let R=Math.pow(2,8*i-1);z(this,e,t,i,R-1,-R)}let l=i-1,y=1,S=0;for(this[t+l]=e&255;--l>=0&&(y*=256);)e<0&&S===0&&this[t+l+1]!==0&&(S=1),this[t+l]=(e/y>>0)-S&255;return t+i},a.prototype.writeInt8=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},a.prototype.writeInt16LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},a.prototype.writeInt16BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},a.prototype.writeInt32LE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},a.prototype.writeInt32BE=function(e,t,i){return e=+e,t=t>>>0,i||z(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},a.prototype.writeBigInt64LE=Q(function(e,t=0){return ut(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),a.prototype.writeBigInt64BE=Q(function(e,t=0){return lt(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function dt(r,e,t,i,u,l){if(t+i>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function pt(r,e,t,i,u){return e=+e,t=t>>>0,u||dt(r,e,t,4),n.write(r,e,t,i,23,4),t+4}a.prototype.writeFloatLE=function(e,t,i){return pt(this,e,t,!0,i)},a.prototype.writeFloatBE=function(e,t,i){return pt(this,e,t,!1,i)};function yt(r,e,t,i,u){return e=+e,t=t>>>0,u||dt(r,e,t,8),n.write(r,e,t,i,52,8),t+8}a.prototype.writeDoubleLE=function(e,t,i){return yt(this,e,t,!0,i)},a.prototype.writeDoubleBE=function(e,t,i){return yt(this,e,t,!1,i)},a.prototype.copy=function(e,t,i,u){if(!a.isBuffer(e))throw new TypeError("argument should be a Buffer");if(i||(i=0),!u&&u!==0&&(u=this.length),t>=e.length&&(t=e.length),t||(t=0),u>0&&u<i&&(u=i),u===i||e.length===0||this.length===0)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(i<0||i>=this.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("sourceEnd out of bounds");u>this.length&&(u=this.length),e.length-t<u-i&&(u=e.length-t+i);let l=u-i;return this===e&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(t,i,u):Uint8Array.prototype.set.call(e,this.subarray(i,u),t),l},a.prototype.fill=function(e,t,i,u){if(typeof e=="string"){if(typeof t=="string"?(u=t,t=0,i=this.length):typeof i=="string"&&(u=i,i=this.length),u!==void 0&&typeof u!="string")throw new TypeError("encoding must be a string");if(typeof u=="string"&&!a.isEncoding(u))throw new TypeError("Unknown encoding: "+u);if(e.length===1){let y=e.charCodeAt(0);(u==="utf8"&&y<128||u==="latin1")&&(e=y)}}else typeof e=="number"?e=e&255:typeof e=="boolean"&&(e=Number(e));if(t<0||this.length<t||this.length<i)throw new RangeError("Out of range index");if(i<=t)return this;t=t>>>0,i=i===void 0?this.length:i>>>0,e||(e=0);let l;if(typeof e=="number")for(l=t;l<i;++l)this[l]=e;else{let y=a.isBuffer(e)?e:a.from(e,u),S=y.length;if(S===0)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(l=0;l<i-t;++l)this[l+t]=y[l%S]}return this};let ue={};function Ne(r,e,t){ue[r]=class extends t{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${r}]`,this.stack,delete this.name}get code(){return r}set code(u){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:u,writable:!0})}toString(){return`${this.name} [${r}]: ${this.message}`}}}Ne("ERR_BUFFER_OUT_OF_BOUNDS",function(r){return r?`${r} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),Ne("ERR_INVALID_ARG_TYPE",function(r,e){return`The "${r}" argument must be of type number. Received type ${typeof e}`},TypeError),Ne("ERR_OUT_OF_RANGE",function(r,e,t){let i=`The value of "${r}" is out of range.`,u=t;return Number.isInteger(t)&&Math.abs(t)>2**32?u=ht(String(t)):typeof t=="bigint"&&(u=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(u=ht(u)),u+="n"),i+=` It must be ${e}. Received ${u}`,i},RangeError);function ht(r){let e="",t=r.length,i=r[0]==="-"?1:0;for(;t>=i+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function hn(r,e,t){le(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&ge(e,r.length-(t+1))}function gt(r,e,t,i,u,l){if(r>t||r<e){let y=typeof e=="bigint"?"n":"",S;throw l>3?e===0||e===BigInt(0)?S=`>= 0${y} and < 2${y} ** ${(l+1)*8}${y}`:S=`>= -(2${y} ** ${(l+1)*8-1}${y}) and < 2 ** ${(l+1)*8-1}${y}`:S=`>= ${e}${y} and <= ${t}${y}`,new ue.ERR_OUT_OF_RANGE("value",S,r)}hn(i,u,l)}function le(r,e){if(typeof r!="number")throw new ue.ERR_INVALID_ARG_TYPE(e,"number",r)}function ge(r,e,t){throw Math.floor(r)!==r?(le(r,t),new ue.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new ue.ERR_BUFFER_OUT_OF_BOUNDS:new ue.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}let gn=/[^+/0-9A-Za-z-_]/g;function fn(r){if(r=r.split("=")[0],r=r.trim().replace(gn,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Oe(r,e){e=e||1/0;let t,i=r.length,u=null,l=[];for(let y=0;y<i;++y){if(t=r.charCodeAt(y),t>55295&&t<57344){if(!u){if(t>56319){(e-=3)>-1&&l.push(239,191,189);continue}else if(y+1===i){(e-=3)>-1&&l.push(239,191,189);continue}u=t;continue}if(t<56320){(e-=3)>-1&&l.push(239,191,189),u=t;continue}t=(u-55296<<10|t-56320)+65536}else u&&(e-=3)>-1&&l.push(239,191,189);if(u=null,t<128){if((e-=1)<0)break;l.push(t)}else if(t<2048){if((e-=2)<0)break;l.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;l.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;l.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return l}function mn(r){let e=[];for(let t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function wn(r,e){let t,i,u,l=[];for(let y=0;y<r.length&&!((e-=2)<0);++y)t=r.charCodeAt(y),i=t>>8,u=t%256,l.push(u),l.push(i);return l}function ft(r){return o.toByteArray(fn(r))}function ve(r,e,t,i){let u;for(u=0;u<i&&!(u+t>=e.length||u>=r.length);++u)e[u+t]=r[u];return u}function Y(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function Re(r){return r!==r}let bn=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let i=t*16;for(let u=0;u<16;++u)e[i+u]=r[t]+r[u]}return e}();function Q(r){return typeof BigInt>"u"?An:r}function An(){throw new Error("BigInt not supported")}return re}var me,Et,Be,vt,re,Tt,ie,O,er,tr,Ve=fe(()=>{"use strict";E();T();v();me={},Et=!1;Be={},vt=!1;re={},Tt=!1;ie=kn();ie.Buffer;ie.SlowBuffer;ie.INSPECT_MAX_BYTES;ie.kMaxLength;O=ie.Buffer,er=ie.INSPECT_MAX_BYTES,tr=ie.kMaxLength});var T=fe(()=>{"use strict";Ve()});var xt=mt((cr,Bt)=>{"use strict";E();T();v();function Un(o){if(o.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var c=0;c<o.length;c++){var d=o.charAt(c),p=d.charCodeAt(0);if(n[p]!==255)throw new TypeError(d+" is ambiguous");n[p]=c}var a=o.length,g=o.charAt(0),w=Math.log(a)/Math.log(256),I=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,B=0,x=0,k=h.length;x!==k&&h[x]===0;)x++,m++;for(var C=(k-x)*I+1>>>0,U=new Uint8Array(C);x!==k;){for(var M=h[x],K=0,H=C-1;(M!==0||K<B)&&H!==-1;H--,K++)M+=256*U[H]>>>0,U[H]=M%a>>>0,M=M/a>>>0;if(M!==0)throw new Error("Non-zero carry");B=K,x++}for(var q=C-B;q!==C&&U[q]===0;)q++;for(var ce=g.repeat(m);q<C;++q)ce+=o.charAt(U[q]);return ce}function A(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;for(var m=0,B=0,x=0;h[m]===g;)B++,m++;for(var k=(h.length-m)*w+1>>>0,C=new Uint8Array(k);h[m];){var U=n[h.charCodeAt(m)];if(U===255)return;for(var M=0,K=k-1;(U!==0||M<x)&&K!==-1;K--,M++)U+=a*C[K]>>>0,C[K]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");x=M,m++}for(var H=k-x;H!==k&&C[H]===0;)H++;for(var q=new Uint8Array(B+(k-H)),ce=B;H!==k;)q[ce++]=C[H++];return q}function _(h){var m=A(h);if(m)return m;throw new Error("Non-base"+a+" character")}return{encode:f,decodeUnsafe:A,decode:_}}Bt.exports=Un});var Ct=mt((pr,St)=>{"use strict";E();T();v();var Pn=xt(),Mn="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";St.exports=Pn(Mn)});var jn={};wt(jn,{Account:()=>Ee,BaseConfigStore:()=>nt,BaseContractManager:()=>Pe,BaseKeyStore:()=>Ae,BaseOrderlyKeyPair:()=>Z,BaseSigner:()=>J,EtherAdapter:()=>Ke,EventEmitter:()=>rn.default,LocalStorageStore:()=>ye,MemoryConfigStore:()=>Ie,MockKeyStore:()=>he,SimpleDI:()=>en,getDefaultSigner:()=>qt,getMockSigner:()=>zt,utils:()=>tt});module.exports=xn(jn);E();T();v();E();T();v();E();T();v();var be=De(Ct());E();T();v();var $=2n**255n-19n,de=2n**252n+27742317777372353535851937790883648493n,$e=0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51an,He=0x6666666666666666666666666666666666666666666666666666666666666658n,xe={a:-1n,d:37095705934669439343138083508754565189542113879843219016388785533085940283555n,p:$,n:de,h:8,Gx:$e,Gy:He},j=(o="")=>{throw new Error(o)},Mt=o=>typeof o=="string",_e=(o,n)=>!(o instanceof Uint8Array)||typeof n=="number"&&n>0&&o.length!==n?j("Uint8Array expected"):o,pe=o=>new Uint8Array(o),ke=(o,n)=>_e(Mt(o)?ze(o):pe(o),n),b=(o,n=$)=>{let s=o%n;return s>=0n?s:n+s},_t=o=>o instanceof ee?o:j("Point expected"),kt,ee=class o{constructor(n,s,c,d){this.ex=n,this.ey=s,this.ez=c,this.et=d}static fromAffine(n){return new o(n.x,n.y,1n,b(n.x*n.y))}static fromHex(n,s=!0){let{d:c}=xe;n=ke(n,32);let d=n.slice();d[31]=n[31]&-129;let p=Ot(d);p===0n||(s&&!(0n<p&&p<$)&&j("bad y coord 1"),!s&&!(0n<p&&p<2n**256n)&&j("bad y coord 2"));let a=b(p*p),g=b(a-1n),w=b(c*a+1n),{isValid:I,value:f}=Nn(g,w);I||j("bad y coordinate 3");let A=(f&1n)===1n;return(n[31]&128)!==0!==A&&(f=b(-f)),new o(f,p,1n,b(f*p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}equals(n){let{ex:s,ey:c,ez:d}=this,{ex:p,ey:a,ez:g}=_t(n),w=b(s*g),I=b(p*d),f=b(c*g),A=b(a*d);return w===I&&f===A}is0(){return this.equals(Se)}negate(){return new o(b(-this.ex),this.ey,this.ez,b(-this.et))}double(){let{ex:n,ey:s,ez:c}=this,{a:d}=xe,p=b(n*n),a=b(s*s),g=b(2n*b(c*c)),w=b(d*p),I=n+s,f=b(b(I*I)-p-a),A=w+a,_=A-g,h=w-a,m=b(f*_),B=b(A*h),x=b(f*h),k=b(_*A);return new o(m,B,k,x)}add(n){let{ex:s,ey:c,ez:d,et:p}=this,{ex:a,ey:g,ez:w,et:I}=_t(n),{a:f,d:A}=xe,_=b(s*a),h=b(c*g),m=b(p*A*I),B=b(d*w),x=b((s+c)*(a+g)-_-h),k=b(B-m),C=b(B+m),U=b(h-f*_),M=b(x*k),K=b(C*U),H=b(x*U),q=b(k*C);return new o(M,K,q,H)}mul(n,s=!0){if(n===0n)return s===!0?j("cannot multiply by 0"):Se;if(typeof n=="bigint"&&0n<n&&n<de||j("invalid scalar, must be < L"),!s&&this.is0()||n===1n)return this;if(this.equals(ae))return Ln(n).p;let c=Se,d=ae;for(let p=this;n>0n;p=p.double(),n>>=1n)n&1n?c=c.add(p):s&&(d=d.add(p));return c}multiply(n){return this.mul(n)}clearCofactor(){return this.mul(BigInt(xe.h),!1)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){let n=this.mul(de/2n,!1).double();return de%2n&&(n=n.add(this)),n.is0()}toAffine(){let{ex:n,ey:s,ez:c}=this;if(this.is0())return{x:0n,y:0n};let d=Rt(c);return b(c*d)!==1n&&j("invalid inverse"),{x:b(n*d),y:b(s*d)}}toRawBytes(){let{x:n,y:s}=this.toAffine(),c=Nt(s);return c[31]|=n&1n?128:0,c}toHex(){return je(this.toRawBytes())}};ee.BASE=new ee($e,He,1n,b($e*He));ee.ZERO=new ee(0n,1n,1n,0n);var{BASE:ae,ZERO:Se}=ee,Kt=(o,n)=>o.toString(16).padStart(n,"0"),je=o=>Array.from(o).map(n=>Kt(n,2)).join(""),ze=o=>{let n=o.length;(!Mt(o)||n%2)&&j("hex invalid 1");let s=pe(n/2);for(let c=0;c<s.length;c++){let d=c*2,p=o.slice(d,d+2),a=Number.parseInt(p,16);(Number.isNaN(a)||a<0)&&j("hex invalid 2"),s[c]=a}return s},Nt=o=>ze(Kt(o,32*2)).reverse(),Ot=o=>BigInt("0x"+je(pe(_e(o)).reverse())),Ce=(...o)=>{let n=pe(o.reduce((c,d)=>c+_e(d).length,0)),s=0;return o.forEach(c=>{n.set(c,s),s+=c.length}),n},Rt=(o,n=$)=>{(o===0n||n<=0n)&&j("no inverse n="+o+" mod="+n);let s=b(o,n),c=n,d=0n,p=1n,a=1n,g=0n;for(;s!==0n;){let w=c/s,I=c%s,f=d-a*w,A=p-g*w;c=s,s=I,d=a,p=g,a=f,g=A}return c===1n?b(d,n):j("no inverse")},G=(o,n)=>{let s=o;for(;n-- >0n;)s*=s,s%=$;return s},Kn=o=>{let s=o*o%$*o%$,c=G(s,2n)*s%$,d=G(c,1n)*o%$,p=G(d,5n)*d%$,a=G(p,10n)*p%$,g=G(a,20n)*a%$,w=G(g,40n)*g%$,I=G(w,80n)*w%$,f=G(I,80n)*w%$,A=G(f,10n)*p%$;return{pow_p_5_8:G(A,2n)*o%$,b2:s}},Ut=19681161376707505956807079304988542015446066515923890162744021073123829784752n,Nn=(o,n)=>{let s=b(n*n*n),c=b(s*s*n),d=Kn(o*c).pow_p_5_8,p=b(o*s*d),a=b(n*p*p),g=p,w=b(p*Ut),I=a===o,f=a===b(-o),A=a===b(-o*Ut);return I&&(p=g),(f||A)&&(p=w),(b(p)&1n)===1n&&(p=b(-p)),{isValid:I||f,value:p}},We=o=>b(Ot(o),de),we,qe=(...o)=>Ge.sha512Async(...o),Dt=(...o)=>typeof we=="function"?we(...o):j("etc.sha512Sync not set"),Ft=o=>{let n=o.slice(0,32);n[0]&=248,n[31]&=127,n[31]|=64;let s=o.slice(32,64),c=We(n),d=ae.mul(c),p=d.toRawBytes();return{head:n,prefix:s,scalar:c,point:d,pointBytes:p}},Ye=o=>qe(ke(o,32)).then(Ft),On=o=>Ft(Dt(ke(o,32))),Lt=o=>Ye(o).then(n=>n.pointBytes);function Rn(o,n){return o?qe(n.hashable).then(n.finish):n.finish(Dt(n.hashable))}var Dn=(o,n,s)=>{let{pointBytes:c,scalar:d}=o,p=We(n),a=ae.mul(p).toRawBytes();return{hashable:Ce(a,c,s),finish:I=>{let f=b(p+We(I)*d,de);return _e(Ce(a,Nt(f)),64)}}},Vt=async(o,n)=>{let s=ke(o),c=await Ye(n),d=await qe(c.prefix,s);return Rn(!0,Dn(c,d,s))};var Pt=()=>typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0,Ge={bytesToHex:je,hexToBytes:ze,concatBytes:Ce,mod:b,invert:Rt,randomBytes:o=>{let n=Pt();return n||j("crypto.getRandomValues must be defined"),n.getRandomValues(pe(o))},sha512Async:async(...o)=>{let n=Pt();n||j("crypto.subtle or etc.sha512Async must be defined");let s=Ce(...o);return pe(await n.subtle.digest("SHA-512",s.buffer))},sha512Sync:void 0};Object.defineProperties(Ge,{sha512Sync:{configurable:!1,get(){return we},set(o){we||(we=o)}}});var $t={getExtendedPublicKeyAsync:Ye,getExtendedPublicKey:On,randomPrivateKey:()=>Ge.randomBytes(32),precompute(o=8,n=ae){return n.multiply(3n),n}},se=8,Fn=()=>{let o=[],n=256/se+1,s=ae,c=s;for(let d=0;d<n;d++){c=s,o.push(c);for(let p=1;p<2**(se-1);p++)c=c.add(s),o.push(c);s=c.double()}return o},Ln=o=>{let n=kt||(kt=Fn()),s=(f,A)=>{let _=A.negate();return f?_:A},c=Se,d=ae,p=1+256/se,a=2**(se-1),g=BigInt(2**se-1),w=2**se,I=BigInt(se);for(let f=0;f<p;f++){let A=f*a,_=Number(o&g);o>>=I,_>a&&(_-=w,o+=1n);let h=A,m=A+Math.abs(_)-1,B=f%2!==0,x=_<0;_===0?d=d.add(s(B,n[h])):c=c.add(s(x,n[m]))}return{p:c,f:d}};var Z=class o{static generateKey(){let n,s;do n=$t.randomPrivateKey(),s=(0,be.encode)(n);while(s.length!==44);return new o(s)}constructor(n){this.secretKey=n;let s=(0,be.decode)(n);this.privateKey=O.from(s).toString("hex")}async sign(n){return await Vt(n,this.privateKey)}async getPublicKey(){let n=await Lt(this.privateKey);return`ed25519:${(0,be.encode)(n)}`}toString(){return this.privateKey}};var Ae=class{constructor(n="testnet"){this.networkId=n}get keyPrefix(){return`orderly_${this.networkId}_`}},ye=class extends Ae{getOrderlyKey(n){let s;if(n)s=this.getItem(n,"orderlyKey");else{let c=this.getAddress();if(!c)return null;s=this.getItem(c,"orderlyKey")}return s?new Z(s):null}getAccountId(n){return this.getItem(n,"accountId")}setAccountId(n,s){this.setItem(n,{accountId:s})}getAddress(){return localStorage.getItem(`${this.keyPrefix}address`)}setAddress(n){localStorage.setItem(`${this.keyPrefix}address`,n)}generateKey(){return Z.generateKey()}setKey(n,s){this.setItem(n,{orderlyKey:s.secretKey})}cleanAllKey(n){localStorage.removeItem(`${this.keyPrefix}${n}`),localStorage.removeItem(`${this.keyPrefix}address`)}cleanKey(n,s){let c=this.getItem(n);delete c[s],localStorage.setItem(`${this.keyPrefix}${n}`,JSON.stringify(c))}setItem(n,s){let c=`${this.keyPrefix}${n}`,d=localStorage.getItem(c);d?d=JSON.parse(d):d={},localStorage.setItem(c,JSON.stringify({...d,...s}))}getItem(n,s){let c=`${this.keyPrefix}${n}`,d=localStorage.getItem(c);return d?d=JSON.parse(d):d={},typeof s>"u"?d:d[s]}},he=class{constructor(n){this.secretKey=n}generateKey(){return new Z(this.secretKey)}getOrderlyKey(){return new Z(this.secretKey)}getAccountId(){return""}setAccountId(n){}getAddress(){return""}setAddress(n){}setKey(n,s){}cleanAllKey(){}cleanKey(n){}};E();T();v();var tt={};wt(tt,{base64url:()=>Xe,calculateStringHash:()=>Qe,formatByUnits:()=>et,parseAccountId:()=>Ze,parseBrokerHash:()=>Ue,parseTokenHash:()=>Je});E();T();v();var te=require("ethers"),Xe=function(o){return o.replace(/\+/g,"-").replace(/\//g,"_")};function Ue(o){return Qe(o)}function Ze(o,n){let s=te.AbiCoder.defaultAbiCoder();return(0,te.keccak256)(s.encode(["address","bytes32"],[o,Ue(n)]))}function Je(o){return Qe(o)}function Qe(o){return(0,te.solidityPackedKeccak256)(["string"],[o])}function et(o,n="ether"){return(0,te.formatUnits)(o,n)}Ve();var J=class{constructor(n){this.keyStore=n}async sign(n){let s=Date.now().toString(),c=[s,n.method.toUpperCase(),n.url].join("");n.data&&Object.keys(n.data).length&&(c+=JSON.stringify(n.data));let{signature:d,publicKey:p}=await this.signText(c);return{"orderly-key":p,"orderly-timestamp":s,"orderly-signature":d}}async signText(n){let s=this.keyStore.getOrderlyKey();if(!s)throw new Error("orderlyKeyPair is not defined");let c=O.from(n),d=await s.sign(c),p=O.from(d).toString("base64");return{signature:Xe(p),publicKey:await s.getPublicKey()}}};var rn=De(require("eventemitter3"));E();T();v();E();T();v();var Ie=class{constructor(){this._restore()}_restore(){this.map=new Map([["apiBaseUrl","https://testnet-api-evm.orderly.org"],["klineDataUrl","https://testnet-api-evm.orderly.org"],["publicWsUrl","wss://testnet-ws-evm.orderly.org"],["publicWebsocketKey","OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY"],["privateWsUrl","wss://testnet-ws-private-evm.orderly.org"],["operatorUrl","https://testnet-operator-evm.orderly.org"],["swapSupportApiUrl","https://fi-api.woo.org"],["brokerId","woofi_dex"],["env","dev-evm"]])}get(n){return this.map.get(n)}set(n,s){this.map.set(n,s)}clear(){}},nt=class extends Ie{constructor(s){super();this.configMap=s}_restore(){let s=Object.entries(this.configMap);this.map=new Map(s)}};E();T();v();var X={EIP712Domain:[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],Registration:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"timestamp",type:"uint64"},{name:"registrationNonce",type:"uint256"}],Withdraw:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"receiver",type:"address"},{name:"token",type:"string"},{name:"amount",type:"uint256"},{name:"withdrawNonce",type:"uint64"},{name:"timestamp",type:"uint64"}],AddOrderlyKey:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"orderlyKey",type:"string"},{name:"scope",type:"string"},{name:"timestamp",type:"uint64"},{name:"expiration",type:"uint64"}],SettlePnl:[{name:"brokerId",type:"string"},{name:"chainId",type:"uint256"},{name:"settleNonce",type:"uint64"},{name:"timestamp",type:"uint64"}]},Ht="0x6aAd876244E7A1Ad44Ec4824Ce813729E5B6C291",Wt="0xd64AeB281f3E8cd70e668b6cb24De7e532dC214D",jt="0x1826B75e2ef249173FC735149AE4B8e9ea10abff";var zt=o=>{let n=new he(o||"AFmQSju4FhDwG93cMdKogcnKx7SWmViDtDv5PVzfvRDF");return new J(n)},qt=()=>{if(typeof window>"u")throw new Error("the default signer only supports browsers.");let o=new ye("");return new J(o)};function $n(){return"0x8794E7260517B1766fc7b55cAfcd56e6bf08600e"}function Yt(o,n){return{name:"Orderly",version:"1",chainId:o,verifyingContract:n?$n():"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}function Gt(o){let{chainId:n,registrationNonce:s,brokerId:c}=o,d=Date.now(),p="Registration",a={brokerId:c,chainId:n,timestamp:d,registrationNonce:s},g={EIP712Domain:X.EIP712Domain,[p]:X[p]};return[a,{domain:Yt(n),message:a,primaryType:p,types:g}]}function Xt(o){let{publicKey:n,chainId:s,primaryType:c,brokerId:d,expiration:p=365}=o,a=Date.now(),g={brokerId:d,orderlyKey:n,scope:"read,trading",chainId:s,timestamp:a,expiration:a+1e3*60*60*24*p},w={EIP712Domain:X.EIP712Domain,[c]:X[c]},I={domain:Yt(s),message:g,primaryType:c,types:w};return[g,I]}function Zt(o){let{chainId:n,settlePnlNonce:s,domain:c,brokerId:d}=o,p="SettlePnl",a=new Date().getTime(),g={EIP712Domain:X.EIP712Domain,[p]:X[p]},w={brokerId:d,chainId:n,timestamp:a,settleNonce:s};return[w,{domain:c,message:w,primaryType:p,types:g}]}E();T();v();var rt=[{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 Jt=[{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(n){this.configStore=n}getContractInfoByEnv(){return{usdcAddress:Ht,usdcAbi:rt,vaultAddress:Wt,vaultAbi:Jt,verifyContractAddress:jt,erc20Abi:rt}}};E();T();v();E();T();v();var it=class{constructor(n=[],s={}){this.providers=n;this.services=s;this.injectProperties={}}register(...n){this.providers.push(...n),n.forEach(s=>{let c=s;c instanceof Function&&(c=new s),this.add(c)})}registerByName(n,s){let c=s;c instanceof Function&&(c=new s),this.addByName(n,c)}get(n){return this.services[n]}getAll(){return Object.assign({},this.services)}add(n){return this.addByName(n.constructor.name,n)}addByName(n,s){return this.services[n]=s,this.services[n.toLowerCase()]=s,this.injectIntoProperties(s,n),this.get(n)}inject(n,s,c){n&&c&&(n[s]=c)}injectIntoProperties(n,s=n.constructor.name){this.getInjectProperty(s.toLowerCase()).forEach(c=>{this.inject(c.target,c.propertyKey,n)})}getInjectProperty(n){return this.injectProperties[n]||(this.injectProperties[n]=[]),this.injectProperties[n]}},Qt=it;var st=class o{static getContainer(){return o.container||(o.container=new Qt),o.container}static register(...n){this.getContainer().register(...n)}static registerByName(n,s){this.getContainer().registerByName(n,s)}static get(n){return this.getContainer().get(n)}static getAll(){return this.getContainer().getAll()}constructor(){}},en=st;E();T();v();var W=require("@orderly.network/types");var tn=De(require("eventemitter3"));E();T();v();var at=require("ethers");var Me=class{constructor(n,s,c){this.configStore=n;this.contractManger=s;this.account=c}async withdraw(n){if(!this.account.walletClient)throw new Error("walletClient is undefined");if(!this.account.stateValue.address)throw new Error("account address is rqeuired");let{chainId:s,token:c,amount:d}=n,p="/v1/withdraw_request",a=await this.getWithdrawalNonce(),g=this.account.getDomain(!0),[w,I]=this._generateWithdrawMessage({chainId:s,receiver:this.account.stateValue.address,token:c,amount:this.account.walletClient.parseUnits(d.toString()),nonce:a,domain:g}),A={signature:await this.account.signTypedData(I),message:w,userAddress:this.account.stateValue.address,verifyingContract:g.verifyingContract},_={method:"POST",url:p,data:A},h=await this.account.signer.sign(_);return await this._simpleFetch(p,{method:"POST",body:JSON.stringify(A),headers:{"Content-Type":"application/json","orderly-account-id":this.account.stateValue.accountId,...h}})}_generateWithdrawMessage(n){let{chainId:s,receiver:c,token:d,amount:p,domain:a,nonce:g}=n,w="Withdraw",I=Date.now(),f={EIP712Domain:X.EIP712Domain,[w]:X[w]},A={brokerId:this.configStore.get("brokerId"),chainId:s,receiver:c,token:d,amount:p,timestamp:I,withdrawNonce:g};return[A,{domain:a,message:A,primaryType:w,types:f}]}async getWithdrawalNonce(){let n=Date.now().toString(),s="/v1/withdraw_nonce",c=[n,"GET",s].join(""),d=this.account.signer,{publicKey:p,signature:a}=await d.signText(c),g=await this._simpleFetch(s,{headers:{"orderly-account-id":this.account.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.withdraw_nonce;throw new Error(g.message)}async getNativeBalance(n){console.log("getNativeBalance",this.account.stateValue.address);let s=await this.account.walletClient?.getBalance(this.account.stateValue.address);return et(s,n?.decimals)}async getBalance(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),c=await this.account.walletClient?.call(n??s.usdcAddress,"balanceOf",[this.account.stateValue.address],{abi:s.usdcAbi});return console.log("-----*****-----",c),this.account.walletClient?.formatUnits(c)}async getBalanceByAddress(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),c=await this.account.walletClient?.call(n,"balanceOf",[this.account.stateValue.address],{abi:s.erc20Abi});return this.account.walletClient?.formatUnits(c)}async getAllowance(n){if(!this.account.walletClient)return"0";let s=this.contractManger.getContractInfoByEnv(),c=await this.account.walletClient?.call(n??s.usdcAddress,"allowance",[this.account.stateValue.address,s.vaultAddress],{abi:s.usdcAbi});return this.account.walletClient?.formatUnits(c)}async approve(n,s){if(!n)throw new Error("address is required");if(!this.account.walletClient)throw new Error("walletClient is undefined");let c=this.contractManger.getContractInfoByEnv(),d=typeof s<"u"&&s!==""?this.account.walletClient.parseUnits(s):at.ethers.MaxUint256.toString(),p=await this.account.walletClient?.call(n,"approve",[c.vaultAddress,d],{abi:c.usdcAbi});return console.log("-----*****-----",p),p}async approveByAddress(n){let{amount:s,address:c}=n;return this._approve(c,s)}async _approve(n,s){if(!this.account.walletClient)throw new Error("walletClient is undefined");let c=typeof s<"u"&&s!==""?this.account.walletClient.parseUnits(s):at.ethers.MaxUint256.toString(),d=this.contractManger.getContractInfoByEnv(),p=await this.account.walletClient?.call(n,"approve",[d.vaultAddress,c],{abi:d.erc20Abi});return console.log("-----*****-----",p),p}async deposit(n){console.log("deposit amount:",n);let s=this.configStore.get("brokerId");if(!s)throw new Error("brokerId is required");let c=this.contractManger.getContractInfoByEnv(),d={accountId:this.account.accountIdHashStr,brokerHash:Ue(s),tokenHash:Je("USDC"),tokenAmount:this.account.walletClient?.parseUnits(n)};return await this.account.walletClient?.call(c.vaultAddress,"deposit",[d],{abi:c.vaultAbi})}async _simpleFetch(n,s={}){let c=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(c,s).then(d=>d.json())}get usdcAddress(){return this.contractManger.getContractInfoByEnv().usdcAddress}};var Ee=class{constructor(n,s,c,d){this.configStore=n;this.keyStore=s;this.contractManger=c;this.getWalletAdapter=d;this._ee=new tn.default;this._state={status:W.AccountStatusEnum.NotConnected,balance:"",checking:!1,leverage:Number.NaN};this.assetsManager=new Me(n,c,this),this._bindEvents()}login(n){if(!n)throw new Error("address is required")}logout(){}async setAddress(n,s){if(!n)throw new Error("address is required");this.keyStore.setAddress(n);let c={...this.stateValue,status:W.AccountStatusEnum.Connected,address:n,connectWallet:s?.wallet};return this._ee.emit("change:status",c),s&&(this.walletClient=this.getWalletAdapter({...s,address:n})),await this._checkAccount(n)}get stateValue(){return this._state}get accountId(){return this.stateValue.accountId}get accountIdHashStr(){if(!this.address)throw new Error("address is error");if(!this.configStore.get("brokerId"))throw new Error("brokerId is undefined");return Ze(this.address,this.configStore.get("brokerId"))}get address(){return this.stateValue.address}get chainId(){return this.walletClient?.chainId}set position(n){let s={...this.stateValue,positon:n};this._ee.emit("change:status",s)}set orders(n){let s={...this.stateValue,orders:n};this._ee.emit("change:status",s)}_bindEvents(){this._ee.addListener("change:status",n=>{console.log("change:status",n),this._state=n})}async _checkAccount(n){let s;try{let c=await this._checkAccountExist(n);if(c&&c.account_id)console.log("account is exist"),this.keyStore.setAccountId(n,c.account_id),s={...this.stateValue,status:W.AccountStatusEnum.SignedIn,accountId:c.account_id,userId:c.user_id},this._ee.emit("change:status",s);else return s={...this.stateValue,status:W.AccountStatusEnum.NotSignedIn},this._ee.emit("change:status",s),W.AccountStatusEnum.NotSignedIn;let d=this.keyStore.getOrderlyKey();if(s={...this.stateValue,status:W.AccountStatusEnum.DisabledTrading},!d)return console.log("orderlyKey is null"),this._ee.emit("change:status",s),W.AccountStatusEnum.DisabledTrading;let p=await d.getPublicKey(),a=await this._checkOrderlyKeyState(c.account_id,p);if(a&&a.orderly_key&&a.key_status==="ACTIVE"){let g=Date.now(),w=a.expiration;if(g>w)return this.keyStore.cleanKey(n,"orderlyKey"),W.AccountStatusEnum.DisabledTrading;let I={...this.stateValue,status:W.AccountStatusEnum.EnableTrading};return this._ee.emit("change:status",I),W.AccountStatusEnum.EnableTrading}return this.keyStore.cleanKey(n,"orderlyKey"),W.AccountStatusEnum.NotConnected}catch(c){console.log("\u68C0\u67E5\u8D26\u6237\u72B6\u6001\u9519\u8BEF:",c)}return W.AccountStatusEnum.NotSignedIn}async _checkAccountExist(n){let s=await this._simpleFetch(`/v1/get_account?address=${n}&broker_id=woofi_dex`);return s.success?s.data:null}async createAccount(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getRegisterationNonce(),s=this.stateValue.address;if(!s)throw new Error("address is undefined");let[c,d]=Gt({registrationNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId")}),p=await this.signTypedData(d),a=await this._simpleFetch("/v1/register_account",{method:"POST",body:JSON.stringify({signature:p,message:c,userAddress:s}),headers:{"Content-Type":"application/json"}});if(a.success){this.keyStore.setAccountId(s,a.data.account_id);let g={...this.stateValue,status:W.AccountStatusEnum.DisabledTrading,accountId:a.data.account_id,userId:a.data.user_id};return this._ee.emit("change:status",g),a}}async signTypedData(n){return this.walletClient?await this.walletClient.signTypedData(this.stateValue.address,JSON.stringify(n)):Promise.reject("walletClient is undefined")}async createOrderlyKey(n){if(this.stateValue.accountId===void 0)throw new Error("account id is undefined");if(!this.walletClient)throw new Error("walletClient is undefined");let s="AddOrderlyKey",c=this.keyStore.generateKey(),d=await c.getPublicKey(),[p,a]=Xt({publicKey:d,chainId:this.walletClient.chainId,primaryType:s,expiration:n,brokerId:this.configStore.get("brokerId")}),g=this.stateValue.address;if(!g)throw new Error("address is undefined");let w=await this.signTypedData(a),I=await this._simpleFetch("/v1/orderly_key",{method:"POST",body:JSON.stringify({signature:w,message:p,userAddress:g}),headers:{"X-Account-Id":this.stateValue.accountId,"Content-Type":"application/json"}});if(I.success){this.keyStore.setKey(g,c);let f={...this.stateValue,status:W.AccountStatusEnum.EnableTrading};return this._ee.emit("change:status",f),I}else throw new Error(I.message)}async settle(){if(!this.walletClient)return Promise.reject("walletClient is undefined");let n=await this._getSettleNonce(),s=this.stateValue.address,c=this.getDomain(!0),d="/v1/settle_pnl",[p,a]=Zt({settlePnlNonce:n,chainId:this.walletClient.chainId,brokerId:this.configStore.get("brokerId"),domain:c}),w={signature:await this.signTypedData(a),message:p,userAddress:s,verifyingContract:c.verifyingContract},I={method:"POST",url:d,data:w},f=await this.signer.sign(I),A=await this._simpleFetch(d,{method:"POST",body:JSON.stringify(w),headers:{"Content-Type":"application/json","orderly-account-id":this.stateValue.accountId,...f}});if(A.success)return A;throw new Error(A.message)}async disconnect(){let n={...this.stateValue,status:W.AccountStatusEnum.NotConnected,accountId:void 0,userId:void 0,address:void 0};this._ee.emit("change:status",n)}async _checkOrderlyKeyState(n,s){let c=await this._simpleFetch(`/v1/get_orderly_key?account_id=${n}&orderly_key=${s}`);if(c.success)return c.data;throw new Error(c.message)}get signer(){return this._singer||(this._singer=new J(this.keyStore)),this._singer}get wallet(){return this.walletClient}async _getRegisterationNonce(){let n=await this._simpleFetch("/v1/registration_nonce",{headers:{"orderly-account-id":this.stateValue.accountId}});if(n.success)return n.data?.registration_nonce;throw new Error(n.message)}async _getSettleNonce(){let n=Date.now().toString(),c=[n,"GET","/v1/settle_nonce"].join(""),d=this.signer,{publicKey:p,signature:a}=await d.signText(c),g=await this._simpleFetch("/v1/settle_nonce",{headers:{"orderly-account-id":this.stateValue.accountId,"orderly-key":p,"orderly-timestamp":n,"orderly-signature":a}});if(g.success)return g.data?.settle_nonce;throw new Error(g.message)}async _simpleFetch(n,s={}){let c=`${this.configStore.get("apiBaseUrl")}${n}`;return fetch(c,s).then(d=>d.json())}getDomain(n){if(!this.walletClient)throw new Error("walletClient is undefined");return{name:"Orderly",version:"1",chainId:this.walletClient.chainId,verifyingContract:n?this.contractManger.getContractInfoByEnv().verifyContractAddress:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"}}get on(){return this._ee.on.bind(this._ee)}get once(){return this._ee.once.bind(this._ee)}get off(){return this._ee.off.bind(this._ee)}};Ee.instanceName="account";E();T();v();E();T();v();var oe=require("ethers"),nn=require("@enzoferey/ethers-error-parser"),Ke=class{constructor(n){console.log("EtherAdapter constructor",n),this._chainId=parseInt(n.chain.id,16),this.provider=new oe.BrowserProvider(n.provider,"any"),this._address=n.address}parseUnits(n){return oe.ethers.parseUnits(n,6).toString()}formatUnits(n){return oe.ethers.formatUnits(n,6)}getBalance(n){return console.log("*********",n),this.provider.getBalance(n).then(s=>(console.log("getBalance",s),s),s=>{console.log("get native token balance error",s)})}deposit(n,s,c){throw new Error("Method not implemented.")}async call(n,s,c,d){let p=await this.provider?.getSigner();return new oe.ethers.Contract(n,d.abi,p)[s].apply(null,c).catch(g=>{throw(0,nn.getParsedEthersError)(g)})}get chainId(){return this._chainId}get addresses(){return this._address}async send(n,s){return await this.provider?.send(n,s)}async signTypedData(n,s){return await this.provider?.send("eth_signTypedData_v4",[n,s])}async verify(n,s){let{domain:c,types:d,message:p}=n,a=oe.ethers.verifyTypedData(c,d,p,s);console.log("recovered",a)}on(n,s){this.provider?.on(n,s)}off(n,s){this.provider?.off(n,s)}};0&&(module.exports={Account,BaseConfigStore,BaseContractManager,BaseKeyStore,BaseOrderlyKeyPair,BaseSigner,EtherAdapter,EventEmitter,LocalStorageStore,MemoryConfigStore,MockKeyStore,SimpleDI,getDefaultSigner,getMockSigner,utils});
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
@jspm/core/nodelibs/browser/buffer.js:
|