@orderly.network/core 0.0.38 → 0.0.39

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.
@@ -0,0 +1,276 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ export { default as EventEmitter } from 'eventemitter3';
3
+ import { AccountStatusEnum } from '@orderly.network/types';
4
+
5
+ interface OrderlyKeyPair {
6
+ getPublicKey(): Promise<string>;
7
+ secretKey: string;
8
+ sign: (data: Uint8Array) => Promise<Uint8Array>;
9
+ }
10
+ declare class BaseOrderlyKeyPair implements OrderlyKeyPair {
11
+ secretKey: string;
12
+ private privateKey;
13
+ static generateKey(): OrderlyKeyPair;
14
+ constructor(secretKey: string);
15
+ sign(message: Uint8Array): Promise<Uint8Array>;
16
+ getPublicKey(): Promise<string>;
17
+ toString(): string;
18
+ }
19
+
20
+ interface OrderlyKeyStore {
21
+ getOrderlyKey: (address?: string) => OrderlyKeyPair | null;
22
+ getAccountId: (address: string) => string | undefined | null;
23
+ setAccountId: (address: string, accountId: string) => void;
24
+ getAddress: () => string | undefined | null;
25
+ setAddress: (address: string) => void;
26
+ generateKey: () => OrderlyKeyPair;
27
+ cleanKey: (address: string, key: string) => void;
28
+ cleanAllKey: (address: string) => void;
29
+ setKey: (orderlyKey: string, secretKey: OrderlyKeyPair) => void;
30
+ }
31
+ declare abstract class BaseKeyStore implements OrderlyKeyStore {
32
+ private readonly networkId;
33
+ constructor(networkId?: string);
34
+ abstract getOrderlyKey(address?: string): OrderlyKeyPair | null;
35
+ abstract getAccountId(address: string): string | undefined | null;
36
+ abstract setAccountId(address: string, accountId: string): void;
37
+ abstract getAddress(): string | undefined | null;
38
+ abstract setAddress(address: string): void;
39
+ abstract generateKey(): OrderlyKeyPair;
40
+ abstract setKey(orderlyKey: string, secretKey: OrderlyKeyPair): void;
41
+ abstract cleanAllKey(address: string): void;
42
+ abstract cleanKey(address: string, key: string): void;
43
+ protected get keyPrefix(): string;
44
+ }
45
+ declare class LocalStorageStore extends BaseKeyStore {
46
+ getOrderlyKey(address?: string): OrderlyKeyPair | null;
47
+ getAccountId(address: string): string | undefined | null;
48
+ setAccountId(address: string, accountId: string): void;
49
+ getAddress(): string | undefined | null;
50
+ setAddress(address: string): void;
51
+ generateKey(): OrderlyKeyPair;
52
+ setKey(address: string, orderlyKey: OrderlyKeyPair): void;
53
+ cleanAllKey(address: string): void;
54
+ cleanKey(address: string, key: string): void;
55
+ private setItem;
56
+ private getItem;
57
+ }
58
+ declare class MockKeyStore implements OrderlyKeyStore {
59
+ private readonly secretKey;
60
+ constructor(secretKey: string);
61
+ generateKey(): BaseOrderlyKeyPair;
62
+ getOrderlyKey(): BaseOrderlyKeyPair;
63
+ getAccountId(): string;
64
+ setAccountId(accountId: string): void;
65
+ getAddress(): string;
66
+ setAddress(address: string): void;
67
+ setKey(orderlyKey: string, secretKey: OrderlyKeyPair): void;
68
+ cleanAllKey(): void;
69
+ cleanKey(key: string): void;
70
+ }
71
+
72
+ type MessageFactor = {
73
+ url: string;
74
+ method: "GET" | "POST" | "PUT" | "DELETE";
75
+ data?: any;
76
+ };
77
+ type SignedMessagePayload = {
78
+ "orderly-key": string;
79
+ "orderly-timestamp": string;
80
+ "orderly-signature": string;
81
+ "orderly-account-id"?: string;
82
+ };
83
+ /**
84
+ * 签名
85
+ * @example
86
+ * ```ts
87
+ * const signer = new BaseSigner(keyStore);
88
+ * const payload = await signer.sign({
89
+ * url: "https://api.orderly.io/get_account?address=0x1234567890&brokerId=woofi_dex",
90
+ * method: "GET",
91
+ * data: {
92
+ * address: "0x1234567890",
93
+ * brokerId: "woofi_dex",
94
+ * },
95
+ * });
96
+ * ```
97
+ */
98
+ interface Signer {
99
+ sign: (data: MessageFactor) => Promise<SignedMessagePayload>;
100
+ signText: (text: string) => Promise<{
101
+ signature: string;
102
+ publicKey: string;
103
+ }>;
104
+ }
105
+ declare class BaseSigner implements Signer {
106
+ private readonly keyStore;
107
+ constructor(keyStore: OrderlyKeyStore);
108
+ sign(message: MessageFactor): Promise<SignedMessagePayload>;
109
+ signText(text: string): Promise<{
110
+ signature: string;
111
+ publicKey: string;
112
+ }>;
113
+ }
114
+
115
+ type ConfigKey = "apiBaseUrl" | "klineDataUrl";
116
+ interface ConfigStore {
117
+ get<T>(key: string): T;
118
+ set<T>(key: string, value: T): void;
119
+ clear(): void;
120
+ }
121
+ declare class MemoryConfigStore implements ConfigStore {
122
+ protected map: Map<string, any>;
123
+ constructor();
124
+ protected _restore(): void;
125
+ get<T>(key: string): T;
126
+ set<T>(key: string, value: T): void;
127
+ clear(): void;
128
+ }
129
+ /**
130
+ *
131
+ */
132
+ declare class BaseConfigStore extends MemoryConfigStore {
133
+ private readonly configMap;
134
+ constructor(configMap: Record<string, any>);
135
+ protected _restore(): void;
136
+ }
137
+
138
+ declare const getMockSigner: (secretKey?: string) => BaseSigner;
139
+ declare const getDefaultSigner: () => BaseSigner;
140
+
141
+ interface IContract {
142
+ getContractInfoByEnv(): any;
143
+ }
144
+ declare class BaseContract implements IContract {
145
+ private readonly configStore;
146
+ constructor(configStore: ConfigStore);
147
+ getContractInfoByEnv(): {
148
+ usdcAddress: string;
149
+ vaultAddress: string;
150
+ verifyContractAddress: string;
151
+ };
152
+ }
153
+
154
+ declare class SimpleDI {
155
+ private static container;
156
+ private static getContainer;
157
+ static register(...serviceClasses: any[]): void;
158
+ static registerByName(name: string, serviceClass: any): void;
159
+ static get<T = any>(name: string): T;
160
+ static getAll(): {
161
+ [name: string]: any;
162
+ };
163
+ private constructor();
164
+ }
165
+
166
+ interface WalletAdapter {
167
+ get chainId(): number;
168
+ get addresses(): string;
169
+ getBalance: (address: string) => Promise<any>;
170
+ deposit: (from: string, to: string, amount: string) => Promise<any>;
171
+ send: (method: string, params: Array<any> | Record<string, any>) => Promise<any>;
172
+ signTypedData: (address: string, data: any) => Promise<string>;
173
+ }
174
+ type WalletAdapterOptions = {
175
+ provider: any;
176
+ address: string;
177
+ label?: string;
178
+ chain: {
179
+ id: string;
180
+ };
181
+ };
182
+ type getWalletAdapterFunc = (options: WalletAdapterOptions) => WalletAdapter;
183
+
184
+ interface AccountState {
185
+ status: AccountStatusEnum;
186
+ checking: boolean;
187
+ accountId?: string;
188
+ userId?: string;
189
+ address?: string;
190
+ balance: string;
191
+ leverage: number;
192
+ positon?: string[];
193
+ orders?: string[];
194
+ }
195
+ /**
196
+ * 账户
197
+ * @example
198
+ * ```ts
199
+ * const account = new Account();
200
+ * account.login("0x1234567890");
201
+ * ```
202
+ */
203
+ declare class Account {
204
+ private readonly configStore;
205
+ private readonly keyStore;
206
+ private readonly contractManger;
207
+ private readonly getWalletAdapter;
208
+ static instanceName: string;
209
+ private _singer?;
210
+ private _ee;
211
+ private _state;
212
+ private walletClient?;
213
+ constructor(configStore: ConfigStore, keyStore: OrderlyKeyStore, contractManger: IContract, getWalletAdapter: getWalletAdapterFunc);
214
+ /**
215
+ * 登录
216
+ * @param address 钱包地址
217
+ */
218
+ login(address: string): void;
219
+ logout(): void;
220
+ /**
221
+ * 连接钱包先用第三方的React版本,不用自己实现
222
+ */
223
+ setAddress(address: string, wallet?: {
224
+ provider: any;
225
+ chain: {
226
+ id: string;
227
+ };
228
+ [key: string]: any;
229
+ }): Promise<AccountStatusEnum>;
230
+ get stateValue(): AccountState;
231
+ get accountId(): string | undefined;
232
+ get address(): string | undefined;
233
+ get chainId(): string | undefined;
234
+ /**
235
+ * set user positions count
236
+ */
237
+ set position(position: string[]);
238
+ set orders(orders: string[]);
239
+ private _bindEvents;
240
+ private _checkAccount;
241
+ private _checkAccountExist;
242
+ createAccount(): Promise<any>;
243
+ createOrderlyKey(expiration: number): Promise<any>;
244
+ settlement(): Promise<any>;
245
+ disconnect(): Promise<void>;
246
+ private _checkOrderlyKeyState;
247
+ get signer(): Signer;
248
+ get wallet(): any;
249
+ private _getRegisterationNonce;
250
+ private _getSettleNonce;
251
+ private _simpleFetch;
252
+ private getDomain;
253
+ get on(): <T extends string | symbol>(event: T, fn: (...args: any[]) => void, context?: any) => EventEmitter<string | symbol, any>;
254
+ get once(): <T extends string | symbol>(event: T, fn: (...args: any[]) => void, context?: any) => EventEmitter<string | symbol, any>;
255
+ get off(): <T extends string | symbol>(event: T, fn?: ((...args: any[]) => void) | undefined, context?: any, once?: boolean | undefined) => EventEmitter<string | symbol, any>;
256
+ }
257
+
258
+ declare class EtherAdapter implements WalletAdapter {
259
+ private provider?;
260
+ private _chainId;
261
+ private _address;
262
+ constructor(options: WalletAdapterOptions);
263
+ getBalance(address: string): Promise<any>;
264
+ deposit(from: string, to: string, amount: string): Promise<any>;
265
+ get chainId(): number;
266
+ get addresses(): string;
267
+ send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
268
+ signTypedData(address: string, data: any): Promise<any>;
269
+ verify(data: {
270
+ domain: any;
271
+ message: any;
272
+ types: any;
273
+ }, signature: string): Promise<void>;
274
+ }
275
+
276
+ 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 };
@@ -0,0 +1,276 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ export { default as EventEmitter } from 'eventemitter3';
3
+ import { AccountStatusEnum } from '@orderly.network/types';
4
+
5
+ interface OrderlyKeyPair {
6
+ getPublicKey(): Promise<string>;
7
+ secretKey: string;
8
+ sign: (data: Uint8Array) => Promise<Uint8Array>;
9
+ }
10
+ declare class BaseOrderlyKeyPair implements OrderlyKeyPair {
11
+ secretKey: string;
12
+ private privateKey;
13
+ static generateKey(): OrderlyKeyPair;
14
+ constructor(secretKey: string);
15
+ sign(message: Uint8Array): Promise<Uint8Array>;
16
+ getPublicKey(): Promise<string>;
17
+ toString(): string;
18
+ }
19
+
20
+ interface OrderlyKeyStore {
21
+ getOrderlyKey: (address?: string) => OrderlyKeyPair | null;
22
+ getAccountId: (address: string) => string | undefined | null;
23
+ setAccountId: (address: string, accountId: string) => void;
24
+ getAddress: () => string | undefined | null;
25
+ setAddress: (address: string) => void;
26
+ generateKey: () => OrderlyKeyPair;
27
+ cleanKey: (address: string, key: string) => void;
28
+ cleanAllKey: (address: string) => void;
29
+ setKey: (orderlyKey: string, secretKey: OrderlyKeyPair) => void;
30
+ }
31
+ declare abstract class BaseKeyStore implements OrderlyKeyStore {
32
+ private readonly networkId;
33
+ constructor(networkId?: string);
34
+ abstract getOrderlyKey(address?: string): OrderlyKeyPair | null;
35
+ abstract getAccountId(address: string): string | undefined | null;
36
+ abstract setAccountId(address: string, accountId: string): void;
37
+ abstract getAddress(): string | undefined | null;
38
+ abstract setAddress(address: string): void;
39
+ abstract generateKey(): OrderlyKeyPair;
40
+ abstract setKey(orderlyKey: string, secretKey: OrderlyKeyPair): void;
41
+ abstract cleanAllKey(address: string): void;
42
+ abstract cleanKey(address: string, key: string): void;
43
+ protected get keyPrefix(): string;
44
+ }
45
+ declare class LocalStorageStore extends BaseKeyStore {
46
+ getOrderlyKey(address?: string): OrderlyKeyPair | null;
47
+ getAccountId(address: string): string | undefined | null;
48
+ setAccountId(address: string, accountId: string): void;
49
+ getAddress(): string | undefined | null;
50
+ setAddress(address: string): void;
51
+ generateKey(): OrderlyKeyPair;
52
+ setKey(address: string, orderlyKey: OrderlyKeyPair): void;
53
+ cleanAllKey(address: string): void;
54
+ cleanKey(address: string, key: string): void;
55
+ private setItem;
56
+ private getItem;
57
+ }
58
+ declare class MockKeyStore implements OrderlyKeyStore {
59
+ private readonly secretKey;
60
+ constructor(secretKey: string);
61
+ generateKey(): BaseOrderlyKeyPair;
62
+ getOrderlyKey(): BaseOrderlyKeyPair;
63
+ getAccountId(): string;
64
+ setAccountId(accountId: string): void;
65
+ getAddress(): string;
66
+ setAddress(address: string): void;
67
+ setKey(orderlyKey: string, secretKey: OrderlyKeyPair): void;
68
+ cleanAllKey(): void;
69
+ cleanKey(key: string): void;
70
+ }
71
+
72
+ type MessageFactor = {
73
+ url: string;
74
+ method: "GET" | "POST" | "PUT" | "DELETE";
75
+ data?: any;
76
+ };
77
+ type SignedMessagePayload = {
78
+ "orderly-key": string;
79
+ "orderly-timestamp": string;
80
+ "orderly-signature": string;
81
+ "orderly-account-id"?: string;
82
+ };
83
+ /**
84
+ * 签名
85
+ * @example
86
+ * ```ts
87
+ * const signer = new BaseSigner(keyStore);
88
+ * const payload = await signer.sign({
89
+ * url: "https://api.orderly.io/get_account?address=0x1234567890&brokerId=woofi_dex",
90
+ * method: "GET",
91
+ * data: {
92
+ * address: "0x1234567890",
93
+ * brokerId: "woofi_dex",
94
+ * },
95
+ * });
96
+ * ```
97
+ */
98
+ interface Signer {
99
+ sign: (data: MessageFactor) => Promise<SignedMessagePayload>;
100
+ signText: (text: string) => Promise<{
101
+ signature: string;
102
+ publicKey: string;
103
+ }>;
104
+ }
105
+ declare class BaseSigner implements Signer {
106
+ private readonly keyStore;
107
+ constructor(keyStore: OrderlyKeyStore);
108
+ sign(message: MessageFactor): Promise<SignedMessagePayload>;
109
+ signText(text: string): Promise<{
110
+ signature: string;
111
+ publicKey: string;
112
+ }>;
113
+ }
114
+
115
+ type ConfigKey = "apiBaseUrl" | "klineDataUrl";
116
+ interface ConfigStore {
117
+ get<T>(key: string): T;
118
+ set<T>(key: string, value: T): void;
119
+ clear(): void;
120
+ }
121
+ declare class MemoryConfigStore implements ConfigStore {
122
+ protected map: Map<string, any>;
123
+ constructor();
124
+ protected _restore(): void;
125
+ get<T>(key: string): T;
126
+ set<T>(key: string, value: T): void;
127
+ clear(): void;
128
+ }
129
+ /**
130
+ *
131
+ */
132
+ declare class BaseConfigStore extends MemoryConfigStore {
133
+ private readonly configMap;
134
+ constructor(configMap: Record<string, any>);
135
+ protected _restore(): void;
136
+ }
137
+
138
+ declare const getMockSigner: (secretKey?: string) => BaseSigner;
139
+ declare const getDefaultSigner: () => BaseSigner;
140
+
141
+ interface IContract {
142
+ getContractInfoByEnv(): any;
143
+ }
144
+ declare class BaseContract implements IContract {
145
+ private readonly configStore;
146
+ constructor(configStore: ConfigStore);
147
+ getContractInfoByEnv(): {
148
+ usdcAddress: string;
149
+ vaultAddress: string;
150
+ verifyContractAddress: string;
151
+ };
152
+ }
153
+
154
+ declare class SimpleDI {
155
+ private static container;
156
+ private static getContainer;
157
+ static register(...serviceClasses: any[]): void;
158
+ static registerByName(name: string, serviceClass: any): void;
159
+ static get<T = any>(name: string): T;
160
+ static getAll(): {
161
+ [name: string]: any;
162
+ };
163
+ private constructor();
164
+ }
165
+
166
+ interface WalletAdapter {
167
+ get chainId(): number;
168
+ get addresses(): string;
169
+ getBalance: (address: string) => Promise<any>;
170
+ deposit: (from: string, to: string, amount: string) => Promise<any>;
171
+ send: (method: string, params: Array<any> | Record<string, any>) => Promise<any>;
172
+ signTypedData: (address: string, data: any) => Promise<string>;
173
+ }
174
+ type WalletAdapterOptions = {
175
+ provider: any;
176
+ address: string;
177
+ label?: string;
178
+ chain: {
179
+ id: string;
180
+ };
181
+ };
182
+ type getWalletAdapterFunc = (options: WalletAdapterOptions) => WalletAdapter;
183
+
184
+ interface AccountState {
185
+ status: AccountStatusEnum;
186
+ checking: boolean;
187
+ accountId?: string;
188
+ userId?: string;
189
+ address?: string;
190
+ balance: string;
191
+ leverage: number;
192
+ positon?: string[];
193
+ orders?: string[];
194
+ }
195
+ /**
196
+ * 账户
197
+ * @example
198
+ * ```ts
199
+ * const account = new Account();
200
+ * account.login("0x1234567890");
201
+ * ```
202
+ */
203
+ declare class Account {
204
+ private readonly configStore;
205
+ private readonly keyStore;
206
+ private readonly contractManger;
207
+ private readonly getWalletAdapter;
208
+ static instanceName: string;
209
+ private _singer?;
210
+ private _ee;
211
+ private _state;
212
+ private walletClient?;
213
+ constructor(configStore: ConfigStore, keyStore: OrderlyKeyStore, contractManger: IContract, getWalletAdapter: getWalletAdapterFunc);
214
+ /**
215
+ * 登录
216
+ * @param address 钱包地址
217
+ */
218
+ login(address: string): void;
219
+ logout(): void;
220
+ /**
221
+ * 连接钱包先用第三方的React版本,不用自己实现
222
+ */
223
+ setAddress(address: string, wallet?: {
224
+ provider: any;
225
+ chain: {
226
+ id: string;
227
+ };
228
+ [key: string]: any;
229
+ }): Promise<AccountStatusEnum>;
230
+ get stateValue(): AccountState;
231
+ get accountId(): string | undefined;
232
+ get address(): string | undefined;
233
+ get chainId(): string | undefined;
234
+ /**
235
+ * set user positions count
236
+ */
237
+ set position(position: string[]);
238
+ set orders(orders: string[]);
239
+ private _bindEvents;
240
+ private _checkAccount;
241
+ private _checkAccountExist;
242
+ createAccount(): Promise<any>;
243
+ createOrderlyKey(expiration: number): Promise<any>;
244
+ settlement(): Promise<any>;
245
+ disconnect(): Promise<void>;
246
+ private _checkOrderlyKeyState;
247
+ get signer(): Signer;
248
+ get wallet(): any;
249
+ private _getRegisterationNonce;
250
+ private _getSettleNonce;
251
+ private _simpleFetch;
252
+ private getDomain;
253
+ get on(): <T extends string | symbol>(event: T, fn: (...args: any[]) => void, context?: any) => EventEmitter<string | symbol, any>;
254
+ get once(): <T extends string | symbol>(event: T, fn: (...args: any[]) => void, context?: any) => EventEmitter<string | symbol, any>;
255
+ get off(): <T extends string | symbol>(event: T, fn?: ((...args: any[]) => void) | undefined, context?: any, once?: boolean | undefined) => EventEmitter<string | symbol, any>;
256
+ }
257
+
258
+ declare class EtherAdapter implements WalletAdapter {
259
+ private provider?;
260
+ private _chainId;
261
+ private _address;
262
+ constructor(options: WalletAdapterOptions);
263
+ getBalance(address: string): Promise<any>;
264
+ deposit(from: string, to: string, amount: string): Promise<any>;
265
+ get chainId(): number;
266
+ get addresses(): string;
267
+ send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
268
+ signTypedData(address: string, data: any): Promise<any>;
269
+ verify(data: {
270
+ domain: any;
271
+ message: any;
272
+ types: any;
273
+ }, signature: string): Promise<void>;
274
+ }
275
+
276
+ 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 };