@ultrade/ultrade-js-sdk 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,1219 +1,11 @@
1
- /******/ (() => { // webpackBootstrap
2
- /******/ "use strict";
3
- /******/ var __webpack_modules__ = ({
4
-
5
- /***/ 10:
6
- /***/ ((module) => {
7
-
8
- module.exports = require("@ultrade/shared/common/index");
9
-
10
- /***/ }),
11
-
12
- /***/ 65:
13
- /***/ ((module) => {
14
-
15
- module.exports = require("@ultrade/shared/helpers/algo.helper");
16
-
17
- /***/ }),
18
-
19
- /***/ 156:
20
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
21
-
22
-
23
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
- if (k2 === undefined) k2 = k;
25
- var desc = Object.getOwnPropertyDescriptor(m, k);
26
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
- desc = { enumerable: true, get: function() { return m[k]; } };
28
- }
29
- Object.defineProperty(o, k2, desc);
30
- }) : (function(o, m, k, k2) {
31
- if (k2 === undefined) k2 = k;
32
- o[k2] = m[k];
33
- }));
34
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
35
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
36
- };
37
- Object.defineProperty(exports, "__esModule", ({ value: true }));
38
- exports.SocketManager = void 0;
39
- __exportStar(__webpack_require__(985), exports);
40
- var sockets_1 = __webpack_require__(382);
41
- Object.defineProperty(exports, "SocketManager", ({ enumerable: true, get: function () { return sockets_1.SocketManager; } }));
42
-
43
-
44
- /***/ }),
45
-
46
- /***/ 185:
47
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
48
-
49
-
50
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
51
- if (k2 === undefined) k2 = k;
52
- var desc = Object.getOwnPropertyDescriptor(m, k);
53
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
54
- desc = { enumerable: true, get: function() { return m[k]; } };
55
- }
56
- Object.defineProperty(o, k2, desc);
57
- }) : (function(o, m, k, k2) {
58
- if (k2 === undefined) k2 = k;
59
- o[k2] = m[k];
60
- }));
61
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
62
- Object.defineProperty(o, "default", { enumerable: true, value: v });
63
- }) : function(o, v) {
64
- o["default"] = v;
65
- });
66
- var __importStar = (this && this.__importStar) || (function () {
67
- var ownKeys = function(o) {
68
- ownKeys = Object.getOwnPropertyNames || function (o) {
69
- var ar = [];
70
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
71
- return ar;
72
- };
73
- return ownKeys(o);
74
- };
75
- return function (mod) {
76
- if (mod && mod.__esModule) return mod;
77
- var result = {};
78
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
79
- __setModuleDefault(result, mod);
80
- return result;
81
- };
82
- })();
83
- Object.defineProperty(exports, "__esModule", ({ value: true }));
84
- exports.decodeString = exports.unpackData = void 0;
85
- const algosdk_1 = __importStar(__webpack_require__(241));
86
- const format = {
87
- priceCoin_locked: {
88
- type: 'uint',
89
- },
90
- priceCoin_available: {
91
- type: 'uint',
92
- },
93
- baseCoin_locked: {
94
- type: 'uint',
95
- },
96
- baseCoin_available: {
97
- type: 'uint',
98
- },
99
- companyId: {
100
- type: 'uint',
101
- },
102
- WLFeeShare: {
103
- type: 'uint',
104
- },
105
- WLCustomFee: {
106
- type: 'uint',
107
- },
108
- slotMap: {
109
- type: 'uint',
110
- },
111
- };
112
- const unpackData = (data) => {
113
- const result = new Map();
114
- let index = 0;
115
- for (const [name, type] of Object.entries(format)) {
116
- if (index >= data.length) {
117
- throw new Error('Array index out of bounds');
118
- }
119
- let value;
120
- switch (type.type) {
121
- case 'address':
122
- value = (0, algosdk_1.encodeAddress)(data.slice(index, index + 32));
123
- index += 32;
124
- break;
125
- case 'bytes':
126
- value = data.slice(index, index + type.size);
127
- value = algosdk_1.default.decodeUint64(value, 'mixed');
128
- index += type.size;
129
- break;
130
- case 'uint':
131
- value = algosdk_1.default.decodeUint64(data.slice(index, index + 8), 'mixed');
132
- index += 8;
133
- break;
134
- case 'string':
135
- value = (0, exports.decodeString)(data.slice(index, index + type.size));
136
- index += type.size;
137
- break;
138
- }
139
- result.set(name, value);
140
- }
141
- return Object.fromEntries(result);
142
- };
143
- exports.unpackData = unpackData;
144
- const decodeString = (value) => {
145
- return Buffer.from(value).toString('utf-8');
146
- };
147
- exports.decodeString = decodeString;
148
-
149
-
150
- /***/ }),
151
-
152
- /***/ 186:
153
- /***/ ((module) => {
154
-
155
- module.exports = require("@ultrade/shared/enums");
156
-
157
- /***/ }),
158
-
159
- /***/ 193:
160
- /***/ ((module) => {
161
-
162
- module.exports = require("@ultrade/shared/constants");
163
-
164
- /***/ }),
165
-
166
- /***/ 230:
167
- /***/ ((module) => {
168
-
169
- module.exports = require("@ultrade/shared/helpers/codex/index");
170
-
171
- /***/ }),
172
-
173
- /***/ 241:
174
- /***/ ((module) => {
175
-
176
- module.exports = require("algosdk");
177
-
178
- /***/ }),
179
-
180
- /***/ 287:
181
- /***/ ((module) => {
182
-
183
- module.exports = require("react-secure-storage");
184
-
185
- /***/ }),
186
-
187
- /***/ 382:
188
- /***/ ((__unused_webpack_module, exports) => {
189
-
190
-
191
- Object.defineProperty(exports, "__esModule", ({ value: true }));
192
- exports.SocketManager = void 0;
193
- class SocketManager {
194
- onDisconnect;
195
- onConnectError;
196
- socket = null;
197
- socketPool = {};
198
- websocketUrl;
199
- socketIOFactory;
200
- constructor(url, socketIOFactory, onDisconnect, onConnectError) {
201
- this.onDisconnect = onDisconnect;
202
- this.onConnectError = onConnectError;
203
- this.websocketUrl = url;
204
- this.socketIOFactory = socketIOFactory;
205
- this.initializeSocket();
206
- }
207
- initializeSocket() {
208
- if (this.socket === null) {
209
- this.socket = this.socketIOFactory(this.websocketUrl, {
210
- reconnection: true,
211
- reconnectionDelay: 1000,
212
- reconnectionAttempts: 9999,
213
- transports: ['websocket'],
214
- });
215
- if (this.onDisconnect) {
216
- this.socket.on('disconnect', () => {
217
- this.onDisconnect(this.socket.id);
218
- });
219
- }
220
- if (this.onConnectError) {
221
- this.socket.on('connect_error', (err) => {
222
- this.onConnectError(err);
223
- });
224
- }
225
- }
226
- }
227
- getSocket() {
228
- return this.socket;
229
- }
230
- subscribe(subscribeOptions, callback) {
231
- const handlerId = Date.now();
232
- if (this.socket === null) {
233
- this.initializeSocket();
234
- }
235
- this.socket.onAny((event, ...args) => {
236
- callback(event, args);
237
- });
238
- this.socket.io.on('reconnect', () => {
239
- this.socket.emit('subscribe', subscribeOptions);
240
- });
241
- this.socket.emit('subscribe', subscribeOptions);
242
- this.socketPool[handlerId] = subscribeOptions;
243
- return handlerId;
244
- }
245
- unsubscribe(handlerId) {
246
- const options = this.socketPool[handlerId];
247
- if (options && this.socket) {
248
- this.socket.emit('unsubscribe', options);
249
- delete this.socketPool[handlerId];
250
- }
251
- if (Object.keys(this.socketPool).length === 0 && this.socket) {
252
- this.disconnect();
253
- }
254
- }
255
- disconnect() {
256
- if (this.socket) {
257
- this.socket.disconnect();
258
- this.socket = null;
259
- }
260
- }
261
- isConnected() {
262
- return this.socket !== null && this.socket.connected;
263
- }
264
- on(event, handler) {
265
- if (this.socket) {
266
- this.socket.on(event, handler);
267
- }
268
- }
269
- off(event, handler) {
270
- if (this.socket) {
271
- if (handler) {
272
- this.socket.off(event, handler);
273
- }
274
- else {
275
- this.socket.off(event);
276
- }
277
- }
278
- }
279
- emit(event, ...args) {
280
- if (this.socket) {
281
- this.socket.emit(event, ...args);
282
- }
283
- }
284
- emitCurrentPair(data) {
285
- this.emit('currentPair', data);
286
- }
287
- emitOrderFilter(data) {
288
- this.emit('orderFilter', data);
289
- }
290
- onReconnect(handler) {
291
- if (this.socket) {
292
- this.socket.io.off('reconnect');
293
- this.socket.io.on('reconnect', handler);
294
- return () => {
295
- if (this.socket) {
296
- this.socket.io.off('reconnect', handler);
297
- }
298
- };
299
- }
300
- return () => { };
301
- }
302
- offReconnect(handler) {
303
- if (this.socket) {
304
- if (handler) {
305
- this.socket.io.off('reconnect', handler);
306
- }
307
- else {
308
- this.socket.io.off('reconnect');
309
- }
310
- }
311
- }
312
- }
313
- exports.SocketManager = SocketManager;
314
-
315
-
316
- /***/ }),
317
-
318
- /***/ 524:
319
- /***/ ((module) => {
320
-
321
- module.exports = require("@ultrade/shared/interfaces");
322
-
323
- /***/ }),
324
-
325
- /***/ 566:
326
- /***/ ((module) => {
327
-
328
- module.exports = require("@ultrade/shared/helpers/withdraw.helper");
329
-
330
- /***/ }),
331
-
332
- /***/ 610:
333
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
334
-
335
-
336
- var __importDefault = (this && this.__importDefault) || function (mod) {
337
- return (mod && mod.__esModule) ? mod : { "default": mod };
338
- };
339
- Object.defineProperty(exports, "__esModule", ({ value: true }));
340
- exports.LocalStorageService = void 0;
341
- const react_secure_storage_1 = __importDefault(__webpack_require__(287));
342
- const host = new URL((window.location !== window.parent.location) ? document.referrer : document.location.href).host;
343
- const addHostPostfix = (key) => `${key}_${host}`;
344
- const secureLocalStorageProxy = new Proxy(react_secure_storage_1.default, {
345
- get(target, prop, receiver) {
346
- if (typeof prop === 'string' && typeof target[prop] === 'function') {
347
- return function (...args) {
348
- if (typeof prop === 'string' && ['setItem', 'getItem', 'removeItem'].includes(prop)) {
349
- args[0] = addHostPostfix(args[0]);
350
- }
351
- return target[prop].apply(target, args);
352
- };
353
- }
354
- return Reflect.get(target, prop, receiver);
355
- }
356
- });
357
- const localStorageProxy = new Proxy(localStorage, {
358
- get(target, prop, receiver) {
359
- if (typeof prop === 'string' && typeof target[prop] === 'function') {
360
- return function (...args) {
361
- if (typeof prop === 'string' && ['setItem', 'getItem', 'removeItem', 'key'].includes(prop)) {
362
- args[0] = addHostPostfix(args[0]);
363
- }
364
- return target[prop].apply(target, args);
365
- };
366
- }
367
- return Reflect.get(target, prop, receiver);
368
- }
369
- });
370
- class LocalStorageService {
371
- isBrowser;
372
- keys = {
373
- mainWallet: 'main-wallet',
374
- tradingKey: 'trading-key'
375
- };
376
- constructor() {
377
- this.isBrowser = typeof window !== 'undefined';
378
- if (!this.isBrowser) {
379
- this.clearMainWallet = () => { };
380
- this.getMainWallet = () => null;
381
- this.setMainWallet = () => { };
382
- }
383
- }
384
- setMainWallet(mainWallet) {
385
- localStorageProxy.setItem(this.keys.mainWallet, JSON.stringify(mainWallet));
386
- }
387
- getMainWallet() {
388
- const mainWalletStr = localStorageProxy.getItem(this.keys.mainWallet);
389
- if (!mainWalletStr) {
390
- return null;
391
- }
392
- const mainWallet = JSON.parse(mainWalletStr);
393
- const tradingKey = secureLocalStorageProxy.getItem(`${this.keys.tradingKey}-${mainWallet.address}`);
394
- // @ts-ignore
395
- if (tradingKey && (tradingKey.expiredAt === 0 || Number(new Date(tradingKey.expiredAt)) - Date.now() > 1)) {
396
- // @ts-ignore
397
- mainWallet.tradingKey = tradingKey.address;
398
- }
399
- return mainWallet;
400
- }
401
- clearMainWallet() {
402
- localStorageProxy.removeItem(this.keys.mainWallet);
403
- }
404
- }
405
- exports.LocalStorageService = LocalStorageService;
406
-
407
-
408
- /***/ }),
409
-
410
- /***/ 726:
411
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
412
-
413
-
414
- var __importDefault = (this && this.__importDefault) || function (mod) {
415
- return (mod && mod.__esModule) ? mod : { "default": mod };
416
- };
417
- Object.defineProperty(exports, "__esModule", ({ value: true }));
418
- exports.AlgodService = void 0;
419
- const algo_helper_1 = __webpack_require__(65);
420
- const algosdk_1 = __importDefault(__webpack_require__(241));
421
- const axios_1 = __importDefault(__webpack_require__(938));
422
- const utils_1 = __webpack_require__(185);
423
- class AlgodService {
424
- client;
425
- authCredentials;
426
- indexerDomain;
427
- constructor(algodClient, credentials, indexerDomain) {
428
- this.client = algodClient;
429
- this.authCredentials = credentials;
430
- this.indexerDomain = indexerDomain;
431
- }
432
- isAppOptedIn(appLocalState, appId) {
433
- return !!appLocalState?.find((app) => app.id === appId);
434
- }
435
- isAssetOptedIn(balances, assetId) {
436
- return Object.keys(balances).includes(assetId.toString());
437
- }
438
- async optInAsset(userAddress, assetIndex) {
439
- const params = await this.getTxnParams();
440
- const response = algosdk_1.default.makeAssetTransferTxnWithSuggestedParamsFromObject({
441
- suggestedParams: {
442
- ...params,
443
- },
444
- from: userAddress,
445
- to: userAddress,
446
- assetIndex: assetIndex,
447
- amount: 0,
448
- });
449
- return response;
450
- }
451
- async makeAppCallTransaction(assetIndex, senderAddress, appId, args, params) {
452
- const accounts = [];
453
- const foreignApps = [];
454
- const foreignAssets = [assetIndex];
455
- const txn = algosdk_1.default.makeApplicationNoOpTxn(senderAddress, params || await this.getTxnParams(), appId, args, accounts, foreignApps, foreignAssets);
456
- return txn;
457
- }
458
- makeTransferTransaction(params, assetIndex, transferAmount, senderAddress, appAddress) {
459
- if (transferAmount <= 0)
460
- return null;
461
- const txn_params = {
462
- suggestedParams: {
463
- ...params,
464
- },
465
- from: senderAddress,
466
- to: appAddress,
467
- amount: transferAmount,
468
- };
469
- if (assetIndex === 0) {
470
- return algosdk_1.default.makePaymentTxnWithSuggestedParamsFromObject(txn_params);
471
- }
472
- txn_params.assetIndex = assetIndex;
473
- return algosdk_1.default.makeAssetTransferTxnWithSuggestedParamsFromObject(
474
- // @ts-ignore
475
- txn_params);
476
- }
477
- get signer() {
478
- return this.authCredentials.signer;
479
- }
480
- set signer(value) {
481
- this.authCredentials.signer = value;
482
- }
483
- async signAndSend(txnGroup) {
484
- if (!Array.isArray(txnGroup))
485
- txnGroup = [txnGroup];
486
- const recoveredAccount = this.getCurrentAccount();
487
- if (recoveredAccount) {
488
- const signedTxns = txnGroup.map((txn) => txn.signTxn(recoveredAccount.sk));
489
- return this.client.sendRawTransaction(signedTxns).do();
490
- }
491
- return this.authCredentials.signer.signAndSend(txnGroup);
492
- }
493
- async signAndSendData(data, signMessage, sendAction, encoding) {
494
- const message = typeof data === "string" ? data : JSON.stringify(data);
495
- const payload = typeof data === "string" ? { message } : { ...data };
496
- const signature = await signMessage(message, encoding);
497
- return sendAction({
498
- ...payload,
499
- signature: signature
500
- });
501
- }
502
- async getTxnParams() {
503
- return await (0, algo_helper_1.getTxnParams)(this.client);
504
- }
505
- getCurrentAccount() {
506
- if (!this.authCredentials.mnemonic)
507
- return null;
508
- return algosdk_1.default.mnemonicToSecretKey(this.authCredentials.mnemonic);
509
- }
510
- async getAccountInfo(address) {
511
- return this.client.accountInformation(address).do();
512
- }
513
- constructArgsForAppCall(...args) {
514
- const appArgs = [];
515
- args.forEach((elem) => {
516
- appArgs.push(new Uint8Array(elem.toBuffer ? elem.toBuffer() : Buffer.from(elem.toString())));
517
- });
518
- return appArgs;
519
- }
520
- validateCredentials() {
521
- if (!this.authCredentials.mnemonic && !this.authCredentials.signer) {
522
- throw 'You need specify mnemonic or signer to execute the method';
523
- }
524
- }
525
- async getAppState(appId) {
526
- try {
527
- const app = await this.client.getApplicationByID(appId).do();
528
- const globalState = (0, algo_helper_1.decodeStateArray)(app['params']['global-state']);
529
- return globalState;
530
- }
531
- catch (error) {
532
- console.log(`Attempt to load app by id ${appId}`);
533
- console.log(error.message);
534
- }
535
- }
536
- async getSuperAppId(appId) {
537
- const state = await this.getAppState(appId);
538
- return state?.['UL_SUPERADMIN_APP'] || 0;
539
- }
540
- async getPairBalances(appId, address) {
541
- const { data } = await axios_1.default.get(`${this.indexerDomain}/v2/accounts/${address}?include-all=true`);
542
- if (data.account.hasOwnProperty('apps-local-state')) {
543
- const state = data.account['apps-local-state'].find((el) => el.id === appId && el.deleted === false);
544
- if (!state) {
545
- return null;
546
- }
547
- const key = state['key-value'].find((el) => el.key === 'YWNjb3VudEluZm8=');
548
- const uintArray = Buffer.from(key.value.bytes, 'base64');
549
- return (0, utils_1.unpackData)(uintArray);
550
- }
551
- }
552
- async calculateTransferAmount(appId, address, side, quantity, price, decimal) {
553
- const pairBalances = await this.getPairBalances(appId, address);
554
- const availableBalance = (side === 'B'
555
- ? pairBalances?.priceCoin_available
556
- : pairBalances?.baseCoin_available) ?? 0;
557
- if (side === 'B') {
558
- quantity = (quantity / 10 ** decimal) * price;
559
- }
560
- const transferAmount = Math.ceil(quantity - availableBalance);
561
- if (transferAmount < 0) {
562
- return 0;
563
- }
564
- return transferAmount;
565
- }
566
- }
567
- exports.AlgodService = AlgodService;
568
-
569
-
570
- /***/ }),
571
-
572
- /***/ 734:
573
- /***/ ((__unused_webpack_module, exports) => {
574
-
575
-
576
- Object.defineProperty(exports, "__esModule", ({ value: true }));
577
- exports.SOCIAL_ACTION_SOURCE = exports.PRIVATE_STREAMS = exports.STREAMS = exports.ORDER_STATUS = exports.DIRECT_SETTLE = void 0;
578
- var DIRECT_SETTLE;
579
- (function (DIRECT_SETTLE) {
580
- DIRECT_SETTLE["YES"] = "Y";
581
- DIRECT_SETTLE["NO"] = "N";
582
- })(DIRECT_SETTLE || (exports.DIRECT_SETTLE = DIRECT_SETTLE = {}));
583
- var ORDER_STATUS;
584
- (function (ORDER_STATUS) {
585
- ORDER_STATUS[ORDER_STATUS["OPEN_ORDER"] = 1] = "OPEN_ORDER";
586
- ORDER_STATUS[ORDER_STATUS["CANCELLED"] = 2] = "CANCELLED";
587
- ORDER_STATUS[ORDER_STATUS["MATCHED"] = 3] = "MATCHED";
588
- ORDER_STATUS[ORDER_STATUS["SELF_MATCHED"] = 4] = "SELF_MATCHED";
589
- })(ORDER_STATUS || (exports.ORDER_STATUS = ORDER_STATUS = {}));
590
- var STREAMS;
591
- (function (STREAMS) {
592
- STREAMS[STREAMS["QUOTE"] = 1] = "QUOTE";
593
- STREAMS[STREAMS["LAST_PRICE"] = 2] = "LAST_PRICE";
594
- STREAMS[STREAMS["DEPTH"] = 3] = "DEPTH";
595
- STREAMS[STREAMS["LAST_CANDLESTICK"] = 4] = "LAST_CANDLESTICK";
596
- STREAMS[STREAMS["ORDERS"] = 5] = "ORDERS";
597
- STREAMS[STREAMS["TRADES"] = 6] = "TRADES";
598
- STREAMS[STREAMS["SYSTEM"] = 7] = "SYSTEM";
599
- STREAMS[STREAMS["WALLET_TRANSACTIONS"] = 8] = "WALLET_TRANSACTIONS";
600
- STREAMS[STREAMS["ALL_STAT"] = 9] = "ALL_STAT";
601
- STREAMS[STREAMS["CODEX_ASSETS"] = 12] = "CODEX_ASSETS";
602
- STREAMS[STREAMS["CODEX_BALANCES"] = 10] = "CODEX_BALANCES";
603
- STREAMS[STREAMS["LAST_LOOK"] = 11] = "LAST_LOOK";
604
- STREAMS[STREAMS["SETTINGS_UPDATE"] = 13] = "SETTINGS_UPDATE";
605
- STREAMS[STREAMS["NEW_NOTIFICATION"] = 14] = "NEW_NOTIFICATION";
606
- STREAMS[STREAMS["POINT_SYSTEM_SETTINGS_UPDATE"] = 15] = "POINT_SYSTEM_SETTINGS_UPDATE";
607
- })(STREAMS || (exports.STREAMS = STREAMS = {}));
608
- exports.PRIVATE_STREAMS = [
609
- STREAMS.ORDERS,
610
- STREAMS.WALLET_TRANSACTIONS,
611
- STREAMS.CODEX_BALANCES,
612
- STREAMS.LAST_LOOK,
613
- ];
614
- var SOCIAL_ACTION_SOURCE;
615
- (function (SOCIAL_ACTION_SOURCE) {
616
- SOCIAL_ACTION_SOURCE["COMPANY"] = "COMPANY";
617
- SOCIAL_ACTION_SOURCE["TWITTER"] = "TWITTER";
618
- SOCIAL_ACTION_SOURCE["DISCORD"] = "DISCORD";
619
- SOCIAL_ACTION_SOURCE["TELEGRAM"] = "TELEGRAM";
620
- })(SOCIAL_ACTION_SOURCE || (exports.SOCIAL_ACTION_SOURCE = SOCIAL_ACTION_SOURCE = {}));
621
-
622
-
623
- /***/ }),
624
-
625
- /***/ 845:
626
- /***/ ((module) => {
627
-
628
- module.exports = require("@ultrade/shared/helpers/codex.helper");
629
-
630
- /***/ }),
631
-
632
- /***/ 938:
633
- /***/ ((module) => {
634
-
635
- module.exports = require("axios");
636
-
637
- /***/ }),
638
-
639
- /***/ 985:
640
- /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
641
-
642
-
643
- // @ts-nocheck
644
- var __importDefault = (this && this.__importDefault) || function (mod) {
645
- return (mod && mod.__esModule) ? mod : { "default": mod };
646
- };
647
- Object.defineProperty(exports, "__esModule", ({ value: true }));
648
- exports.Client = void 0;
649
- const axios_1 = __importDefault(__webpack_require__(938));
650
- const constants_1 = __webpack_require__(193);
651
- const index_1 = __webpack_require__(10);
652
- const codex_helper_1 = __webpack_require__(845);
653
- const withdraw_helper_1 = __webpack_require__(566);
654
- const sockets_1 = __webpack_require__(382);
655
- const algodService_1 = __webpack_require__(726);
656
- const enums_1 = __webpack_require__(734);
657
- const localStorage_1 = __webpack_require__(610);
658
- const interfaces_1 = __webpack_require__(524);
659
- const interfaces_2 = __webpack_require__(524);
660
- const enums_2 = __webpack_require__(186);
661
- const index_2 = __webpack_require__(230);
662
- const DEFAULT_LOGIN_MESSAGE = `By signing this message you are logging into your trading account and agreeing to all terms and conditions of the platform.`;
663
- class Client {
664
- client;
665
- algodNode;
666
- algodIndexer;
667
- apiUrl;
668
- companyId;
669
- websocketUrl;
670
- wallet;
671
- _axios;
672
- localStorageService;
673
- isUltradeID;
674
- socketManager;
675
- constructor(options, authCredentials) {
676
- if (options.network === "mainnet") {
677
- this.algodNode = 'https://mainnet-api.algonode.cloud';
678
- this.apiUrl = 'https://mainnet-api.algonode.cloud';
679
- this.algodIndexer = 'https://mainnet-idx.algonode.cloud';
680
- }
681
- else if (options.network === "testnet") {
682
- this.apiUrl = "https://testnet-apigw.ultradedev.net";
683
- this.algodNode = 'https://testnet-api.algonode.cloud';
684
- this.algodIndexer = 'https://testnet-idx.algonode.cloud';
685
- }
686
- else {
687
- this.apiUrl = "http://localhost:5001";
688
- this.algodNode = 'http://localhost:4001';
689
- this.algodIndexer = 'http://localhost:8980';
690
- }
691
- if (options.apiUrl !== undefined) {
692
- this.apiUrl = options.apiUrl;
693
- }
694
- if (options.companyId !== undefined) {
695
- this.companyId = options.companyId;
696
- }
697
- this.websocketUrl = options.websocketUrl;
698
- this.client = new algodService_1.AlgodService(options.algoSdkClient, authCredentials || {}, this.algodIndexer);
699
- this._axios = this.axiosInterceptor(axios_1.default.create({
700
- baseURL: this.apiUrl,
701
- }));
702
- this.localStorageService = new localStorage_1.LocalStorageService();
703
- this.wallet = this.localStorageService.getMainWallet();
704
- this.isUltradeID = false;
705
- this.socketManager = new sockets_1.SocketManager(this.websocketUrl, options.socketIO, (socketId) => {
706
- console.log(`Socket ${socketId} disconnected at`, new Date());
707
- }, (err) => {
708
- console.log(`Socket connect_error due to ${err}`);
709
- });
710
- console.log('SDK Wallet', this.wallet);
711
- }
712
- axiosInterceptor = (axios) => {
713
- const tokenizedUrls = [
714
- '/market/balances',
715
- '/market/order',
716
- '/market/orders',
717
- '/market/account/kyc/status',
718
- '/market/account/kyc/init',
719
- '/market/withdrawal-fee',
720
- '/market/operation-details',
721
- '/wallet/key',
722
- '/wallet/transactions',
723
- '/wallet/transfer',
724
- '/wallet/withdraw',
725
- '/wallet/whitelist',
726
- '/wallet/withdrawal-wallets',
727
- ];
728
- const tokenRequired = (config) => {
729
- return config.withWalletCredentials || tokenizedUrls.some(value => config.url.includes(value));
730
- };
731
- const tradingKeyRequired = (config) => {
732
- const urls = [
733
- '/market/order',
734
- // '/wallet/transfer',
735
- ];
736
- return config.withWalletCredentials || urls.some(value => config.url.includes(value));
737
- };
738
- const companyIdRequired = (config) => {
739
- const urls = [
740
- '/wallet/signin',
741
- '/market/account/kyc/init',
742
- '/notifications'
743
- ];
744
- return urls.some(value => config.url.includes(value));
745
- };
746
- const isSocialRequest = (config) => {
747
- const urls = [
748
- '/social/',
749
- ];
750
- return urls.some(value => config.url.includes(value));
751
- };
752
- const ifCollectStatistic = (config) => {
753
- return tokenizedUrls.some(value => config.url.includes(value));
754
- };
755
- axios.interceptors.request.use((config) => {
756
- if (this.wallet && tokenRequired(config)) {
757
- config.headers['X-Wallet-Address'] = this.wallet.address;
758
- config.headers['X-Wallet-Token'] = this.wallet.token;
759
- }
760
- if (this.wallet && ifCollectStatistic(config)) {
761
- config.headers['CompanyId'] = this.companyId;
762
- }
763
- if (this.wallet && tradingKeyRequired(config)) {
764
- const tradingKey = this.wallet?.tradingKey;
765
- if (tradingKey) {
766
- config.headers['X-Trading-Key'] = tradingKey;
767
- }
768
- }
769
- if (companyIdRequired(config)) {
770
- config.headers['CompanyId'] = this.companyId;
771
- }
772
- if (isSocialRequest(config) && !config.headers.CompanyId) {
773
- config.headers['CompanyId'] = this.isUltradeID ? 1 : this.companyId;
774
- }
775
- return config;
776
- }, (error) => Promise.reject(error));
777
- //Add a response interceptor
778
- axios.interceptors.response.use((response) => {
779
- return response.data;
780
- }, async (error) => {
781
- console.log('Request was failed', error);
782
- const invalidToken = [401].includes(error?.response?.status);
783
- if (invalidToken && tokenRequired(error.config)) {
784
- this.wallet = null;
785
- this.localStorageService.clearMainWallet();
786
- }
787
- return Promise.reject(error);
788
- });
789
- return axios;
790
- };
791
- // TODO: rework emit logic in SDK UL-1257
792
- // public setState(args: AppSocketState) {
793
- // return ws.emitPair(args);
794
- // }
795
- // public setFilter(args: AppSocketState) {
796
- // return ws.emitFilter(args);
797
- // }
798
- get useUltradeID() {
799
- return this.isUltradeID;
800
- }
801
- set useUltradeID(isUltrade) {
802
- this.isUltradeID = isUltrade;
803
- }
804
- get isLogged() {
805
- return !!this.wallet?.token;
806
- }
807
- get mainWallet() {
808
- return this.wallet;
809
- }
810
- set mainWallet(wallet) {
811
- this.wallet = wallet;
812
- if (!wallet) {
813
- this.localStorageService.clearMainWallet();
814
- }
815
- else {
816
- this.localStorageService.setMainWallet(wallet);
817
- }
818
- }
819
- setSigner(signer) {
820
- this.client.signer = signer;
821
- }
822
- subscribe(subscribeOptions, callback) {
823
- const requiresAuth = subscribeOptions.streams.some(stream => enums_1.PRIVATE_STREAMS.includes(stream));
824
- if (requiresAuth && !this.mainWallet?.token && !this.mainWallet?.tradingKey) {
825
- subscribeOptions.streams = subscribeOptions.streams.filter(stream => !enums_1.PRIVATE_STREAMS.includes(stream));
826
- return this.socketManager.subscribe(subscribeOptions, callback);
827
- }
828
- if (requiresAuth) {
829
- subscribeOptions.options = {
830
- ...subscribeOptions.options,
831
- token: this.mainWallet?.token,
832
- tradingKey: this.mainWallet?.tradingKey
833
- };
834
- return this.socketManager.subscribe(subscribeOptions, callback);
835
- }
836
- return this.socketManager.subscribe(subscribeOptions, callback);
837
- }
838
- unsubscribe(handlerId) {
839
- this.socketManager.unsubscribe(handlerId);
840
- }
841
- getPairList(companyId) {
842
- const query = companyId ? `&companyId=${companyId}` : "";
843
- return this._axios.get(`/market/markets?includeAllOrders=false${query}`);
844
- }
845
- getExchangeInfo(symbol) {
846
- return this._axios.get(`/market/market?symbol=${symbol}`);
847
- }
848
- getPrice(symbol) {
849
- return this._axios.get(`/market/price?symbol=${symbol}`);
850
- }
851
- getDepth(symbol, depth) {
852
- return this._axios.get(`/market/depth?symbol=${symbol}&depth=${depth}`);
853
- }
854
- getSymbols(mask) {
855
- return this._axios.get(`/market/symbols${mask ? '?mask=' + mask : ''}`);
856
- }
857
- getLastTrades(symbol) {
858
- return this._axios.get(`/market/last-trades?symbol=${symbol}`);
859
- }
860
- getHistory(symbol, interval, startTime, endTime, limit = 500, page = 1) {
861
- return this._axios.get(`/market/history?symbol=${symbol}&interval=${interval}&startTime=${startTime ?? ""}&endTime=${endTime ?? ""}&limit=${limit}&page=${page}`);
862
- }
863
- getOrders(symbol, status, limit = 50, endTime, startTime) {
864
- const statusStr = !status
865
- ? ""
866
- : (status === 1)
867
- ? enums_2.OrderStatus.Open
868
- : [enums_2.OrderStatus.Canceled, enums_2.OrderStatus.Matched, enums_2.OrderStatus.SelfMatched, enums_2.OrderStatus.Expired].join(',');
869
- const symbolQuery = symbol ? `&symbol=${symbol}` : "";
870
- const statusQuery = statusStr ? `&status=${statusStr}` : "";
871
- const startTimeQuery = startTime ? `&startTime=${startTime}` : "";
872
- const endTimeQuery = endTime ? `&endTime=${endTime}` : "";
873
- return this._axios.get(`/market/orders?limit=${limit}${symbolQuery}${statusQuery}${startTimeQuery}${endTimeQuery}`);
874
- }
875
- getOrderById(orderId) {
876
- return this._axios.get(`/market/order/${orderId}`);
877
- }
878
- getSettings() {
879
- const domain = new URL((window.location !== window.parent.location) ? document.referrer : document.location.href).host;
880
- return this._axios.get(`/market/settings`, { headers: { "wl-domain": domain } });
881
- }
882
- getBalances() {
883
- return this._axios.get(`/market/balances`);
884
- }
885
- getChains() {
886
- return this._axios.get(`/market/chains`);
887
- }
888
- getCodexAssets() {
889
- return this._axios.get(`/market/assets`);
890
- }
891
- getCCTPAssets() {
892
- return this._axios.get(`/market/cctp-assets`);
893
- }
894
- getCCTPUnifiedAssets() {
895
- return this._axios.get(`/market/cctp-unified-assets`);
896
- }
897
- getWithdrawalFee(assetAddress, chainId) {
898
- return this._axios.get(`/market/withdrawal-fee?assetAddress=${assetAddress}&chainId=${chainId}`);
899
- }
900
- getKycStatus() {
901
- return this._axios.get(`/market/account/kyc/status`);
902
- }
903
- getKycInitLink(embeddedAppUrl) {
904
- return this._axios.post(`/market/account/kyc/init`, { embeddedAppUrl });
905
- }
906
- getDollarValues(assetIds = []) {
907
- return this._axios.get(`/market/dollar-price?assetIds=${JSON.stringify(assetIds)}`);
908
- }
909
- getTransactionDetalis(transactionId) {
910
- return this._axios.get(`/market/operation-details?operationId=${transactionId}`);
911
- }
912
- //#region Wallet
913
- getWalletTransactions(type, page, limit = 100) {
914
- return this._axios.get(`/wallet/transactions?type=${type}&limit=${limit}&page=${page}`, { withWalletCredentials: true });
915
- }
916
- getTradingKeys() {
917
- return this._axios.get(`/wallet/keys`, { withWalletCredentials: true });
918
- }
919
- getTransfers(page, limit = 100) {
920
- return this._axios.get(`/wallet/transfers?limit=${limit}&page=${page}`, { withWalletCredentials: true });
921
- }
922
- getPendingTransactions() {
923
- return this._axios.get(`/wallet/transactions/pending`, { withWalletCredentials: true });
924
- }
925
- getWhitelist() {
926
- return this._axios.get(`/wallet/whitelist`, { withWalletCredentials: true });
927
- }
928
- addWhitelist(data) {
929
- const encoding = 'hex';
930
- data = {
931
- ...data,
932
- expiredDate: data.expiredDate && Math.round(data.expiredDate / 1000)
933
- };
934
- const message = Buffer.from((0, index_2.makeDtwMsg)(data)).toString(encoding);
935
- return this.client.signAndSendData(message, this.client.signer.signMessage, ({ signature }) => this._axios.post(`/wallet/whitelist`, { message, signature }), encoding);
936
- }
937
- deleteWhitelist(whitelistId) {
938
- const data = { whitelistId };
939
- return this.client.signAndSendData(data, this.client.signer.signMessage, ({ signature }) => this._axios.delete(`/wallet/whitelist`, {
940
- data: { data, signature }
941
- }));
942
- }
943
- getAllWithdrawalWallets() {
944
- return this._axios.get(`/wallet/withdrawal-wallets`);
945
- }
946
- getWithdrawalWalletByAddress(address) {
947
- return this._axios.get(`/wallet/withdrawal-wallets/${address}`);
948
- }
949
- createWithdrawalWallet(body) {
950
- return this._axios.post(`/wallet/withdrawal-wallets`, body);
951
- }
952
- updateWithdrawalWallet(params) {
953
- return this._axios.patch(`/wallet/withdrawal-wallets`, params);
954
- }
955
- deleteWithdrawalWallet(address) {
956
- return this._axios.delete(`/wallet/withdrawal-wallets/${address}`);
957
- }
958
- //#endregion Wallet
959
- //#region System
960
- getVersion() {
961
- return this._axios.get(`/system/version`);
962
- }
963
- getMaintenance() {
964
- return this._axios.get(`/system/maintenance`);
965
- }
966
- getNotifications() {
967
- return this._axios.get(`/notifications`, { withWalletCredentials: true });
968
- }
969
- getNotificationsUnreadCount() {
970
- return this._axios.get(`/notifications/count`, { withWalletCredentials: true });
971
- }
972
- readNotifications(notifications) {
973
- return this._axios.put(`/notifications`, { notifications }, { withWalletCredentials: true });
974
- }
975
- //#endregion System
976
- //#region Affiliates
977
- getAffiliatesStatus(companyId) {
978
- return this._axios.get(`/affiliates/${companyId}/dashboardStatus`, { withWalletCredentials: true });
979
- }
980
- createAffiliate(companyId) {
981
- return this._axios.post(`/affiliates/${companyId}`, {}, { withWalletCredentials: true });
982
- }
983
- getAffiliateProgress(companyId) {
984
- return this._axios.get(`/affiliates/${companyId}/tradingVolumeProgress`, { withWalletCredentials: true });
985
- }
986
- getAffiliateInfo(companyId, range) {
987
- return this._axios.get(`/affiliates/${companyId}/dashboard?range=${range}`, { withWalletCredentials: true });
988
- }
989
- countAffiliateDepost(companyId) {
990
- return this._axios.post(`/affiliates/${companyId}/deposit `, {}, { withWalletCredentials: true });
991
- }
992
- countAffiliateClick(referralToken) {
993
- return this._axios.post(`/affiliates/click`, { referralToken }, { withWalletCredentials: true });
994
- }
995
- //#endregion Affiliates
996
- //#region Social
997
- getSocialAccount() {
998
- return this._axios.get(`/social/account`, { withWalletCredentials: true });
999
- }
1000
- addSocialEmail(email, embeddedAppUrl) {
1001
- return this._axios.put(`/social/account/email`, { email, embeddedAppUrl }, { withWalletCredentials: true });
1002
- }
1003
- verifySocialEmail(email, hash) {
1004
- return this._axios.put(`/social/account/verifyEmail`, { email, hash }, { withWalletCredentials: true });
1005
- }
1006
- getLeaderboards() {
1007
- return this._axios.get(`/social/leaderboard`, { withWalletCredentials: true });
1008
- }
1009
- getUnlocks() {
1010
- return this._axios.get(`/social/unlocks`, { withWalletCredentials: true });
1011
- }
1012
- getSocialSettings() {
1013
- return this._axios.get(`/social/settings`, { withWalletCredentials: true });
1014
- }
1015
- getSeason(ultradeId) {
1016
- return this._axios.get(`/social/seasons/active`, {
1017
- withWalletCredentials: true,
1018
- headers: { "CompanyId": ultradeId }
1019
- });
1020
- }
1021
- getPastSeasons() {
1022
- return this._axios.get(`/social/seasons/history`, { withWalletCredentials: true });
1023
- }
1024
- //#region Telegram
1025
- addTelegram(data) {
1026
- return this._axios.post(`/social/telegram/connect`, data, { withWalletCredentials: true });
1027
- }
1028
- disconnectTelegram(data) {
1029
- return this._axios.put(`/social/telegram/disconnect`, data, { withWalletCredentials: true });
1030
- }
1031
- //#endregion Telegram
1032
- //#region Discord
1033
- getDiscordConnectionUrl(url) {
1034
- const query = url ? `?embeddedAppUrl=${encodeURIComponent(url)}` : "";
1035
- return this._axios.get(`/social/discord/connect${query}`, { withWalletCredentials: true })
1036
- .then(({ url }) => url);
1037
- }
1038
- disconnectDiscord() {
1039
- return this._axios.put(`/social/discord/disconnect`, {}, { withWalletCredentials: true });
1040
- }
1041
- //#endregion Discord
1042
- //#region Twitter
1043
- getTwitterConnectionUrl(appUrl, permissions) {
1044
- const queryURL = appUrl ? `?embeddedAppUrl=${encodeURIComponent(appUrl)}` : "";
1045
- const queryPermissions = permissions ? `&scopes=${permissions}` : "";
1046
- return this._axios.get(`/social/twitter/connect${queryURL}${queryPermissions}`, { withWalletCredentials: true })
1047
- .then(({ url }) => url);
1048
- }
1049
- disconnectTwitter() {
1050
- return this._axios.put(`/social/twitter/disconnect`, {}, { withWalletCredentials: true });
1051
- }
1052
- getTweets() {
1053
- return this._axios.get(`/social/twitter/tweets`, { withWalletCredentials: true });
1054
- }
1055
- actionWithTweet(data) {
1056
- return this._axios.post(`/social/twitter/tweet/actions`, data, { withWalletCredentials: true });
1057
- }
1058
- async getActions() {
1059
- return this._axios.get(`/social/actions`, { withWalletCredentials: true });
1060
- }
1061
- async getActionHistory() {
1062
- return this._axios.get(`/social/actions/history`, { withWalletCredentials: true });
1063
- }
1064
- getAIStyles() {
1065
- return this._axios.get(`/social/twitter/tweets/styles`, { withWalletCredentials: true });
1066
- }
1067
- getAIComment(styleId, tweetId) {
1068
- return this._axios.get(`/social/twitter/tweets/${tweetId}/generateComment?styleId=${styleId}`, { withWalletCredentials: true });
1069
- }
1070
- //#endregion Twitter
1071
- //#endregion Social
1072
- getTechnologyByProvider(provider) {
1073
- switch (provider) {
1074
- case interfaces_2.PROVIDERS.PERA:
1075
- return "ALGORAND";
1076
- case interfaces_2.PROVIDERS.METAMASK:
1077
- return "EVM";
1078
- case interfaces_2.PROVIDERS.SOLFLARE:
1079
- case interfaces_2.PROVIDERS.COINBASE:
1080
- case interfaces_2.PROVIDERS.PHANTOM:
1081
- case interfaces_2.PROVIDERS.BACKPACK:
1082
- case interfaces_2.PROVIDERS.MOBILE:
1083
- return "SOLANA";
1084
- default: throw new Error("Not implemented");
1085
- }
1086
- }
1087
- login({ address, provider, chain, referralToken, loginMessage }) {
1088
- const encoding = 'hex';
1089
- const signingMessage = loginMessage || DEFAULT_LOGIN_MESSAGE;
1090
- const data = {
1091
- address,
1092
- technology: this.getTechnologyByProvider(provider),
1093
- };
1094
- const message = Buffer.from((0, codex_helper_1.makeLoginMsg)(data, signingMessage)).toString(encoding);
1095
- return this.client.signAndSendData(message, this.client.signer.signMessage, ({ signature }) => this._axios.put(`/wallet/signin`, { data, message, encoding, signature, referralToken })
1096
- .then((token) => {
1097
- this.mainWallet = { address, provider, token, chain };
1098
- return token;
1099
- }), encoding);
1100
- }
1101
- addTradingKey(data) {
1102
- const encoding = 'hex';
1103
- const message = Buffer.from((0, codex_helper_1.makeTradingKeyMsg)(data, true)).toString(encoding);
1104
- const { device, type } = data;
1105
- return this.client.signAndSendData(message, this.client.signer.signMessage, ({ signature }) => this._axios.post(`/wallet/key`, {
1106
- data: { device, type }, encoding, message, signature
1107
- })
1108
- .then((tradingKey) => {
1109
- if (this.mainWallet && tradingKey.type === interfaces_1.TradingKeyType.User) {
1110
- this.mainWallet.tradingKey = tradingKey.address;
1111
- }
1112
- return tradingKey;
1113
- }), encoding);
1114
- }
1115
- revokeTradingKey(data) {
1116
- const encoding = 'hex';
1117
- const message = Buffer.from((0, codex_helper_1.makeTradingKeyMsg)(data, false)).toString(encoding);
1118
- const { device, type } = data;
1119
- return this.client.signAndSendData(message, this.client.signer.signMessage, ({ signature }) => this._axios.delete(`/wallet/key`, {
1120
- data: { data: { device, type }, encoding, message, signature }
1121
- })
1122
- .then(() => {
1123
- if (this.mainWallet && data.tkAddress === this.mainWallet.tradingKey) {
1124
- this.mainWallet.tradingKey = undefined;
1125
- }
1126
- }), encoding);
1127
- }
1128
- withdraw(withdrawData, prettyMsg) {
1129
- const encoding = 'hex';
1130
- const data = {
1131
- ...withdrawData,
1132
- random: (0, index_1.getRandomInt)(1, Number.MAX_SAFE_INTEGER),
1133
- };
1134
- const message = Buffer.from((0, withdraw_helper_1.makeWithdrawMsg)(data, prettyMsg)).toString(encoding);
1135
- return this.client.signAndSendData(message, this.client.signer.signMessage, ({ signature }) => this._axios.post(`/wallet/withdraw`, { encoding, message, signature, destinationAddress: data.recipient }), encoding);
1136
- }
1137
- transfer(transferData) {
1138
- const encoding = 'hex';
1139
- const data = {
1140
- ...transferData,
1141
- random: (0, index_1.getRandomInt)(1, Number.MAX_SAFE_INTEGER),
1142
- };
1143
- const message = Buffer.from((0, index_2.makeTransferMsg)(data)).toString(encoding);
1144
- return this.client.signAndSendData(message, this.client.signer.signMessage, ({ signature }) => this._axios.post(`/wallet/transfer`, { message, signature }), encoding);
1145
- }
1146
- async createOrder(order) {
1147
- const _daysInSec = constants_1.DEFAULT_ORDER_EXPIRATION_DAYS * 24 * 60 * 60;
1148
- const expiredTime = Math.floor(Date.now() / 1000) + _daysInSec;
1149
- const data = {
1150
- ...order,
1151
- version: constants_1.ORDER_MSG_VERSION,
1152
- expiredTime,
1153
- random: (0, index_1.getRandomInt)(1, Number.MAX_SAFE_INTEGER),
1154
- };
1155
- console.log('CreateOrderData', data);
1156
- const encoding = 'hex';
1157
- const message = Buffer.from((0, codex_helper_1.makeCreateOrderMsg)(data)).toString(encoding);
1158
- return await this.client.signAndSendData(message, this.client.signer.signMessageByToken, ({ signature }) => this._axios.post(`/market/order`, { encoding, message, signature }), encoding);
1159
- }
1160
- async cancelOrder(order) {
1161
- const data = { orderId: order.orderId };
1162
- const encoding = 'hex';
1163
- const message = Buffer.from((0, codex_helper_1.getCancelOrderDataJsonBytes)(order)).toString(encoding);
1164
- return this.client.signAndSendData(message, this.client.signer.signMessageByToken, ({ signature }) => this._axios.delete(`/market/order`, {
1165
- data: { data, message, signature }
1166
- }), encoding);
1167
- }
1168
- async cancelMultipleOrders({ orderIds, pairId }) {
1169
- const data = { orderIds, pairId };
1170
- return this.client.signAndSendData(data, this.client.signer.signMessageByToken, ({ signature }) => this._axios.delete(`/market/orders`, {
1171
- data: { data, signature }
1172
- }));
1173
- }
1174
- async ping() {
1175
- const data = this._axios.get(`/system/time`);
1176
- return Math.round(Date.now() - data.currentTime);
1177
- }
1178
- }
1179
- exports.Client = Client;
1180
-
1181
-
1182
- /***/ })
1183
-
1184
- /******/ });
1185
- /************************************************************************/
1186
- /******/ // The module cache
1187
- /******/ var __webpack_module_cache__ = {};
1188
- /******/
1189
- /******/ // The require function
1190
- /******/ function __webpack_require__(moduleId) {
1191
- /******/ // Check if module is in cache
1192
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
1193
- /******/ if (cachedModule !== undefined) {
1194
- /******/ return cachedModule.exports;
1195
- /******/ }
1196
- /******/ // Create a new module (and put it into the cache)
1197
- /******/ var module = __webpack_module_cache__[moduleId] = {
1198
- /******/ // no module.id needed
1199
- /******/ // no module.loaded needed
1200
- /******/ exports: {}
1201
- /******/ };
1202
- /******/
1203
- /******/ // Execute the module function
1204
- /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
1205
- /******/
1206
- /******/ // Return the exports of the module
1207
- /******/ return module.exports;
1208
- /******/ }
1209
- /******/
1210
- /************************************************************************/
1211
- /******/
1212
- /******/ // startup
1213
- /******/ // Load entry module and return exports
1214
- /******/ // This entry module is referenced by other modules so it can't be inlined
1215
- /******/ var __webpack_exports__ = __webpack_require__(156);
1216
- /******/ module.exports = __webpack_exports__;
1217
- /******/
1218
- /******/ })()
1219
- ;
1
+ function Z(){throw new Error("setTimeout has not been defined")}function j(){throw new Error("clearTimeout has not been defined")}var I=Z,_=j;typeof globalThis.setTimeout=="function"&&(I=setTimeout);typeof globalThis.clearTimeout=="function"&&(_=clearTimeout);function ee(r){if(I===setTimeout)return setTimeout(r,0);if((I===Z||!I)&&setTimeout)return I=setTimeout,setTimeout(r,0);try{return I(r,0)}catch{try{return I.call(null,r,0)}catch{return I.call(this,r,0)}}}function Ee(r){if(_===clearTimeout)return clearTimeout(r);if((_===j||!_)&&clearTimeout)return _=clearTimeout,clearTimeout(r);try{return _(r)}catch{try{return _.call(null,r)}catch{return _.call(this,r)}}}var A=[],W=!1,E,B=-1;function Te(){!W||!E||(W=!1,E.length?A=E.concat(A):B=-1,A.length&&te())}function te(){if(!W){var r=ee(Te);W=!0;for(var e=A.length;e;){for(E=A,A=[];++B<e;)E&&E[B].run();B=-1,e=A.length}E=null,W=!1,Ee(r)}}function Ce(r){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];A.push(new re(r,e)),A.length===1&&!W&&ee(te)}function re(r,e){this.fun=r,this.array=e}re.prototype.run=function(){this.fun.apply(null,this.array)};var ve="browser",Pe="browser",Se=!0,We={},Ue=[],De="",Re={},Be={},Me={};function T(){}var Ne=T,Le=T,Oe=T,$e=T,Ye=T,Fe=T,Ke=T;function qe(r){throw new Error("process.binding is not supported")}function Ve(){return"/"}function Xe(r){throw new Error("process.chdir is not supported")}function Ge(){return 0}var S=globalThis.performance||{},ze=S.now||S.mozNow||S.msNow||S.oNow||S.webkitNow||function(){return new Date().getTime()};function He(r){var e=ze.call(S)*.001,t=Math.floor(e),i=Math.floor(e%1*1e9);return r&&(t=t-r[0],i=i-r[1],i<0&&(t--,i+=1e9)),[t,i]}var Je=new Date;function Qe(){var r=new Date,e=r-Je;return e/1e3}var b={nextTick:Ce,title:ve,browser:Se,env:We,argv:Ue,version:De,versions:Re,on:Ne,addListener:Le,once:Oe,off:$e,removeListener:Ye,removeAllListeners:Fe,emit:Ke,binding:qe,cwd:Ve,chdir:Xe,umask:Ge,hrtime:He,platform:Pe,release:Be,config:Me,uptime:Qe},Q={};Object.keys(Q).forEach(r=>{let e=r.split("."),t=b;for(let i=0;i<e.length;i++){let n=e[i];i===e.length-1?t[n]=Q[r]:t=t[n]||(t[n]={})}});var x=[],m=[],Ze=typeof Uint8Array<"u"?Uint8Array:Array,V=!1;function ae(){V=!0;for(var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0,t=r.length;e<t;++e)x[e]=r[e],m[r.charCodeAt(e)]=e;m[45]=62,m[95]=63}function je(r){V||ae();var e,t,i,n,s,a,c=r.length;if(c%4>0)throw new Error("Invalid string. Length must be a multiple of 4");s=r[c-2]==="="?2:r[c-1]==="="?1:0,a=new Ze(c*3/4-s),i=s>0?c-4:c;var l=0;for(e=0,t=0;e<i;e+=4,t+=3)n=m[r.charCodeAt(e)]<<18|m[r.charCodeAt(e+1)]<<12|m[r.charCodeAt(e+2)]<<6|m[r.charCodeAt(e+3)],a[l++]=n>>16&255,a[l++]=n>>8&255,a[l++]=n&255;return s===2?(n=m[r.charCodeAt(e)]<<2|m[r.charCodeAt(e+1)]>>4,a[l++]=n&255):s===1&&(n=m[r.charCodeAt(e)]<<10|m[r.charCodeAt(e+1)]<<4|m[r.charCodeAt(e+2)]>>2,a[l++]=n>>8&255,a[l++]=n&255),a}function et(r){return x[r>>18&63]+x[r>>12&63]+x[r>>6&63]+x[r&63]}function tt(r,e,t){for(var i,n=[],s=e;s<t;s+=3)i=(r[s]<<16)+(r[s+1]<<8)+r[s+2],n.push(et(i));return n.join("")}function ie(r){V||ae();for(var e,t=r.length,i=t%3,n="",s=[],a=16383,c=0,l=t-i;c<l;c+=a)s.push(tt(r,c,c+a>l?l:c+a));return i===1?(e=r[t-1],n+=x[e>>2],n+=x[e<<4&63],n+="=="):i===2&&(e=(r[t-2]<<8)+r[t-1],n+=x[e>>10],n+=x[e>>4&63],n+=x[e<<2&63],n+="="),s.push(n),s.join("")}o.TYPED_ARRAY_SUPPORT=globalThis.TYPED_ARRAY_SUPPORT!==void 0?globalThis.TYPED_ARRAY_SUPPORT:!0;function M(){return o.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function k(r,e){if(M()<e)throw new RangeError("Invalid typed array length");return o.TYPED_ARRAY_SUPPORT?(r=new Uint8Array(e),r.__proto__=o.prototype):(r===null&&(r=new o(e)),r.length=e),r}function o(r,e,t){if(!o.TYPED_ARRAY_SUPPORT&&!(this instanceof o))return new o(r,e,t);if(typeof r=="number"){if(typeof e=="string")throw new Error("If encoding is specified then the first argument must be a string");return X(this,r)}return oe(this,r,e,t)}o.poolSize=8192;o._augment=function(r){return r.__proto__=o.prototype,r};function oe(r,e,t,i){if(typeof e=="number")throw new TypeError('"value" argument must not be a number');return typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer?nt(r,e,t,i):typeof e=="string"?it(r,e,t):st(r,e)}o.from=function(r,e,t){return oe(null,r,e,t)};o.kMaxLength=M();o.TYPED_ARRAY_SUPPORT&&(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,typeof Symbol<"u"&&Symbol.species&&o[Symbol.species]);function le(r){if(typeof r!="number")throw new TypeError('"size" argument must be a number');if(r<0)throw new RangeError('"size" argument must not be negative')}function rt(r,e,t,i){return le(e),e<=0?k(r,e):t!==void 0?typeof i=="string"?k(r,e).fill(t,i):k(r,e).fill(t):k(r,e)}o.alloc=function(r,e,t){return rt(null,r,e,t)};function X(r,e){if(le(e),r=k(r,e<0?0:G(e)|0),!o.TYPED_ARRAY_SUPPORT)for(var t=0;t<e;++t)r[t]=0;return r}o.allocUnsafe=function(r){return X(null,r)};o.allocUnsafeSlow=function(r){return X(null,r)};function it(r,e,t){if((typeof t!="string"||t==="")&&(t="utf8"),!o.isEncoding(t))throw new TypeError('"encoding" must be a valid string encoding');var i=ce(e,t)|0;r=k(r,i);var n=r.write(e,t);return n!==i&&(r=r.slice(0,n)),r}function q(r,e){var t=e.length<0?0:G(e.length)|0;r=k(r,t);for(var i=0;i<t;i+=1)r[i]=e[i]&255;return r}function nt(r,e,t,i){if(e.byteLength,t<0||e.byteLength<t)throw new RangeError("'offset' is out of bounds");if(e.byteLength<t+(i||0))throw new RangeError("'length' is out of bounds");return t===void 0&&i===void 0?e=new Uint8Array(e):i===void 0?e=new Uint8Array(e,t):e=new Uint8Array(e,t,i),o.TYPED_ARRAY_SUPPORT?(r=e,r.__proto__=o.prototype):r=q(r,e),r}function st(r,e){if(y(e)){var t=G(e.length)|0;return r=k(r,t),r.length===0||e.copy(r,0,0,t),r}if(e){if(typeof ArrayBuffer<"u"&&e.buffer instanceof ArrayBuffer||"length"in e)return typeof e.length!="number"||_t(e.length)?k(r,0):q(r,e);if(e.type==="Buffer"&&Array.isArray(e.data))return q(r,e.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function G(r){if(r>=M())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+M().toString(16)+" bytes");return r|0}o.isBuffer=Et;function y(r){return!!(r!=null&&r._isBuffer)}o.compare=function(e,t){if(!y(e)||!y(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var i=e.length,n=t.length,s=0,a=Math.min(i,n);s<a;++s)if(e[s]!==t[s]){i=e[s],n=t[s];break}return i<n?-1:n<i?1:0};o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};o.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(e.length===0)return o.alloc(0);var i;if(t===void 0)for(t=0,i=0;i<e.length;++i)t+=e[i].length;var n=o.allocUnsafe(t),s=0;for(i=0;i<e.length;++i){var a=e[i];if(!y(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,s),s+=a.length}return n};function ce(r,e){if(y(r))return r.length;if(typeof ArrayBuffer<"u"&&typeof ArrayBuffer.isView=="function"&&(ArrayBuffer.isView(r)||r instanceof ArrayBuffer))return r.byteLength;typeof r!="string"&&(r=""+r);var t=r.length;if(t===0)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":case void 0:return N(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return me(r).length;default:if(i)return N(r).length;e=(""+e).toLowerCase(),i=!0}}o.byteLength=ce;function at(r,e,t){var 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 mt(this,e,t);case"utf8":case"utf-8":return fe(this,e,t);case"ascii":return dt(this,e,t);case"latin1":case"binary":return gt(this,e,t);case"base64":return ft(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return wt(this,e,t);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),i=!0}}o.prototype._isBuffer=!0;function C(r,e,t){var i=r[e];r[e]=r[t],r[t]=i}o.prototype.swap16=function(){var e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)C(this,t,t+1);return this};o.prototype.swap32=function(){var e=this.length;if(e%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)C(this,t,t+3),C(this,t+1,t+2);return this};o.prototype.swap64=function(){var e=this.length;if(e%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)C(this,t,t+7),C(this,t+1,t+6),C(this,t+2,t+5),C(this,t+3,t+4);return this};o.prototype.toString=function(){var e=this.length|0;return e===0?"":arguments.length===0?fe(this,0,e):at.apply(this,arguments)};o.prototype.equals=function(e){if(!y(e))throw new TypeError("Argument must be a Buffer");return this===e?!0:o.compare(this,e)===0};o.prototype.compare=function(e,t,i,n,s){if(!y(e))throw new TypeError("Argument must be a Buffer");if(t===void 0&&(t=0),i===void 0&&(i=e?e.length:0),n===void 0&&(n=0),s===void 0&&(s=this.length),t<0||i>e.length||n<0||s>this.length)throw new RangeError("out of range index");if(n>=s&&t>=i)return 0;if(n>=s)return-1;if(t>=i)return 1;if(t>>>=0,i>>>=0,n>>>=0,s>>>=0,this===e)return 0;for(var a=s-n,c=i-t,l=Math.min(a,c),u=this.slice(n,s),h=e.slice(t,i),f=0;f<l;++f)if(u[f]!==h[f]){a=u[f],c=h[f];break}return a<c?-1:c<a?1:0};function ue(r,e,t,i,n){if(r.length===0)return-1;if(typeof t=="string"?(i=t,t=0):t>2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,isNaN(t)&&(t=n?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(n)return-1;t=r.length-1}else if(t<0)if(n)t=0;else return-1;if(typeof e=="string"&&(e=o.from(e,i)),y(e))return e.length===0?-1:ne(r,e,t,i,n);if(typeof e=="number")return e=e&255,o.TYPED_ARRAY_SUPPORT&&typeof Uint8Array.prototype.indexOf=="function"?n?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):ne(r,[e],t,i,n);throw new TypeError("val must be string, number or Buffer")}function ne(r,e,t,i,n){var s=1,a=r.length,c=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;s=2,a/=2,c/=2,t/=2}function l(g,P){return s===1?g[P]:g.readUInt16BE(P*s)}var u;if(n){var h=-1;for(u=t;u<a;u++)if(l(r,u)===l(e,h===-1?0:u-h)){if(h===-1&&(h=u),u-h+1===c)return h*s}else h!==-1&&(u-=u-h),h=-1}else for(t+c>a&&(t=a-c),u=t;u>=0;u--){for(var f=!0,w=0;w<c;w++)if(l(r,u+w)!==l(e,w)){f=!1;break}if(f)return u}return-1}o.prototype.includes=function(e,t,i){return this.indexOf(e,t,i)!==-1};o.prototype.indexOf=function(e,t,i){return ue(this,e,t,i,!0)};o.prototype.lastIndexOf=function(e,t,i){return ue(this,e,t,i,!1)};function ot(r,e,t,i){t=Number(t)||0;var n=r.length-t;i?(i=Number(i),i>n&&(i=n)):i=n;var s=e.length;if(s%2!==0)throw new TypeError("Invalid hex string");i>s/2&&(i=s/2);for(var a=0;a<i;++a){var c=parseInt(e.substr(a*2,2),16);if(isNaN(c))return a;r[t+a]=c}return a}function lt(r,e,t,i){return $(N(e,r.length-t),r,t,i)}function he(r,e,t,i){return $(kt(e),r,t,i)}function ct(r,e,t,i){return he(r,e,t,i)}function ut(r,e,t,i){return $(me(e),r,t,i)}function ht(r,e,t,i){return $(It(e,r.length-t),r,t,i)}o.prototype.write=function(e,t,i,n){if(t===void 0)n="utf8",i=this.length,t=0;else if(i===void 0&&typeof t=="string")n=t,i=this.length,t=0;else if(isFinite(t))t=t|0,isFinite(i)?(i=i|0,n===void 0&&(n="utf8")):(n=i,i=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var s=this.length-t;if((i===void 0||i>s)&&(i=s),e.length>0&&(i<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var a=!1;;)switch(n){case"hex":return ot(this,e,t,i);case"utf8":case"utf-8":return lt(this,e,t,i);case"ascii":return he(this,e,t,i);case"latin1":case"binary":return ct(this,e,t,i);case"base64":return ut(this,e,t,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ht(this,e,t,i);default:if(a)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),a=!0}};o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function ft(r,e,t){return e===0&&t===r.length?ie(r):ie(r.slice(e,t))}function fe(r,e,t){t=Math.min(r.length,t);for(var i=[],n=e;n<t;){var s=r[n],a=null,c=s>239?4:s>223?3:s>191?2:1;if(n+c<=t){var l,u,h,f;switch(c){case 1:s<128&&(a=s);break;case 2:l=r[n+1],(l&192)===128&&(f=(s&31)<<6|l&63,f>127&&(a=f));break;case 3:l=r[n+1],u=r[n+2],(l&192)===128&&(u&192)===128&&(f=(s&15)<<12|(l&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(a=f));break;case 4:l=r[n+1],u=r[n+2],h=r[n+3],(l&192)===128&&(u&192)===128&&(h&192)===128&&(f=(s&15)<<18|(l&63)<<12|(u&63)<<6|h&63,f>65535&&f<1114112&&(a=f))}}a===null?(a=65533,c=1):a>65535&&(a-=65536,i.push(a>>>10&1023|55296),a=56320|a&1023),i.push(a),n+=c}return pt(i)}var se=4096;function pt(r){var e=r.length;if(e<=se)return String.fromCharCode.apply(String,r);for(var t="",i=0;i<e;)t+=String.fromCharCode.apply(String,r.slice(i,i+=se));return t}function dt(r,e,t){var i="";t=Math.min(r.length,t);for(var n=e;n<t;++n)i+=String.fromCharCode(r[n]&127);return i}function gt(r,e,t){var i="";t=Math.min(r.length,t);for(var n=e;n<t;++n)i+=String.fromCharCode(r[n]);return i}function mt(r,e,t){var i=r.length;(!e||e<0)&&(e=0),(!t||t<0||t>i)&&(t=i);for(var n="",s=e;s<t;++s)n+=bt(r[s]);return n}function wt(r,e,t){for(var i=r.slice(e,t),n="",s=0;s<i.length;s+=2)n+=String.fromCharCode(i[s]+i[s+1]*256);return n}o.prototype.slice=function(e,t){var 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);var n;if(o.TYPED_ARRAY_SUPPORT)n=this.subarray(e,t),n.__proto__=o.prototype;else{var s=t-e;n=new o(s,void 0);for(var a=0;a<s;++a)n[a]=this[a+e]}return n};function p(r,e,t){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+e>t)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUIntLE=function(e,t,i){e=e|0,t=t|0,i||p(e,t,this.length);for(var n=this[e],s=1,a=0;++a<t&&(s*=256);)n+=this[e+a]*s;return n};o.prototype.readUIntBE=function(e,t,i){e=e|0,t=t|0,i||p(e,t,this.length);for(var n=this[e+--t],s=1;t>0&&(s*=256);)n+=this[e+--t]*s;return n};o.prototype.readUInt8=function(e,t){return t||p(e,1,this.length),this[e]};o.prototype.readUInt16LE=function(e,t){return t||p(e,2,this.length),this[e]|this[e+1]<<8};o.prototype.readUInt16BE=function(e,t){return t||p(e,2,this.length),this[e]<<8|this[e+1]};o.prototype.readUInt32LE=function(e,t){return t||p(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};o.prototype.readUInt32BE=function(e,t){return t||p(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};o.prototype.readIntLE=function(e,t,i){e=e|0,t=t|0,i||p(e,t,this.length);for(var n=this[e],s=1,a=0;++a<t&&(s*=256);)n+=this[e+a]*s;return s*=128,n>=s&&(n-=Math.pow(2,8*t)),n};o.prototype.readIntBE=function(e,t,i){e=e|0,t=t|0,i||p(e,t,this.length);for(var n=t,s=1,a=this[e+--n];n>0&&(s*=256);)a+=this[e+--n]*s;return s*=128,a>=s&&(a-=Math.pow(2,8*t)),a};o.prototype.readInt8=function(e,t){return t||p(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};o.prototype.readInt16LE=function(e,t){t||p(e,2,this.length);var i=this[e]|this[e+1]<<8;return i&32768?i|4294901760:i};o.prototype.readInt16BE=function(e,t){t||p(e,2,this.length);var i=this[e+1]|this[e]<<8;return i&32768?i|4294901760:i};o.prototype.readInt32LE=function(e,t){return t||p(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};o.prototype.readInt32BE=function(e,t){return t||p(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};o.prototype.readFloatLE=function(e,t){return t||p(e,4,this.length),Y(this,e,!0,23,4)};o.prototype.readFloatBE=function(e,t){return t||p(e,4,this.length),Y(this,e,!1,23,4)};o.prototype.readDoubleLE=function(e,t){return t||p(e,8,this.length),Y(this,e,!0,52,8)};o.prototype.readDoubleBE=function(e,t){return t||p(e,8,this.length),Y(this,e,!1,52,8)};function d(r,e,t,i,n,s){if(!y(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>n||e<s)throw new RangeError('"value" argument is out of bounds');if(t+i>r.length)throw new RangeError("Index out of range")}o.prototype.writeUIntLE=function(e,t,i,n){if(e=+e,t=t|0,i=i|0,!n){var s=Math.pow(2,8*i)-1;d(this,e,t,i,s,0)}var a=1,c=0;for(this[t]=e&255;++c<i&&(a*=256);)this[t+c]=e/a&255;return t+i};o.prototype.writeUIntBE=function(e,t,i,n){if(e=+e,t=t|0,i=i|0,!n){var s=Math.pow(2,8*i)-1;d(this,e,t,i,s,0)}var a=i-1,c=1;for(this[t+a]=e&255;--a>=0&&(c*=256);)this[t+a]=e/c&255;return t+i};o.prototype.writeUInt8=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,1,255,0),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=e&255,t+1};function L(r,e,t,i){e<0&&(e=65535+e+1);for(var n=0,s=Math.min(r.length-t,2);n<s;++n)r[t+n]=(e&255<<8*(i?n:1-n))>>>(i?n:1-n)*8}o.prototype.writeUInt16LE=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8):L(this,e,t,!0),t+2};o.prototype.writeUInt16BE=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e&255):L(this,e,t,!1),t+2};function O(r,e,t,i){e<0&&(e=4294967295+e+1);for(var n=0,s=Math.min(r.length-t,4);n<s;++n)r[t+n]=e>>>(i?n:3-n)*8&255}o.prototype.writeUInt32LE=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255):O(this,e,t,!0),t+4};o.prototype.writeUInt32BE=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255):O(this,e,t,!1),t+4};o.prototype.writeIntLE=function(e,t,i,n){if(e=+e,t=t|0,!n){var s=Math.pow(2,8*i-1);d(this,e,t,i,s-1,-s)}var a=0,c=1,l=0;for(this[t]=e&255;++a<i&&(c*=256);)e<0&&l===0&&this[t+a-1]!==0&&(l=1),this[t+a]=(e/c>>0)-l&255;return t+i};o.prototype.writeIntBE=function(e,t,i,n){if(e=+e,t=t|0,!n){var s=Math.pow(2,8*i-1);d(this,e,t,i,s-1,-s)}var a=i-1,c=1,l=0;for(this[t+a]=e&255;--a>=0&&(c*=256);)e<0&&l===0&&this[t+a+1]!==0&&(l=1),this[t+a]=(e/c>>0)-l&255;return t+i};o.prototype.writeInt8=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,1,127,-128),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=e&255,t+1};o.prototype.writeInt16LE=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8):L(this,e,t,!0),t+2};o.prototype.writeInt16BE=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e&255):L(this,e,t,!1),t+2};o.prototype.writeInt32LE=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):O(this,e,t,!0),t+4};o.prototype.writeInt32BE=function(e,t,i){return e=+e,t=t|0,i||d(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255):O(this,e,t,!1),t+4};function pe(r,e,t,i,n,s){if(t+i>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function de(r,e,t,i,n){return n||pe(r,e,t,4,34028234663852886e22,-34028234663852886e22),xe(r,e,t,i,23,4),t+4}o.prototype.writeFloatLE=function(e,t,i){return de(this,e,t,!0,i)};o.prototype.writeFloatBE=function(e,t,i){return de(this,e,t,!1,i)};function ge(r,e,t,i,n){return n||pe(r,e,t,8,17976931348623157e292,-17976931348623157e292),xe(r,e,t,i,52,8),t+8}o.prototype.writeDoubleLE=function(e,t,i){return ge(this,e,t,!0,i)};o.prototype.writeDoubleBE=function(e,t,i){return ge(this,e,t,!1,i)};o.prototype.copy=function(e,t,i,n){if(i||(i=0),!n&&n!==0&&(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<i&&(n=i),n===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("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-i&&(n=e.length-t+i);var s=n-i,a;if(this===e&&i<t&&t<n)for(a=s-1;a>=0;--a)e[a+t]=this[a+i];else if(s<1e3||!o.TYPED_ARRAY_SUPPORT)for(a=0;a<s;++a)e[a+t]=this[a+i];else Uint8Array.prototype.set.call(e,this.subarray(i,i+s),t);return s};o.prototype.fill=function(e,t,i,n){if(typeof e=="string"){if(typeof t=="string"?(n=t,t=0,i=this.length):typeof i=="string"&&(n=i,i=this.length),e.length===1){var s=e.charCodeAt(0);s<256&&(e=s)}if(n!==void 0&&typeof n!="string")throw new TypeError("encoding must be a string");if(typeof n=="string"&&!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else typeof e=="number"&&(e=e&255);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);var a;if(typeof e=="number")for(a=t;a<i;++a)this[a]=e;else{var c=y(e)?e:N(new o(e,n).toString()),l=c.length;for(a=0;a<i-t;++a)this[a+t]=c[a%l]}return this};var xt=/[^+\/0-9A-Za-z-_]/g;function yt(r){if(r=At(r).replace(xt,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function At(r){return r.trim?r.trim():r.replace(/^\s+|\s+$/g,"")}function bt(r){return r<16?"0"+r.toString(16):r.toString(16)}function N(r,e){e=e||1/0;for(var t,i=r.length,n=null,s=[],a=0;a<i;++a){if(t=r.charCodeAt(a),t>55295&&t<57344){if(!n){if(t>56319){(e-=3)>-1&&s.push(239,191,189);continue}else if(a+1===i){(e-=3)>-1&&s.push(239,191,189);continue}n=t;continue}if(t<56320){(e-=3)>-1&&s.push(239,191,189),n=t;continue}t=(n-55296<<10|t-56320)+65536}else n&&(e-=3)>-1&&s.push(239,191,189);if(n=null,t<128){if((e-=1)<0)break;s.push(t)}else if(t<2048){if((e-=2)<0)break;s.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;s.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;s.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return s}function kt(r){for(var e=[],t=0;t<r.length;++t)e.push(r.charCodeAt(t)&255);return e}function It(r,e){for(var t,i,n,s=[],a=0;a<r.length&&!((e-=2)<0);++a)t=r.charCodeAt(a),i=t>>8,n=t%256,s.push(n),s.push(i);return s}function me(r){return je(yt(r))}function $(r,e,t,i){for(var n=0;n<i&&!(n+t>=e.length||n>=r.length);++n)e[n+t]=r[n];return n}function _t(r){return r!==r}function Et(r){return r!=null&&(!!r._isBuffer||we(r)||Tt(r))}function we(r){return!!r.constructor&&typeof r.constructor.isBuffer=="function"&&r.constructor.isBuffer(r)}function Tt(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&we(r.slice(0,0))}function Y(r,e,t,i,n){var s,a,c=n*8-i-1,l=(1<<c)-1,u=l>>1,h=-7,f=t?n-1:0,w=t?-1:1,g=r[e+f];for(f+=w,s=g&(1<<-h)-1,g>>=-h,h+=c;h>0;s=s*256+r[e+f],f+=w,h-=8);for(a=s&(1<<-h)-1,s>>=-h,h+=i;h>0;a=a*256+r[e+f],f+=w,h-=8);if(s===0)s=1-u;else{if(s===l)return a?NaN:(g?-1:1)*(1/0);a=a+Math.pow(2,i),s=s-u}return(g?-1:1)*a*Math.pow(2,s-i)}function xe(r,e,t,i,n,s){var a,c,l,u=s*8-n-1,h=(1<<u)-1,f=h>>1,w=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,g=i?0:s-1,P=i?1:-1,_e=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(c=isNaN(e)?1:0,a=h):(a=Math.floor(Math.log(e)/Math.LN2),e*(l=Math.pow(2,-a))<1&&(a--,l*=2),a+f>=1?e+=w/l:e+=w*Math.pow(2,1-f),e*l>=2&&(a++,l/=2),a+f>=h?(c=0,a=h):a+f>=1?(c=(e*l-1)*Math.pow(2,n),a=a+f):(c=e*Math.pow(2,f-1)*Math.pow(2,n),a=0));n>=8;r[t+g]=c&255,g+=P,c/=256,n-=8);for(a=a<<n|c,u+=n;u>0;r[t+g]=a&255,g+=P,a/=256,u-=8);r[t+g-P]|=_e*128}import Mt from"axios";import{DEFAULT_ORDER_EXPIRATION_DAYS as Nt,ORDER_MSG_VERSION as Lt}from"@ultrade/shared/constants";import{getRandomInt as J}from"@ultrade/shared/common/index";import{getCancelOrderDataJsonBytes as Ot,makeLoginMsg as $t,makeTradingKeyMsg as ke,makeCreateOrderMsg as Yt}from"@ultrade/shared/helpers/codex.helper";import{makeWithdrawMsg as Ft}from"@ultrade/shared/helpers/withdraw.helper";var U=class{constructor(e,t,i,n){this.onDisconnect=i;this.onConnectError=n;this.websocketUrl=e,this.socketIOFactory=t,this.initializeSocket()}socket=null;socketPool={};websocketUrl;socketIOFactory;initializeSocket(){this.socket===null&&(this.socket=this.socketIOFactory(this.websocketUrl,{reconnection:!0,reconnectionDelay:1e3,reconnectionAttempts:9999,transports:["websocket"]}),this.onDisconnect&&this.socket.on("disconnect",()=>{this.onDisconnect(this.socket.id)}),this.onConnectError&&this.socket.on("connect_error",e=>{this.onConnectError(e)}))}getSocket(){return this.socket}subscribe(e,t){let i=Date.now();return this.socket===null&&this.initializeSocket(),this.socket.onAny((n,...s)=>{t(n,s)}),this.socket.io.on("reconnect",()=>{this.socket.emit("subscribe",e)}),this.socket.emit("subscribe",e),this.socketPool[i]=e,i}unsubscribe(e){let t=this.socketPool[e];t&&this.socket&&(this.socket.emit("unsubscribe",t),delete this.socketPool[e]),Object.keys(this.socketPool).length===0&&this.socket&&this.disconnect()}disconnect(){this.socket&&(this.socket.disconnect(),this.socket=null)}isConnected(){return this.socket!==null&&this.socket.connected}on(e,t){this.socket&&this.socket.on(e,t)}off(e,t){this.socket&&(t?this.socket.off(e,t):this.socket.off(e))}emit(e,...t){this.socket&&this.socket.emit(e,...t)}emitCurrentPair(e){this.emit("currentPair",e)}emitOrderFilter(e){this.emit("orderFilter",e)}onReconnect(e){return this.socket?(this.socket.io.off("reconnect"),this.socket.io.on("reconnect",e),()=>{this.socket&&this.socket.io.off("reconnect",e)}):()=>{}}offReconnect(e){this.socket&&(e?this.socket.io.off("reconnect",e):this.socket.io.off("reconnect"))}};import{decodeStateArray as St,getTxnParams as Wt}from"@ultrade/shared/helpers/algo.helper";import D from"algosdk";import Ut from"axios";import ye,{encodeAddress as Ct}from"algosdk";var vt={priceCoin_locked:{type:"uint"},priceCoin_available:{type:"uint"},baseCoin_locked:{type:"uint"},baseCoin_available:{type:"uint"},companyId:{type:"uint"},WLFeeShare:{type:"uint"},WLCustomFee:{type:"uint"},slotMap:{type:"uint"}},Ae=r=>{let e=new Map,t=0;for(let[i,n]of Object.entries(vt)){if(t>=r.length)throw new Error("Array index out of bounds");let s;switch(n.type){case"address":s=Ct(r.slice(t,t+32)),t+=32;break;case"bytes":s=r.slice(t,t+n.size),s=ye.decodeUint64(s,"mixed"),t+=n.size;break;case"uint":s=ye.decodeUint64(r.slice(t,t+8),"mixed"),t+=8;break;case"string":s=Pt(r.slice(t,t+n.size)),t+=n.size;break}e.set(i,s)}return Object.fromEntries(e)},Pt=r=>o.from(r).toString("utf-8");var F=class{client;authCredentials;indexerDomain;constructor(e,t,i){this.client=e,this.authCredentials=t,this.indexerDomain=i}isAppOptedIn(e,t){return!!e?.find(i=>i.id===t)}isAssetOptedIn(e,t){return Object.keys(e).includes(t.toString())}async optInAsset(e,t){let i=await this.getTxnParams();return D.makeAssetTransferTxnWithSuggestedParamsFromObject({suggestedParams:{...i},from:e,to:e,assetIndex:t,amount:0})}async makeAppCallTransaction(e,t,i,n,s){let a=[],c=[],l=[e];return D.makeApplicationNoOpTxn(t,s||await this.getTxnParams(),i,n,a,c,l)}makeTransferTransaction(e,t,i,n,s){if(i<=0)return null;let a={suggestedParams:{...e},from:n,to:s,amount:i};return t===0?D.makePaymentTxnWithSuggestedParamsFromObject(a):(a.assetIndex=t,D.makeAssetTransferTxnWithSuggestedParamsFromObject(a))}get signer(){return this.authCredentials.signer}set signer(e){this.authCredentials.signer=e}async signAndSend(e){Array.isArray(e)||(e=[e]);let t=this.getCurrentAccount();if(t){let i=e.map(n=>n.signTxn(t.sk));return this.client.sendRawTransaction(i).do()}return this.authCredentials.signer.signAndSend(e)}async signAndSendData(e,t,i,n){let s=typeof e=="string"?e:JSON.stringify(e),a=typeof e=="string"?{message:s}:{...e},c=await t(s,n);return i({...a,signature:c})}async getTxnParams(){return await Wt(this.client)}getCurrentAccount(){return this.authCredentials.mnemonic?D.mnemonicToSecretKey(this.authCredentials.mnemonic):null}async getAccountInfo(e){return this.client.accountInformation(e).do()}constructArgsForAppCall(...e){let t=[];return e.forEach(i=>{t.push(new Uint8Array(i.toBuffer?i.toBuffer():o.from(i.toString())))}),t}validateCredentials(){if(!this.authCredentials.mnemonic&&!this.authCredentials.signer)throw"You need specify mnemonic or signer to execute the method"}async getAppState(e){try{let t=await this.client.getApplicationByID(e).do();return St(t.params["global-state"])}catch(t){console.log(`Attempt to load app by id ${e}`),console.log(t.message)}}async getSuperAppId(e){return(await this.getAppState(e))?.UL_SUPERADMIN_APP||0}async getPairBalances(e,t){let{data:i}=await Ut.get(`${this.indexerDomain}/v2/accounts/${t}?include-all=true`);if(i.account.hasOwnProperty("apps-local-state")){let n=i.account["apps-local-state"].find(c=>c.id===e&&c.deleted===!1);if(!n)return null;let s=n["key-value"].find(c=>c.key==="YWNjb3VudEluZm8="),a=o.from(s.value.bytes,"base64");return Ae(a)}}async calculateTransferAmount(e,t,i,n,s,a){let c=await this.getPairBalances(e,t),l=(i==="B"?c?.priceCoin_available:c?.baseCoin_available)??0;i==="B"&&(n=n/10**a*s);let u=Math.ceil(n-l);return u<0?0:u}};var z=[5,8,10,11];import Dt from"react-secure-storage";var Rt=new URL(window.location!==window.parent.location?document.referrer:document.location.href).host,be=r=>`${r}_${Rt}`,Bt=new Proxy(Dt,{get(r,e,t){return typeof e=="string"&&typeof r[e]=="function"?function(...i){return typeof e=="string"&&["setItem","getItem","removeItem"].includes(e)&&(i[0]=be(i[0])),r[e].apply(r,i)}:Reflect.get(r,e,t)}}),H=new Proxy(localStorage,{get(r,e,t){return typeof e=="string"&&typeof r[e]=="function"?function(...i){return typeof e=="string"&&["setItem","getItem","removeItem","key"].includes(e)&&(i[0]=be(i[0])),r[e].apply(r,i)}:Reflect.get(r,e,t)}}),K=class{isBrowser;keys={mainWallet:"main-wallet",tradingKey:"trading-key"};constructor(){this.isBrowser=typeof window<"u",this.isBrowser||(this.clearMainWallet=()=>{},this.getMainWallet=()=>null,this.setMainWallet=()=>{})}setMainWallet(e){H.setItem(this.keys.mainWallet,JSON.stringify(e))}getMainWallet(){let e=H.getItem(this.keys.mainWallet);if(!e)return null;let t=JSON.parse(e),i=Bt.getItem(`${this.keys.tradingKey}-${t.address}`);return i&&(i.expiredAt===0||Number(new Date(i.expiredAt))-Date.now()>1)&&(t.tradingKey=i.address),t}clearMainWallet(){H.removeItem(this.keys.mainWallet)}};import{TradingKeyType as Kt}from"@ultrade/shared/interfaces";import{PROVIDERS as v}from"@ultrade/shared/interfaces";import{OrderStatus as R}from"@ultrade/shared/enums";import{makeDtwMsg as qt,makeTransferMsg as Vt}from"@ultrade/shared/helpers/codex/index";var Xt="By signing this message you are logging into your trading account and agreeing to all terms and conditions of the platform.",Ie=class{client;algodNode;algodIndexer;apiUrl;companyId;websocketUrl;wallet;_axios;localStorageService;isUltradeID;socketManager;constructor(e,t){e.network==="mainnet"?(this.algodNode="https://mainnet-api.algonode.cloud",this.apiUrl="https://mainnet-api.algonode.cloud",this.algodIndexer="https://mainnet-idx.algonode.cloud"):e.network==="testnet"?(this.apiUrl="https://testnet-apigw.ultradedev.net",this.algodNode="https://testnet-api.algonode.cloud",this.algodIndexer="https://testnet-idx.algonode.cloud"):(this.apiUrl="http://localhost:5001",this.algodNode="http://localhost:4001",this.algodIndexer="http://localhost:8980"),e.apiUrl!==void 0&&(this.apiUrl=e.apiUrl),e.companyId!==void 0&&(this.companyId=e.companyId),this.websocketUrl=e.websocketUrl,this.client=new F(e.algoSdkClient,t||{},this.algodIndexer),this._axios=this.axiosInterceptor(Mt.create({baseURL:this.apiUrl})),this.localStorageService=new K,this.wallet=this.localStorageService.getMainWallet(),this.isUltradeID=!1,this.socketManager=new U(this.websocketUrl,e.socketIO,i=>{console.log(`Socket ${i} disconnected at`,new Date)},i=>{console.log(`Socket connect_error due to ${i}`)}),console.log("SDK Wallet",this.wallet)}axiosInterceptor=e=>{let t=["/market/balances","/market/order","/market/orders","/market/account/kyc/status","/market/account/kyc/init","/market/withdrawal-fee","/market/operation-details","/wallet/key","/wallet/transactions","/wallet/transfer","/wallet/withdraw","/wallet/whitelist","/wallet/withdrawal-wallets"],i=l=>l.withWalletCredentials||t.some(u=>l.url.includes(u)),n=l=>{let u=["/market/order"];return l.withWalletCredentials||u.some(h=>l.url.includes(h))},s=l=>["/wallet/signin","/market/account/kyc/init","/notifications"].some(h=>l.url.includes(h)),a=l=>["/social/"].some(h=>l.url.includes(h)),c=l=>t.some(u=>l.url.includes(u));return e.interceptors.request.use(l=>{if(this.wallet&&i(l)&&(l.headers["X-Wallet-Address"]=this.wallet.address,l.headers["X-Wallet-Token"]=this.wallet.token),this.wallet&&c(l)&&(l.headers.CompanyId=this.companyId),this.wallet&&n(l)){let u=this.wallet?.tradingKey;u&&(l.headers["X-Trading-Key"]=u)}return s(l)&&(l.headers.CompanyId=this.companyId),a(l)&&!l.headers.CompanyId&&(l.headers.CompanyId=this.isUltradeID?1:this.companyId),l},l=>Promise.reject(l)),e.interceptors.response.use(l=>l.data,async l=>(console.log("Request was failed",l),[401].includes(l?.response?.status)&&i(l.config)&&(this.wallet=null,this.localStorageService.clearMainWallet()),Promise.reject(l))),e};get useUltradeID(){return this.isUltradeID}set useUltradeID(e){this.isUltradeID=e}get isLogged(){return!!this.wallet?.token}get mainWallet(){return this.wallet}set mainWallet(e){this.wallet=e,e?this.localStorageService.setMainWallet(e):this.localStorageService.clearMainWallet()}setSigner(e){this.client.signer=e}subscribe(e,t){let i=e.streams.some(n=>z.includes(n));return i&&!this.mainWallet?.token&&!this.mainWallet?.tradingKey?(e.streams=e.streams.filter(n=>!z.includes(n)),this.socketManager.subscribe(e,t)):i?(e.options={...e.options,token:this.mainWallet?.token,tradingKey:this.mainWallet?.tradingKey},this.socketManager.subscribe(e,t)):this.socketManager.subscribe(e,t)}unsubscribe(e){this.socketManager.unsubscribe(e)}getPairList(e){let t=e?`&companyId=${e}`:"";return this._axios.get(`/market/markets?includeAllOrders=false${t}`)}getExchangeInfo(e){return this._axios.get(`/market/market?symbol=${e}`)}getPrice(e){return this._axios.get(`/market/price?symbol=${e}`)}getDepth(e,t){return this._axios.get(`/market/depth?symbol=${e}&depth=${t}`)}getSymbols(e){return this._axios.get(`/market/symbols${e?"?mask="+e:""}`)}getLastTrades(e){return this._axios.get(`/market/last-trades?symbol=${e}`)}getHistory(e,t,i,n,s=500,a=1){return this._axios.get(`/market/history?symbol=${e}&interval=${t}&startTime=${i??""}&endTime=${n??""}&limit=${s}&page=${a}`)}getOrders(e,t,i=50,n,s){let a=t?t===1?R.Open:[R.Canceled,R.Matched,R.SelfMatched,R.Expired].join(","):"",c=e?`&symbol=${e}`:"",l=a?`&status=${a}`:"",u=s?`&startTime=${s}`:"",h=n?`&endTime=${n}`:"";return this._axios.get(`/market/orders?limit=${i}${c}${l}${u}${h}`)}getOrderById(e){return this._axios.get(`/market/order/${e}`)}getSettings(){let e=new URL(window.location!==window.parent.location?document.referrer:document.location.href).host;return this._axios.get("/market/settings",{headers:{"wl-domain":e}})}getBalances(){return this._axios.get("/market/balances")}getChains(){return this._axios.get("/market/chains")}getCodexAssets(){return this._axios.get("/market/assets")}getCCTPAssets(){return this._axios.get("/market/cctp-assets")}getCCTPUnifiedAssets(){return this._axios.get("/market/cctp-unified-assets")}getWithdrawalFee(e,t){return this._axios.get(`/market/withdrawal-fee?assetAddress=${e}&chainId=${t}`)}getKycStatus(){return this._axios.get("/market/account/kyc/status")}getKycInitLink(e){return this._axios.post("/market/account/kyc/init",{embeddedAppUrl:e})}getDollarValues(e=[]){return this._axios.get(`/market/dollar-price?assetIds=${JSON.stringify(e)}`)}getTransactionDetalis(e){return this._axios.get(`/market/operation-details?operationId=${e}`)}getWalletTransactions(e,t,i=100){return this._axios.get(`/wallet/transactions?type=${e}&limit=${i}&page=${t}`,{withWalletCredentials:!0})}getTradingKeys(){return this._axios.get("/wallet/keys",{withWalletCredentials:!0})}getTransfers(e,t=100){return this._axios.get(`/wallet/transfers?limit=${t}&page=${e}`,{withWalletCredentials:!0})}getPendingTransactions(){return this._axios.get("/wallet/transactions/pending",{withWalletCredentials:!0})}getWhitelist(){return this._axios.get("/wallet/whitelist",{withWalletCredentials:!0})}addWhitelist(e){e={...e,expiredDate:e.expiredDate&&Math.round(e.expiredDate/1e3)};let i=o.from(qt(e)).toString("hex");return this.client.signAndSendData(i,this.client.signer.signMessage,({signature:n})=>this._axios.post("/wallet/whitelist",{message:i,signature:n}),"hex")}deleteWhitelist(e){let t={whitelistId:e};return this.client.signAndSendData(t,this.client.signer.signMessage,({signature:i})=>this._axios.delete("/wallet/whitelist",{data:{data:t,signature:i}}))}getAllWithdrawalWallets(){return this._axios.get("/wallet/withdrawal-wallets")}getWithdrawalWalletByAddress(e){return this._axios.get(`/wallet/withdrawal-wallets/${e}`)}createWithdrawalWallet(e){return this._axios.post("/wallet/withdrawal-wallets",e)}updateWithdrawalWallet(e){return this._axios.patch("/wallet/withdrawal-wallets",e)}deleteWithdrawalWallet(e){return this._axios.delete(`/wallet/withdrawal-wallets/${e}`)}getVersion(){return this._axios.get("/system/version")}getMaintenance(){return this._axios.get("/system/maintenance")}getNotifications(){return this._axios.get("/notifications",{withWalletCredentials:!0})}getNotificationsUnreadCount(){return this._axios.get("/notifications/count",{withWalletCredentials:!0})}readNotifications(e){return this._axios.put("/notifications",{notifications:e},{withWalletCredentials:!0})}getAffiliatesStatus(e){return this._axios.get(`/affiliates/${e}/dashboardStatus`,{withWalletCredentials:!0})}createAffiliate(e){return this._axios.post(`/affiliates/${e}`,{},{withWalletCredentials:!0})}getAffiliateProgress(e){return this._axios.get(`/affiliates/${e}/tradingVolumeProgress`,{withWalletCredentials:!0})}getAffiliateInfo(e,t){return this._axios.get(`/affiliates/${e}/dashboard?range=${t}`,{withWalletCredentials:!0})}countAffiliateDepost(e){return this._axios.post(`/affiliates/${e}/deposit `,{},{withWalletCredentials:!0})}countAffiliateClick(e){return this._axios.post("/affiliates/click",{referralToken:e},{withWalletCredentials:!0})}getSocialAccount(){return this._axios.get("/social/account",{withWalletCredentials:!0})}addSocialEmail(e,t){return this._axios.put("/social/account/email",{email:e,embeddedAppUrl:t},{withWalletCredentials:!0})}verifySocialEmail(e,t){return this._axios.put("/social/account/verifyEmail",{email:e,hash:t},{withWalletCredentials:!0})}getLeaderboards(){return this._axios.get("/social/leaderboard",{withWalletCredentials:!0})}getUnlocks(){return this._axios.get("/social/unlocks",{withWalletCredentials:!0})}getSocialSettings(){return this._axios.get("/social/settings",{withWalletCredentials:!0})}getSeason(e){return this._axios.get("/social/seasons/active",{withWalletCredentials:!0,headers:{CompanyId:e}})}getPastSeasons(){return this._axios.get("/social/seasons/history",{withWalletCredentials:!0})}addTelegram(e){return this._axios.post("/social/telegram/connect",e,{withWalletCredentials:!0})}disconnectTelegram(e){return this._axios.put("/social/telegram/disconnect",e,{withWalletCredentials:!0})}getDiscordConnectionUrl(e){let t=e?`?embeddedAppUrl=${encodeURIComponent(e)}`:"";return this._axios.get(`/social/discord/connect${t}`,{withWalletCredentials:!0}).then(({url:i})=>i)}disconnectDiscord(){return this._axios.put("/social/discord/disconnect",{},{withWalletCredentials:!0})}getTwitterConnectionUrl(e,t){let i=e?`?embeddedAppUrl=${encodeURIComponent(e)}`:"",n=t?`&scopes=${t}`:"";return this._axios.get(`/social/twitter/connect${i}${n}`,{withWalletCredentials:!0}).then(({url:s})=>s)}disconnectTwitter(){return this._axios.put("/social/twitter/disconnect",{},{withWalletCredentials:!0})}getTweets(){return this._axios.get("/social/twitter/tweets",{withWalletCredentials:!0})}actionWithTweet(e){return this._axios.post("/social/twitter/tweet/actions",e,{withWalletCredentials:!0})}async getActions(){return this._axios.get("/social/actions",{withWalletCredentials:!0})}async getActionHistory(){return this._axios.get("/social/actions/history",{withWalletCredentials:!0})}getAIStyles(){return this._axios.get("/social/twitter/tweets/styles",{withWalletCredentials:!0})}getAIComment(e,t){return this._axios.get(`/social/twitter/tweets/${t}/generateComment?styleId=${e}`,{withWalletCredentials:!0})}getTechnologyByProvider(e){switch(e){case v.PERA:return"ALGORAND";case v.METAMASK:return"EVM";case v.SOLFLARE:case v.COINBASE:case v.PHANTOM:case v.BACKPACK:case v.MOBILE:return"SOLANA";default:throw new Error("Not implemented")}}login({address:e,provider:t,chain:i,referralToken:n,loginMessage:s}){let c=s||Xt,l={address:e,technology:this.getTechnologyByProvider(t)},u=o.from($t(l,c)).toString("hex");return this.client.signAndSendData(u,this.client.signer.signMessage,({signature:h})=>this._axios.put("/wallet/signin",{data:l,message:u,encoding:"hex",signature:h,referralToken:n}).then(f=>(this.mainWallet={address:e,provider:t,token:f,chain:i},f)),"hex")}addTradingKey(e){let i=o.from(ke(e,!0)).toString("hex"),{device:n,type:s}=e;return this.client.signAndSendData(i,this.client.signer.signMessage,({signature:a})=>this._axios.post("/wallet/key",{data:{device:n,type:s},encoding:"hex",message:i,signature:a}).then(c=>(this.mainWallet&&c.type===Kt.User&&(this.mainWallet.tradingKey=c.address),c)),"hex")}revokeTradingKey(e){let i=o.from(ke(e,!1)).toString("hex"),{device:n,type:s}=e;return this.client.signAndSendData(i,this.client.signer.signMessage,({signature:a})=>this._axios.delete("/wallet/key",{data:{data:{device:n,type:s},encoding:"hex",message:i,signature:a}}).then(()=>{this.mainWallet&&e.tkAddress===this.mainWallet.tradingKey&&(this.mainWallet.tradingKey=void 0)}),"hex")}withdraw(e,t){let n={...e,random:J(1,Number.MAX_SAFE_INTEGER)},s=o.from(Ft(n,t)).toString("hex");return this.client.signAndSendData(s,this.client.signer.signMessage,({signature:a})=>this._axios.post("/wallet/withdraw",{encoding:"hex",message:s,signature:a,destinationAddress:n.recipient}),"hex")}transfer(e){let i={...e,random:J(1,Number.MAX_SAFE_INTEGER)},n=o.from(Vt(i)).toString("hex");return this.client.signAndSendData(n,this.client.signer.signMessage,({signature:s})=>this._axios.post("/wallet/transfer",{message:n,signature:s}),"hex")}async createOrder(e){let t=Nt*24*60*60,i=Math.floor(Date.now()/1e3)+t,n={...e,version:Lt,expiredTime:i,random:J(1,Number.MAX_SAFE_INTEGER)};console.log("CreateOrderData",n);let s="hex",a=o.from(Yt(n)).toString(s);return await this.client.signAndSendData(a,this.client.signer.signMessageByToken,({signature:c})=>this._axios.post("/market/order",{encoding:s,message:a,signature:c}),s)}async cancelOrder(e){let t={orderId:e.orderId},i="hex",n=o.from(Ot(e)).toString(i);return this.client.signAndSendData(n,this.client.signer.signMessageByToken,({signature:s})=>this._axios.delete("/market/order",{data:{data:t,message:n,signature:s}}),i)}async cancelMultipleOrders({orderIds:e,pairId:t}){let i={orderIds:e,pairId:t};return this.client.signAndSendData(i,this.client.signer.signMessageByToken,({signature:n})=>this._axios.delete("/market/orders",{data:{data:i,signature:n}}))}async ping(){let e=this._axios.get("/system/time");return Math.round(Date.now()-e.currentTime)}};export{Ie as Client,U as SocketManager};
2
+ /*! Bundled license information:
3
+
4
+ @esbuild-plugins/node-globals-polyfill/Buffer.js:
5
+ (*!
6
+ * The buffer module from node.js, for the browser.
7
+ *
8
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
9
+ * @license MIT
10
+ *)
11
+ */