@orderly.network/core 0.1.28 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import EventEmitter from 'eventemitter3';
2
2
  export { default as EventEmitter } from 'eventemitter3';
3
+ import { definedTypes, API, AccountStatusEnum } from '@orderly.network/types';
3
4
  import { parseUnits, TransactionResponse, ethers } from 'ethers';
4
- import { AccountStatusEnum } from '@orderly.network/types';
5
5
 
6
6
  interface OrderlyKeyPair {
7
7
  getPublicKey(): Promise<string>;
@@ -70,12 +70,12 @@ declare class MockKeyStore implements OrderlyKeyStore {
70
70
  cleanKey(key: string): void;
71
71
  }
72
72
 
73
- declare type MessageFactor = {
73
+ type MessageFactor = {
74
74
  url: string;
75
75
  method: "GET" | "POST" | "PUT" | "DELETE";
76
76
  data?: any;
77
77
  };
78
- declare type SignedMessagePayload = {
78
+ type SignedMessagePayload = {
79
79
  "orderly-key": string;
80
80
  "orderly-timestamp": string;
81
81
  "orderly-signature": string;
@@ -113,7 +113,7 @@ declare class BaseSigner implements Signer {
113
113
  }>;
114
114
  }
115
115
 
116
- declare type ConfigKey = "apiBaseUrl" | "klineDataUrl" | "privateWsUrl" | "publicWsUrl" | "operatorUrl" | "swapSupportApiUrl" | "domain" | "brokerId" | "networkId" | "env" | "PROD_URL";
116
+ type ConfigKey = "apiBaseUrl" | "klineDataUrl" | "privateWsUrl" | "publicWsUrl" | "operatorUrl" | "swapSupportApiUrl" | "domain" | "brokerId" | "networkId" | "env" | "PROD_URL" | "markets";
117
117
  interface ConfigStore {
118
118
  get<T>(key: ConfigKey): T;
119
119
  getOr<T>(key: ConfigKey, defaultValue: T): T;
@@ -137,7 +137,7 @@ declare class BaseConfigStore extends MemoryConfigStore {
137
137
  constructor(configMap: Record<string, any>);
138
138
  }
139
139
 
140
- declare type SignatureDomain = {
140
+ type SignatureDomain = {
141
141
  name: string;
142
142
  version: string;
143
143
  chainId: number;
@@ -149,11 +149,15 @@ declare function parseAccountId(userAddress: string, brokerId: string): string;
149
149
  declare function parseTokenHash(tokenSymbol: string): string;
150
150
  declare function calculateStringHash(input: string): string;
151
151
  declare function formatByUnits(amount: string, unit?: number | "ether" | "gwei"): string;
152
+ declare function isHex(value: string): boolean;
153
+ declare function isHexString(value: string): boolean;
152
154
 
153
155
  type utils_SignatureDomain = SignatureDomain;
154
156
  declare const utils_base64url: typeof base64url;
155
157
  declare const utils_calculateStringHash: typeof calculateStringHash;
156
158
  declare const utils_formatByUnits: typeof formatByUnits;
159
+ declare const utils_isHex: typeof isHex;
160
+ declare const utils_isHexString: typeof isHexString;
157
161
  declare const utils_parseAccountId: typeof parseAccountId;
158
162
  declare const utils_parseBrokerHash: typeof parseBrokerHash;
159
163
  declare const utils_parseTokenHash: typeof parseTokenHash;
@@ -164,6 +168,8 @@ declare namespace utils {
164
168
  utils_base64url as base64url,
165
169
  utils_calculateStringHash as calculateStringHash,
166
170
  utils_formatByUnits as formatByUnits,
171
+ utils_isHex as isHex,
172
+ utils_isHexString as isHexString,
167
173
  utils_parseAccountId as parseAccountId,
168
174
  utils_parseBrokerHash as parseBrokerHash,
169
175
  utils_parseTokenHash as parseTokenHash,
@@ -171,14 +177,244 @@ declare namespace utils {
171
177
  };
172
178
  }
173
179
 
174
- declare const getMockSigner: (secretKey?: string | undefined) => BaseSigner;
180
+ declare const getMockSigner: (secretKey?: string) => BaseSigner;
175
181
  declare const getDefaultSigner: () => BaseSigner;
182
+ /**
183
+ * generate `registerAccount` data and to be signed message structure
184
+ */
185
+ declare function generateRegisterAccountMessage(inputs: {
186
+ chainId: number;
187
+ registrationNonce: number;
188
+ brokerId: string;
189
+ }): readonly [{
190
+ brokerId: string;
191
+ chainId: number;
192
+ timestamp: number;
193
+ registrationNonce: number;
194
+ }, {
195
+ domain: {
196
+ name: string;
197
+ version: string;
198
+ chainId: number;
199
+ verifyingContract: string;
200
+ };
201
+ message: {
202
+ brokerId: string;
203
+ chainId: number;
204
+ timestamp: number;
205
+ registrationNonce: number;
206
+ };
207
+ primaryType: string;
208
+ types: {
209
+ EIP712Domain: readonly [{
210
+ readonly name: "name";
211
+ readonly type: "string";
212
+ }, {
213
+ readonly name: "version";
214
+ readonly type: "string";
215
+ }, {
216
+ readonly name: "chainId";
217
+ readonly type: "uint256";
218
+ }, {
219
+ readonly name: "verifyingContract";
220
+ readonly type: "address";
221
+ }];
222
+ Registration: readonly [{
223
+ readonly name: "brokerId";
224
+ readonly type: "string";
225
+ }, {
226
+ readonly name: "chainId";
227
+ readonly type: "uint256";
228
+ }, {
229
+ readonly name: "timestamp";
230
+ readonly type: "uint64";
231
+ }, {
232
+ readonly name: "registrationNonce";
233
+ readonly type: "uint256";
234
+ }];
235
+ };
236
+ }];
237
+ /**
238
+ * generate `addOrderlyKey` data and to be signed message structure
239
+ */
240
+ declare function generateAddOrderlyKeyMessage(inputs: {
241
+ publicKey: string;
242
+ chainId: number;
243
+ brokerId: string;
244
+ primaryType: keyof typeof definedTypes;
245
+ expiration?: number;
246
+ }): readonly [{
247
+ brokerId: string;
248
+ orderlyKey: string;
249
+ scope: string;
250
+ chainId: number;
251
+ timestamp: number;
252
+ expiration: number;
253
+ }, {
254
+ domain: {
255
+ name: string;
256
+ version: string;
257
+ chainId: number;
258
+ verifyingContract: string;
259
+ };
260
+ message: {
261
+ brokerId: string;
262
+ orderlyKey: string;
263
+ scope: string;
264
+ chainId: number;
265
+ timestamp: number;
266
+ expiration: number;
267
+ };
268
+ primaryType: "Registration" | "EIP712Domain" | "Withdraw" | "AddOrderlyKey" | "SettlePnl";
269
+ types: {
270
+ [x: string]: readonly [{
271
+ readonly name: "name";
272
+ readonly type: "string";
273
+ }, {
274
+ readonly name: "version";
275
+ readonly type: "string";
276
+ }, {
277
+ readonly name: "chainId";
278
+ readonly type: "uint256";
279
+ }, {
280
+ readonly name: "verifyingContract";
281
+ readonly type: "address";
282
+ }] | readonly [{
283
+ readonly name: "brokerId";
284
+ readonly type: "string";
285
+ }, {
286
+ readonly name: "chainId";
287
+ readonly type: "uint256";
288
+ }, {
289
+ readonly name: "timestamp";
290
+ readonly type: "uint64";
291
+ }, {
292
+ readonly name: "registrationNonce";
293
+ readonly type: "uint256";
294
+ }] | readonly [{
295
+ readonly name: "brokerId";
296
+ readonly type: "string";
297
+ }, {
298
+ readonly name: "chainId";
299
+ readonly type: "uint256";
300
+ }, {
301
+ readonly name: "receiver";
302
+ readonly type: "address";
303
+ }, {
304
+ readonly name: "token";
305
+ readonly type: "string";
306
+ }, {
307
+ readonly name: "amount";
308
+ readonly type: "uint256";
309
+ }, {
310
+ readonly name: "withdrawNonce";
311
+ readonly type: "uint64";
312
+ }, {
313
+ readonly name: "timestamp";
314
+ readonly type: "uint64";
315
+ }] | readonly [{
316
+ readonly name: "brokerId";
317
+ readonly type: "string";
318
+ }, {
319
+ readonly name: "chainId";
320
+ readonly type: "uint256";
321
+ }, {
322
+ readonly name: "orderlyKey";
323
+ readonly type: "string";
324
+ }, {
325
+ readonly name: "scope";
326
+ readonly type: "string";
327
+ }, {
328
+ readonly name: "timestamp";
329
+ readonly type: "uint64";
330
+ }, {
331
+ readonly name: "expiration";
332
+ readonly type: "uint64";
333
+ }] | readonly [{
334
+ readonly name: "brokerId";
335
+ readonly type: "string";
336
+ }, {
337
+ readonly name: "chainId";
338
+ readonly type: "uint256";
339
+ }, {
340
+ readonly name: "settleNonce";
341
+ readonly type: "uint64";
342
+ }, {
343
+ readonly name: "timestamp";
344
+ readonly type: "uint64";
345
+ }];
346
+ EIP712Domain: readonly [{
347
+ readonly name: "name";
348
+ readonly type: "string";
349
+ }, {
350
+ readonly name: "version";
351
+ readonly type: "string";
352
+ }, {
353
+ readonly name: "chainId";
354
+ readonly type: "uint256";
355
+ }, {
356
+ readonly name: "verifyingContract";
357
+ readonly type: "address";
358
+ }];
359
+ };
360
+ }];
361
+ /**
362
+ * generate `settle` data and to be signed message structure
363
+ */
364
+ declare function generateSettleMessage(inputs: {
365
+ chainId: number;
366
+ brokerId: string;
367
+ settlePnlNonce: string;
368
+ domain: SignatureDomain;
369
+ }): readonly [{
370
+ brokerId: string;
371
+ chainId: number;
372
+ timestamp: number;
373
+ settleNonce: string;
374
+ }, {
375
+ domain: SignatureDomain;
376
+ message: {
377
+ brokerId: string;
378
+ chainId: number;
379
+ timestamp: number;
380
+ settleNonce: string;
381
+ };
382
+ primaryType: string;
383
+ types: {
384
+ EIP712Domain: readonly [{
385
+ readonly name: "name";
386
+ readonly type: "string";
387
+ }, {
388
+ readonly name: "version";
389
+ readonly type: "string";
390
+ }, {
391
+ readonly name: "chainId";
392
+ readonly type: "uint256";
393
+ }, {
394
+ readonly name: "verifyingContract";
395
+ readonly type: "address";
396
+ }];
397
+ SettlePnl: readonly [{
398
+ readonly name: "brokerId";
399
+ readonly type: "string";
400
+ }, {
401
+ readonly name: "chainId";
402
+ readonly type: "uint256";
403
+ }, {
404
+ readonly name: "settleNonce";
405
+ readonly type: "uint64";
406
+ }, {
407
+ readonly name: "timestamp";
408
+ readonly type: "uint64";
409
+ }];
410
+ };
411
+ }];
176
412
 
177
413
  /**
178
414
  * Orderly contracts information
179
415
  * https://wootraders.atlassian.net/wiki/spaces/ORDER/pages/343441906/Orderly+V2+Contract+Information+Board
180
416
  */
181
- declare type OrderlyContracts = {
417
+ type OrderlyContracts = {
182
418
  usdcAddress: string;
183
419
  usdcAbi: any;
184
420
  erc20Abi: any;
@@ -265,21 +501,6 @@ declare class BaseContract implements IContract {
265
501
  type: string;
266
502
  stateMutability?: undefined;
267
503
  outputs?: undefined;
268
- } | {
269
- inputs: {
270
- internalType: string;
271
- name: string;
272
- type: string;
273
- }[];
274
- name: string;
275
- outputs: {
276
- internalType: string;
277
- name: string;
278
- type: string;
279
- }[];
280
- stateMutability: string;
281
- type: string;
282
- anonymous?: undefined;
283
504
  } | {
284
505
  inputs: ({
285
506
  internalType: string;
@@ -297,7 +518,11 @@ declare class BaseContract implements IContract {
297
518
  type: string;
298
519
  })[];
299
520
  name: string;
300
- outputs: never[];
521
+ outputs: {
522
+ internalType: string;
523
+ name: string;
524
+ type: string;
525
+ }[];
301
526
  stateMutability: string;
302
527
  type: string;
303
528
  anonymous?: undefined;
@@ -377,17 +602,20 @@ interface IWalletAdapter {
377
602
  call(address: string, method: string, params: any, options: {
378
603
  abi: any;
379
604
  }): Promise<any>;
605
+ callOnChain(chain: API.NetworkInfos, address: string, method: string, params: any, options: {
606
+ abi: any;
607
+ }): Promise<any>;
380
608
  on(eventName: any, listener: any): void;
381
609
  off(eventName: any, listener: any): void;
382
610
  }
383
- declare type WalletAdapterOptions = {
611
+ type WalletAdapterOptions = {
384
612
  provider: any;
385
613
  address: string;
386
614
  chain: {
387
- id: string;
615
+ id: number;
388
616
  };
389
617
  };
390
- declare type getWalletAdapterFunc = (options: WalletAdapterOptions) => IWalletAdapter;
618
+ type getWalletAdapterFunc = (options: WalletAdapterOptions) => IWalletAdapter;
391
619
 
392
620
  declare class Assets {
393
621
  private readonly configStore;
@@ -397,7 +625,7 @@ declare class Assets {
397
625
  withdraw(inputs: {
398
626
  chainId: number;
399
627
  token: string;
400
- amount: number;
628
+ amount: string | number;
401
629
  allowCrossChainWithdraw: boolean;
402
630
  }): Promise<any>;
403
631
  private _generateWithdrawMessage;
@@ -416,7 +644,14 @@ declare class Assets {
416
644
  address: string;
417
645
  }): Promise<any>;
418
646
  private _approve;
419
- deposit(amount: string): Promise<ethers.TransactionResponse>;
647
+ getDepositData(amount: string): {
648
+ accountId: string | undefined;
649
+ brokerHash: string;
650
+ tokenHash: string;
651
+ tokenAmount: string;
652
+ };
653
+ getDepositFee(amount: string, chain: API.NetworkInfos): Promise<any>;
654
+ deposit(amount: string, fee?: bigint): Promise<ethers.TransactionResponse>;
420
655
  private _simpleFetch;
421
656
  get usdcAddress(): string;
422
657
  }
@@ -443,7 +678,7 @@ interface AccountState {
443
678
  */
444
679
  declare class Account {
445
680
  private readonly configStore;
446
- private readonly keyStore;
681
+ readonly keyStore: OrderlyKeyStore;
447
682
  private readonly getWalletAdapter;
448
683
  static instanceName: string;
449
684
  private _singer?;
@@ -464,7 +699,7 @@ declare class Account {
464
699
  setAddress(address: string, wallet?: {
465
700
  provider: any;
466
701
  chain: {
467
- id: string;
702
+ id: string | number;
468
703
  };
469
704
  wallet?: {
470
705
  name: string;
@@ -486,7 +721,7 @@ declare class Account {
486
721
  private _checkAccountExist;
487
722
  createAccount(): Promise<any>;
488
723
  signTypedData(toSignatureMessage: Record<string, any>): Promise<string>;
489
- createOrderlyKey(expiration: number): Promise<any>;
724
+ createOrderlyKey(expiration?: number): Promise<any>;
490
725
  settle(): Promise<any>;
491
726
  disconnect(): Promise<void>;
492
727
  private _checkOrderlyKeyState;
@@ -522,6 +757,9 @@ declare class EtherAdapter implements IWalletAdapter {
522
757
  call(address: string, method: string, params: any[], options: {
523
758
  abi: any;
524
759
  }): Promise<any>;
760
+ callOnChain(chain: API.NetworkInfos, address: string, method: string, params: any[], options: {
761
+ abi: any;
762
+ }): Promise<any>;
525
763
  get chainId(): number;
526
764
  get addresses(): string;
527
765
  send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
@@ -545,4 +783,4 @@ declare class EtherAdapter implements IWalletAdapter {
545
783
  getContract(address: string, abi: any): ethers.Contract;
546
784
  }
547
785
 
548
- export { Account, AccountState, BaseConfigStore, BaseContract as BaseContractManager, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigKey, ConfigStore, DefaultConfigStore, EtherAdapter, IContract, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, IWalletAdapter as WalletAdapter, WalletAdapterOptions, getDefaultSigner, getMockSigner, getWalletAdapterFunc, utils };
786
+ export { Account, AccountState, BaseConfigStore, BaseContract as BaseContractManager, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigKey, ConfigStore, DefaultConfigStore, EtherAdapter, IContract, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, IWalletAdapter as WalletAdapter, WalletAdapterOptions, generateAddOrderlyKeyMessage, generateRegisterAccountMessage, generateSettleMessage, getDefaultSigner, getMockSigner, getWalletAdapterFunc, utils };