@rabby-wallet/rabby-api 0.6.14-alpha.0 → 0.6.15-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,722 +1,688 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import axios from 'axios';
11
- import rateLimit from 'axios-rate-limit';
12
- import { ethErrors } from 'eth-rpc-errors';
13
- import { getChain, INITIAL_OPENAPI_URL, CHAINS, SIGN_HDS, genSignParams, } from './utils';
14
- import * as sign from '@rabby-wallet/rabby-sign/umd/sign-wasm-rabby';
15
- const maxRPS = 500;
16
- export class OpenApiService {
17
- constructor({ store, adapter }) {
18
- this.setHost = (host) => __awaiter(this, void 0, void 0, function* () {
19
- var _a, _b, _c, _d;
20
- this.store.host = host;
21
- let hf =
22
- // @ts-expect-error
23
- ((_b = (_a = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _a === void 0 ? void 0 : _a.getURL) === null || _b === void 0 ? void 0 : _b.call(_a, 'bridge.html')) ||
24
- (
25
- // @ts-expect-error
26
- (_d = (_c = chrome === null || chrome === void 0 ? void 0 : chrome.extension) === null || _c === void 0 ? void 0 : _c.getURL) === null || _d === void 0 ? void 0 : _d.call(_c, 'bridge.html')) ||
27
- '';
28
- yield this.init(hf);
29
- });
30
- this.getHost = () => {
31
- return this.store.host;
32
- };
33
- this.ethRpc = () => __awaiter(this, void 0, void 0, function* () {
34
- throw ethErrors.provider.disconnected();
35
- });
36
- this.init = (hf) => __awaiter(this, void 0, void 0, function* () {
37
- var _e;
38
- yield sign.lW(hf);
39
- if (!process.env.DEBUG) {
40
- this.store.host = INITIAL_OPENAPI_URL;
41
- }
42
- const request = axios.create({
43
- baseURL: this.store.host,
44
- adapter: this.adapter,
45
- headers: {
46
- 'X-Client': 'Rabby',
47
- 'X-Version': (_e = process.env.release) !== null && _e !== void 0 ? _e : '0.0.0',
48
- },
49
- });
50
- // sign after rateLimit, timestamp is the latest
51
- request.interceptors.request.use((config) => {
52
- const { method, url, params } = genSignParams(config);
53
- const res = sign.cattleGsW(params, method, url);
54
- config.headers = config.headers || {};
55
- config.headers[SIGN_HDS[0]] = encodeURIComponent(res.ts);
56
- config.headers[SIGN_HDS[1]] = encodeURIComponent(res.nonce);
57
- config.headers[SIGN_HDS[2]] = encodeURIComponent(res.version);
58
- config.headers[SIGN_HDS[3]] = encodeURIComponent(res.signature);
59
- return config;
60
- });
61
- this.request = rateLimit(request, { maxRPS });
62
- this.request.interceptors.response.use((response) => {
63
- var _a, _b, _c, _d;
64
- const code = ((_a = response.data) === null || _a === void 0 ? void 0 : _a.err_code) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.error_code);
65
- const msg = ((_c = response.data) === null || _c === void 0 ? void 0 : _c.err_msg) || ((_d = response.data) === null || _d === void 0 ? void 0 : _d.error_msg);
66
- if (code && code !== 200) {
67
- if (msg) {
68
- let err;
69
- try {
70
- err = new Error(JSON.parse(msg));
71
- }
72
- catch (e) {
73
- err = new Error(msg);
74
- }
75
- throw err;
76
- }
77
- throw new Error(response.data);
78
- }
79
- return response;
80
- });
81
- this._mountMethods();
82
- });
83
- this._mountMethods = () => {
84
- this.ethRpc = (chain_id, { origin = 'rabby', method, params }) => {
85
- return this.request
86
- .post(`/v1/wallet/eth_rpc?origin=${origin}&method=${method}`, {
87
- chain_id,
88
- method,
89
- params,
90
- })
91
- .then(({ data }) => {
92
- if (data === null || data === void 0 ? void 0 : data.error) {
93
- throw data.error;
94
- }
95
- return data === null || data === void 0 ? void 0 : data.result;
96
- });
97
- };
98
- };
99
- this.getRecommendChains = (address, origin) => __awaiter(this, void 0, void 0, function* () {
100
- const { data } = yield this.request.get('/v1/wallet/recommend_chains', {
101
- params: {
102
- user_addr: address,
103
- origin,
104
- },
105
- });
106
- return data;
107
- });
108
- this.getTotalBalance = (address) => __awaiter(this, void 0, void 0, function* () {
109
- const { data } = yield this.request.get('/v1/user/total_balance', {
110
- params: {
111
- id: address,
112
- },
113
- });
114
- return Object.assign(Object.assign({}, data), { chain_list: data.chain_list.filter((item) => !!Object.values(CHAINS).find((chain) => chain.serverId === item.id)) });
115
- });
116
- this.getPendingCount = (address) => __awaiter(this, void 0, void 0, function* () {
117
- const { data } = yield this.request.get('/v1/wallet/pending_tx_count', {
118
- params: {
119
- user_addr: address,
120
- },
121
- });
122
- return data;
123
- });
124
- this.checkOrigin = (address, origin) => __awaiter(this, void 0, void 0, function* () {
125
- const { data } = yield this.request.post('/v1/wallet/check_origin', {
126
- user_addr: address,
127
- origin,
128
- });
129
- return data;
130
- });
131
- this.checkText = (address, origin, text) => __awaiter(this, void 0, void 0, function* () {
132
- const { data } = yield this.request.post('/v1/wallet/check_text', {
133
- user_addr: address,
134
- origin,
135
- text,
136
- });
137
- return data;
138
- });
139
- this.checkTx = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
140
- const { data } = yield this.request.post('/v1/wallet/check_tx', {
141
- user_addr: address,
142
- origin,
143
- tx,
144
- update_nonce,
145
- });
146
- return data;
147
- });
148
- this.preExecTx = ({ tx, origin, address, updateNonce = false, pending_tx_list = [], }) => __awaiter(this, void 0, void 0, function* () {
149
- const { data } = yield this.request.post('/v1/wallet/pre_exec_tx', {
150
- tx,
151
- user_addr: address,
152
- origin,
153
- update_nonce: updateNonce,
154
- pending_tx_list,
155
- });
156
- return data;
157
- });
158
- this.historyGasUsed = (params) => __awaiter(this, void 0, void 0, function* () {
159
- const { data } = yield this.request.post('/v1/wallet/history_tx_used_gas', Object.assign({}, params));
160
- return data;
161
- });
162
- this.pendingTxList = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
163
- const { data } = yield this.request.post('/v1/wallet/pending_tx_list', {
164
- tx,
165
- user_addr: address,
166
- origin,
167
- update_nonce,
168
- });
169
- return data;
170
- });
171
- this.traceTx = (txId, traceId, chainId) => __awaiter(this, void 0, void 0, function* () {
172
- const { data } = yield this.request.post('/v1/wallet/trace_tx', {
173
- tx_id: txId,
174
- trace_id: traceId,
175
- chain_id: chainId,
176
- });
177
- return data;
178
- });
179
- this.pushTx = (tx, traceId) => __awaiter(this, void 0, void 0, function* () {
180
- const { data } = yield this.request.post('/v1/wallet/push_tx', {
181
- tx,
182
- trace_id: traceId,
183
- });
184
- return data;
185
- });
186
- this.explainText = (origin, address, text) => __awaiter(this, void 0, void 0, function* () {
187
- const { data } = yield this.request.post('/v1/wallet/explain_text', {
188
- user_addr: address,
189
- origin,
190
- text,
191
- });
192
- return data;
193
- });
194
- this.gasMarket = (chainId, customGas) => __awaiter(this, void 0, void 0, function* () {
195
- const { data } = yield this.request.get('/v1/wallet/gas_market', {
196
- params: {
197
- chain_id: chainId,
198
- custom_price: customGas,
199
- },
200
- });
201
- return data;
202
- });
203
- this.getTx = (chainId, hash, gasPrice) => __awaiter(this, void 0, void 0, function* () {
204
- const { data } = yield this.request.get('/v1/wallet/get_tx', {
205
- params: {
206
- chain_id: chainId,
207
- gas_price: gasPrice,
208
- tx_id: hash,
209
- },
210
- });
211
- return data;
212
- });
213
- this.getEnsAddressByName = (name) => __awaiter(this, void 0, void 0, function* () {
214
- const { data } = yield this.request.get('/v1/wallet/ens', {
215
- params: {
216
- text: name,
217
- },
218
- });
219
- return data;
220
- });
221
- this.searchToken = (id, q, chainId, is_all = false) => __awaiter(this, void 0, void 0, function* () {
222
- const { data } = yield this.request.get('/v1/user/token_search', {
223
- params: {
224
- id,
225
- q,
226
- has_balance: false,
227
- is_all,
228
- chain_id: chainId,
229
- },
230
- });
231
- return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
232
- });
233
- this.searchSwapToken = (id, chainId, q, is_all = false) => __awaiter(this, void 0, void 0, function* () {
234
- const { data } = yield this.request.get('/v1/user/token_search', {
235
- params: {
236
- id,
237
- chain_id: chainId,
238
- q,
239
- is_all,
240
- },
241
- });
242
- return data;
243
- });
244
- this.getToken = (id, chainId, tokenId) => __awaiter(this, void 0, void 0, function* () {
245
- const { data } = yield this.request.get('/v1/user/token', {
246
- params: {
247
- id,
248
- chain_id: chainId,
249
- token_id: tokenId,
250
- },
251
- });
252
- return data;
253
- });
254
- this.getCachedTokenList = (id) => __awaiter(this, void 0, void 0, function* () {
255
- const { data } = yield this.request.get('/v1/user/cache_token_list', {
256
- params: {
257
- id,
258
- },
259
- });
260
- return data;
261
- });
262
- this.listToken = (id, chainId, isAll = false) => __awaiter(this, void 0, void 0, function* () {
263
- const { data } = yield this.request.get('/v1/user/token_list', {
264
- params: {
265
- id,
266
- is_all: isAll,
267
- chain_id: chainId,
268
- },
269
- });
270
- return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
271
- });
272
- this.getHistoryTokenList = (params) => __awaiter(this, void 0, void 0, function* () {
273
- const { data } = yield this.request.get('/v1/user/history_token_list', {
274
- params: {
275
- id: params.id,
276
- chain_id: params.chainId,
277
- time_at: params.timeAt,
278
- date_at: params.dateAt,
279
- },
280
- });
281
- return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
282
- });
283
- this.customListToken = (uuids, id) => __awaiter(this, void 0, void 0, function* () {
284
- const { data } = yield this.request.post('/v1/user/specific_token_list', {
285
- id,
286
- uuids,
287
- });
288
- return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
289
- });
290
- this.listChainAssets = (id) => __awaiter(this, void 0, void 0, function* () {
291
- const { data } = yield this.request.get('/v1/user/simple_protocol_list', {
292
- params: {
293
- id,
294
- },
295
- });
296
- return data;
297
- });
298
- this.listNFT = (id, isAll = true) => __awaiter(this, void 0, void 0, function* () {
299
- const { data } = yield this.request.get('/v1/user/nft_list', {
300
- params: {
301
- id,
302
- is_all: isAll,
303
- },
304
- });
305
- return data === null || data === void 0 ? void 0 : data.filter((nft) => getChain(nft.chain));
306
- });
307
- this.listCollection = (params) => __awaiter(this, void 0, void 0, function* () {
308
- const { data } = yield this.request.get('/v1/nft/collections', {
309
- params,
310
- });
311
- return data;
312
- });
313
- this.listTxHisotry = (params) => __awaiter(this, void 0, void 0, function* () {
314
- const { data } = yield this.request.get('/v1/user/history_list', {
315
- params,
316
- });
317
- return data;
318
- });
319
- this.tokenPrice = (tokenName) => __awaiter(this, void 0, void 0, function* () {
320
- const { data } = yield this.request.get('/v1/token/price_change', {
321
- params: {
322
- token: tokenName,
323
- },
324
- });
325
- return data;
326
- });
327
- this.tokenAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
328
- const { data } = yield this.request.get('/v1/user/token_authorized_list', {
329
- params: {
330
- id,
331
- chain_id,
332
- },
333
- });
334
- return data;
335
- });
336
- this.userNFTAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
337
- const { data } = yield this.request.get('/v1/user/nft_authorized_list', {
338
- params: {
339
- id,
340
- chain_id,
341
- },
342
- });
343
- return data;
344
- });
345
- this.getDEXList = (chain_id) => __awaiter(this, void 0, void 0, function* () {
346
- const { data } = yield this.request.get('/v1/wallet/swap_dex_list', {
347
- params: {
348
- chain_id,
349
- },
350
- });
351
- return data;
352
- });
353
- this.getSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
354
- const { data } = yield this.request.get('/v1/wallet/swap_quote', {
355
- params,
356
- });
357
- return data;
358
- });
359
- this.getSwapTokenList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
360
- const { data } = yield this.request.get('/v1/wallet/swap_token_list', {
361
- params: {
362
- id,
363
- chain_id: chainId,
364
- is_all: false,
365
- },
366
- });
367
- return data;
368
- });
369
- this.postGasStationOrder = (params) => __awaiter(this, void 0, void 0, function* () {
370
- const { data } = yield this.request.post('/v1/wallet/gas_station_order', {
371
- order: {
372
- user_addr: params.userAddr,
373
- from_chain_id: params.fromChainId,
374
- from_tx_id: params.fromTxId,
375
- from_token_id: params.fromTokenId,
376
- from_token_amount: params.fromTokenAmount,
377
- to_chain_id: params.toChainId,
378
- to_token_amount: params.toTokenAmount,
379
- from_usd_value: params.fromUsdValue,
380
- },
381
- });
382
- return data;
383
- });
384
- this.getGasStationChainBalance = (chain_id, addr) => __awaiter(this, void 0, void 0, function* () {
385
- const { data } = yield this.request.get('/v1/wallet/gas_station_usd_value', {
386
- params: {
387
- chain_id,
388
- addr,
389
- },
390
- });
391
- return data;
392
- });
393
- this.getGasStationTokenList = () => __awaiter(this, void 0, void 0, function* () {
394
- const { data } = yield this.request.get('/v1/wallet/gas_station_token_list');
395
- return data;
396
- });
397
- this.explainTypedData = (user_addr, origin, data) => __awaiter(this, void 0, void 0, function* () {
398
- const { data: resData } = yield this.request.post('/v1/wallet/explain_typed_data', {
399
- user_addr,
400
- origin,
401
- data,
402
- });
403
- return resData;
404
- });
405
- this.checkTypedData = (user_addr, origin, data) => __awaiter(this, void 0, void 0, function* () {
406
- const { data: resData } = yield this.request.post('/v1/wallet/check_typed_data', {
407
- user_addr,
408
- origin,
409
- data,
410
- });
411
- return resData;
412
- });
413
- this.approvalStatus = (id) => __awaiter(this, void 0, void 0, function* () {
414
- const { data } = yield this.request.get('/v1/user/approval_status', {
415
- params: {
416
- id,
417
- },
418
- });
419
- return data;
420
- });
421
- this.usedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
422
- const { data } = yield this.request.get('/v1/user/used_chain_list', {
423
- params: {
424
- id,
425
- },
426
- });
427
- return data;
428
- });
429
- this.getLatestVersion = () => __awaiter(this, void 0, void 0, function* () {
430
- const { data } = yield this.request.get('/v1/wallet/version');
431
- return data;
432
- });
433
- this.addOriginFeedback = (params) => __awaiter(this, void 0, void 0, function* () {
434
- const { data } = yield this.request.post('/v1/wallet/add_origin_feedback', {
435
- user_addr: params.user_addr,
436
- origin: params.origin,
437
- is_safe: params.is_safe,
438
- });
439
- return data;
440
- });
441
- this.getProtocolList = (addr) => __awaiter(this, void 0, void 0, function* () {
442
- const { data } = yield this.request.get('/v1/user/protocol_list', {
443
- params: {
444
- id: addr,
445
- },
446
- });
447
- return data;
448
- });
449
- this.getComplexProtocolList = (addr) => __awaiter(this, void 0, void 0, function* () {
450
- const { data } = yield this.request.get('/v1/user/complex_protocol_list', {
451
- params: {
452
- id: addr,
453
- },
454
- });
455
- return data;
456
- });
457
- this.getProtocol = ({ addr, id, }) => __awaiter(this, void 0, void 0, function* () {
458
- const { data } = yield this.request.get('/v1/user/protocol', {
459
- params: {
460
- id: addr,
461
- protocol_id: id,
462
- },
463
- });
464
- return data;
465
- });
466
- this.getHistoryProtocol = ({ addr, id, timeAt, dateAt, }) => __awaiter(this, void 0, void 0, function* () {
467
- const { data } = yield this.request.get('/v1/user/history_protocol', {
468
- params: {
469
- id: addr,
470
- protocol_id: id,
471
- time_at: timeAt,
472
- date_at: dateAt,
473
- },
474
- });
475
- return data;
476
- });
477
- this.getTokenHistoryPrice = ({ chainId, id, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
478
- const { data } = yield this.request.get('/v1/token/history_price', {
479
- params: {
480
- chain_id: chainId,
481
- id,
482
- time_at: timeAt,
483
- },
484
- });
485
- return data;
486
- });
487
- this.getTokenHistoryDict = ({ chainId, ids, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
488
- const { data } = yield this.request.get('/v1/token/history_price_dict', {
489
- params: {
490
- chain_id: chainId,
491
- ids,
492
- time_at: timeAt,
493
- },
494
- });
495
- return data;
496
- });
497
- this.getNetCurve = (addr) => __awaiter(this, void 0, void 0, function* () {
498
- const { data } = yield this.request.get('/v1/user/total_net_curve', {
499
- params: {
500
- id: addr,
501
- },
502
- });
503
- return data;
504
- });
505
- this.getChainList = () => __awaiter(this, void 0, void 0, function* () {
506
- const { data } = yield this.request.get('/v1/chain/list');
507
- return data;
508
- });
509
- this.getCEXSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
510
- const { data } = yield this.request.get('/v1/wallet/cex_swap_quote', {
511
- params,
512
- });
513
- return data;
514
- });
515
- this.getSwapTradeList = (params) => __awaiter(this, void 0, void 0, function* () {
516
- const { data } = yield this.request.get('/v1/wallet/swap_trade_list', {
517
- params,
518
- });
519
- return data;
520
- });
521
- this.postSwap = (params) => __awaiter(this, void 0, void 0, function* () {
522
- const { data } = yield this.request.post('/v1/wallet/swap_trade', params);
523
- return data;
524
- });
525
- this.checkSlippage = (params) => __awaiter(this, void 0, void 0, function* () {
526
- const { data } = yield this.request.get('/v1/wallet/check_slippage', {
527
- params,
528
- });
529
- return data;
530
- });
531
- this.getOriginPopularityLevel = (origin) => __awaiter(this, void 0, void 0, function* () {
532
- const { data } = yield this.request.get('/v1/engine/origin/popularity_level', {
533
- params: {
534
- origin,
535
- },
536
- });
537
- return data;
538
- });
539
- this.getOriginIsScam = (origin, source) => __awaiter(this, void 0, void 0, function* () {
540
- const { data } = yield this.request.get('/v1/engine/origin/is_scam', {
541
- params: {
542
- origin,
543
- source,
544
- },
545
- });
546
- return data;
547
- });
548
- this.getOriginThirdPartyCollectList = (origin) => __awaiter(this, void 0, void 0, function* () {
549
- const { data } = yield this.request.get('/v1/engine/origin/third_party_collect_list', {
550
- params: {
551
- origin,
552
- },
553
- });
554
- return data;
555
- });
556
- this.getSummarizedAssetList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
557
- const { data } = yield this.request.get('/v1/user/summarized_asset_list', {
558
- params: {
559
- id,
560
- chain_id,
561
- },
562
- });
563
- return data;
564
- });
565
- this.parseTx = ({ chainId, tx, origin, addr, }) => __awaiter(this, void 0, void 0, function* () {
566
- const { data } = yield this.request.post('/v1/engine/action/parse_tx', {
567
- chain_id: chainId,
568
- tx,
569
- origin,
570
- user_addr: addr,
571
- });
572
- return data;
573
- });
574
- this.isSuspiciousToken = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
575
- const { data } = yield this.request.get('/v1/engine/token/is_suspicious', {
576
- params: {
577
- chain_id: chainId,
578
- id,
579
- },
580
- });
581
- return data;
582
- });
583
- this.depositCexSupport = (id, chainId, cexId) => __awaiter(this, void 0, void 0, function* () {
584
- const { data } = yield this.request.get('/v1/engine/token/deposit_cex_support', {
585
- params: {
586
- chain_id: chainId,
587
- id,
588
- cex_id: cexId,
589
- },
590
- });
591
- return data;
592
- });
593
- // Token 可充值的 CEX 列表
594
- this.depositCexList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
595
- const { data } = yield this.request.get('/v1/engine/token/deposit_cex_list', {
596
- params: {
597
- chain_id: chainId,
598
- id,
599
- },
600
- });
601
- return data;
602
- });
603
- // 合约信用分
604
- this.getContractCredit = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
605
- const { data } = yield this.request.get('/v1/engine/contract/credit', {
606
- params: {
607
- chain_id: chainId,
608
- id,
609
- },
610
- });
611
- return data;
612
- });
613
- // 是否跟地址交互过
614
- this.hasInteraction = (addr, chainId, contractId) => __awaiter(this, void 0, void 0, function* () {
615
- const { data } = yield this.request.get('/v1/engine/contract/has_interaction', {
616
- params: {
617
- chain_id: chainId,
618
- user_addr: addr,
619
- contract_id: contractId,
620
- },
621
- });
622
- return data;
623
- });
624
- // 授权风险敞口
625
- this.tokenApproveExposure = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
626
- const { data } = yield this.request.get('/v1/engine/contract/token_approval_exposure', {
627
- params: {
628
- chain_id: chainId,
629
- id,
630
- },
631
- });
632
- return data;
633
- });
634
- // 地址描述
635
- this.addrDesc = (id) => __awaiter(this, void 0, void 0, function* () {
636
- const { data } = yield this.request.get('/v1/engine/addr/desc', {
637
- params: {
638
- id,
639
- },
640
- });
641
- return data;
642
- });
643
- // 两个地址是否发生过转账
644
- this.hasTransfer = (chainId, from, to) => __awaiter(this, void 0, void 0, function* () {
645
- const { data } = yield this.request.get('/v1/engine/addr/has_transfer', {
646
- params: {
647
- chain_id: chainId,
648
- from_addr: from,
649
- to_addr: to,
650
- },
651
- });
652
- return data;
653
- });
654
- this.isTokenContract = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
655
- const { data } = yield this.request.get('/v1/engine/contract/is_token', {
656
- params: {
657
- id,
658
- chain_id: chainId,
659
- },
660
- });
661
- return data;
662
- });
663
- this.addrUsedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
664
- const { data } = yield this.request.get('/v1/engine/addr/used_chain_list', {
665
- params: { id },
666
- });
667
- return data;
668
- });
669
- this.getTokenNFTExposure = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
670
- const { data } = yield this.request.get('/v1/engine/contract/top_nft_approval_exposure', {
671
- params: { chain_id: chainId, id },
672
- });
673
- return data;
674
- });
675
- this.getCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
676
- const { data } = yield this.request.get('/v1/engine/collection', {
677
- params: { chain_id: chainId, id },
678
- });
679
- return data;
680
- });
681
- this.isSuspiciousCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
682
- const { data } = yield this.request.get('/v1/engine/collection/is_suspicious', {
683
- params: { chain_id: chainId, id },
684
- });
685
- return data;
686
- });
687
- this.isOriginVerified = (origin) => __awaiter(this, void 0, void 0, function* () {
688
- const { data } = yield this.request.get('/v1/engine/origin/is_verified', {
689
- params: { origin },
690
- });
691
- return data;
692
- });
693
- this.parseTypedData = ({ typedData, origin, address, }) => __awaiter(this, void 0, void 0, function* () {
694
- const { data } = yield this.request.post('/v1/engine/action/parse_typed_data', {
695
- typed_data: typedData,
696
- origin,
697
- user_addr: address,
698
- });
699
- return data;
700
- });
701
- this.parseText = ({ text, origin, address, }) => __awaiter(this, void 0, void 0, function* () {
702
- const { data } = yield this.request.post('/v1/engine/action/parse_text', {
703
- text,
704
- origin,
705
- user_addr: address,
706
- });
707
- return data;
708
- });
709
- this.collectionList = ({ id, chainId, isAll, }) => __awaiter(this, void 0, void 0, function* () {
710
- const { data } = yield this.request.get('/v1/user/collection_list', {
711
- params: {
712
- id,
713
- chain_id: chainId,
714
- is_all: isAll,
715
- },
716
- });
717
- return data;
718
- });
719
- this.store = store;
720
- this.adapter = adapter;
721
- }
722
- }
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import axios from 'axios';
11
+ import rateLimit from 'axios-rate-limit';
12
+ import { ethErrors } from 'eth-rpc-errors';
13
+ import { getChain, INITIAL_OPENAPI_URL, CHAINS, SIGN_HDS, genSignParams, INITIAL_TESTNET_OPENAPI_URL, } from './utils';
14
+ import * as sign from '@rabby-wallet/rabby-sign/umd/sign-wasm-rabby';
15
+ import { TESTNET_CHAINS_LIST } from '@debank/common';
16
+ const maxRPS = 500;
17
+ export class OpenApiService {
18
+ constructor({ store, adapter }) {
19
+ this.setHost = (host) => __awaiter(this, void 0, void 0, function* () {
20
+ var _a, _b, _c, _d;
21
+ this.store.host = host;
22
+ let hf =
23
+ // @ts-expect-error
24
+ ((_b = (_a = chrome === null || chrome === void 0 ? void 0 : chrome.runtime) === null || _a === void 0 ? void 0 : _a.getURL) === null || _b === void 0 ? void 0 : _b.call(_a, 'bridge.html')) ||
25
+ (
26
+ // @ts-expect-error
27
+ (_d = (_c = chrome === null || chrome === void 0 ? void 0 : chrome.extension) === null || _c === void 0 ? void 0 : _c.getURL) === null || _d === void 0 ? void 0 : _d.call(_c, 'bridge.html')) ||
28
+ '';
29
+ yield this.init(hf);
30
+ });
31
+ this.getHost = () => {
32
+ return this.store.host;
33
+ };
34
+ this.setTestnetHost = (host) => __awaiter(this, void 0, void 0, function* () {
35
+ this.store.testnetHost = host;
36
+ });
37
+ this.getTestnetHost = () => {
38
+ return this.store.testnetHost;
39
+ };
40
+ this.ethRpc = () => __awaiter(this, void 0, void 0, function* () {
41
+ throw ethErrors.provider.disconnected();
42
+ });
43
+ this.init = (hf) => __awaiter(this, void 0, void 0, function* () {
44
+ var _e;
45
+ yield sign.lW(hf);
46
+ if (!process.env.DEBUG) {
47
+ this.store.host = INITIAL_OPENAPI_URL;
48
+ this.store.testnetHost = INITIAL_TESTNET_OPENAPI_URL;
49
+ }
50
+ const request = axios.create({
51
+ baseURL: this.store.host,
52
+ adapter: this.adapter,
53
+ headers: {
54
+ 'X-Client': 'Rabby',
55
+ 'X-Version': (_e = process.env.release) !== null && _e !== void 0 ? _e : '0.0.0',
56
+ },
57
+ });
58
+ // sign after rateLimit, timestamp is the latest
59
+ request.interceptors.request.use((config) => {
60
+ const { method, url, params } = genSignParams(config);
61
+ const res = sign.cattleGsW(params, method, url);
62
+ config.headers = config.headers || {};
63
+ config.headers[SIGN_HDS[0]] = encodeURIComponent(res.ts);
64
+ config.headers[SIGN_HDS[1]] = encodeURIComponent(res.nonce);
65
+ config.headers[SIGN_HDS[2]] = encodeURIComponent(res.version);
66
+ config.headers[SIGN_HDS[3]] = encodeURIComponent(res.signature);
67
+ return config;
68
+ });
69
+ this.request = rateLimit(request, { maxRPS });
70
+ this.request.interceptors.response.use((response) => {
71
+ var _a, _b, _c, _d;
72
+ const code = ((_a = response.data) === null || _a === void 0 ? void 0 : _a.err_code) || ((_b = response.data) === null || _b === void 0 ? void 0 : _b.error_code);
73
+ const msg = ((_c = response.data) === null || _c === void 0 ? void 0 : _c.err_msg) || ((_d = response.data) === null || _d === void 0 ? void 0 : _d.error_msg);
74
+ if (code && code !== 200) {
75
+ if (msg) {
76
+ let err;
77
+ try {
78
+ err = new Error(JSON.parse(msg));
79
+ }
80
+ catch (e) {
81
+ err = new Error(msg);
82
+ }
83
+ throw err;
84
+ }
85
+ throw new Error(response.data);
86
+ }
87
+ return response;
88
+ });
89
+ this._mountMethods();
90
+ });
91
+ this._getRequestOptions = (chainId) => {
92
+ if (!chainId) {
93
+ return;
94
+ }
95
+ const testnetHost = this.getTestnetHost();
96
+ if (!testnetHost) {
97
+ return;
98
+ }
99
+ const chain = getChain(chainId);
100
+ if (!(chain === null || chain === void 0 ? void 0 : chain.isTestnet)) {
101
+ return;
102
+ }
103
+ return {
104
+ baseURL: testnetHost,
105
+ };
106
+ };
107
+ this._mountMethods = () => {
108
+ this.ethRpc = (chain_id, { origin = 'rabby', method, params }) => {
109
+ return this.request
110
+ .post(`/v1/wallet/eth_rpc?origin=${origin}&method=${method}`, {
111
+ chain_id,
112
+ method,
113
+ params,
114
+ }, this._getRequestOptions(chain_id))
115
+ .then(({ data }) => {
116
+ if (data === null || data === void 0 ? void 0 : data.error) {
117
+ throw data.error;
118
+ }
119
+ return data === null || data === void 0 ? void 0 : data.result;
120
+ });
121
+ };
122
+ };
123
+ this.getRecommendChains = (address, origin) => __awaiter(this, void 0, void 0, function* () {
124
+ const { data } = yield this.request.get('/v1/wallet/recommend_chains', {
125
+ params: {
126
+ user_addr: address,
127
+ origin,
128
+ },
129
+ });
130
+ return data;
131
+ });
132
+ this.getTotalBalance = (address) => __awaiter(this, void 0, void 0, function* () {
133
+ const { data } = yield this.request.get('/v1/user/total_balance', {
134
+ params: {
135
+ id: address,
136
+ },
137
+ });
138
+ return Object.assign(Object.assign({}, data), { chain_list: data.chain_list.filter((item) => !!Object.values(CHAINS).find((chain) => chain.serverId === item.id)) });
139
+ });
140
+ this.getPendingCount = (address) => __awaiter(this, void 0, void 0, function* () {
141
+ const { data } = yield this.request.get('/v1/wallet/pending_tx_count', {
142
+ params: {
143
+ user_addr: address,
144
+ },
145
+ });
146
+ return data;
147
+ });
148
+ this.checkOrigin = (address, origin) => __awaiter(this, void 0, void 0, function* () {
149
+ const { data } = yield this.request.post('/v1/wallet/check_origin', {
150
+ user_addr: address,
151
+ origin,
152
+ });
153
+ return data;
154
+ });
155
+ this.checkText = (address, origin, text) => __awaiter(this, void 0, void 0, function* () {
156
+ const { data } = yield this.request.post('/v1/wallet/check_text', {
157
+ user_addr: address,
158
+ origin,
159
+ text,
160
+ });
161
+ return data;
162
+ });
163
+ this.checkTx = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
164
+ const { data } = yield this.request.post('/v1/wallet/check_tx', {
165
+ user_addr: address,
166
+ origin,
167
+ tx,
168
+ update_nonce,
169
+ });
170
+ return data;
171
+ });
172
+ this.preExecTx = ({ tx, origin, address, updateNonce = false, pending_tx_list = [], }) => __awaiter(this, void 0, void 0, function* () {
173
+ const { data } = yield this.request.post('/v1/wallet/pre_exec_tx', {
174
+ tx,
175
+ user_addr: address,
176
+ origin,
177
+ update_nonce: updateNonce,
178
+ pending_tx_list,
179
+ });
180
+ return data;
181
+ });
182
+ this.historyGasUsed = (params) => __awaiter(this, void 0, void 0, function* () {
183
+ const { data } = yield this.request.post('/v1/wallet/history_tx_used_gas', Object.assign({}, params));
184
+ return data;
185
+ });
186
+ this.pendingTxList = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
187
+ const { data } = yield this.request.post('/v1/wallet/pending_tx_list', {
188
+ tx,
189
+ user_addr: address,
190
+ origin,
191
+ update_nonce,
192
+ });
193
+ return data;
194
+ });
195
+ this.traceTx = (txId, traceId, chainId) => __awaiter(this, void 0, void 0, function* () {
196
+ const { data } = yield this.request.post('/v1/wallet/trace_tx', {
197
+ tx_id: txId,
198
+ trace_id: traceId,
199
+ chain_id: chainId,
200
+ }, this._getRequestOptions(chainId));
201
+ return data;
202
+ });
203
+ this.pushTx = (tx, traceId) => __awaiter(this, void 0, void 0, function* () {
204
+ const chain = TESTNET_CHAINS_LIST.find((item) => item.id === tx.chainId);
205
+ const { data } = yield this.request.post('/v1/wallet/push_tx', {
206
+ tx,
207
+ trace_id: traceId,
208
+ }, this._getRequestOptions(chain === null || chain === void 0 ? void 0 : chain.serverId));
209
+ return data;
210
+ });
211
+ this.explainText = (origin, address, text) => __awaiter(this, void 0, void 0, function* () {
212
+ const { data } = yield this.request.post('/v1/wallet/explain_text', {
213
+ user_addr: address,
214
+ origin,
215
+ text,
216
+ });
217
+ return data;
218
+ });
219
+ this.gasMarket = (chainId, customGas) => __awaiter(this, void 0, void 0, function* () {
220
+ const { data } = yield this.request.get('/v1/wallet/gas_market', Object.assign({ params: {
221
+ chain_id: chainId,
222
+ custom_price: customGas,
223
+ } }, this._getRequestOptions(chainId)));
224
+ return data;
225
+ });
226
+ this.getTx = (chainId, hash, gasPrice) => __awaiter(this, void 0, void 0, function* () {
227
+ const { data } = yield this.request.get('/v1/wallet/get_tx', Object.assign({ params: {
228
+ chain_id: chainId,
229
+ gas_price: gasPrice,
230
+ tx_id: hash,
231
+ } }, this._getRequestOptions(chainId)));
232
+ return data;
233
+ });
234
+ this.getEnsAddressByName = (name) => __awaiter(this, void 0, void 0, function* () {
235
+ const { data } = yield this.request.get('/v1/wallet/ens', {
236
+ params: {
237
+ text: name,
238
+ },
239
+ });
240
+ return data;
241
+ });
242
+ this.searchToken = (id, q, chainId, is_all = false) => __awaiter(this, void 0, void 0, function* () {
243
+ const { data } = yield this.request.get('/v1/user/token_search', Object.assign({ params: {
244
+ id,
245
+ q,
246
+ has_balance: false,
247
+ is_all,
248
+ chain_id: chainId,
249
+ } }, this._getRequestOptions(chainId)));
250
+ return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
251
+ });
252
+ this.searchSwapToken = (id, chainId, q, is_all = false) => __awaiter(this, void 0, void 0, function* () {
253
+ const { data } = yield this.request.get('/v1/user/token_search', Object.assign({ params: {
254
+ id,
255
+ chain_id: chainId,
256
+ q,
257
+ is_all,
258
+ } }, this._getRequestOptions(chainId)));
259
+ return data;
260
+ });
261
+ this.getToken = (id, chainId, tokenId) => __awaiter(this, void 0, void 0, function* () {
262
+ const { data } = yield this.request.get('/v1/user/token', Object.assign({ params: {
263
+ id,
264
+ chain_id: chainId,
265
+ token_id: tokenId,
266
+ } }, this._getRequestOptions(chainId)));
267
+ return data;
268
+ });
269
+ this.getCachedTokenList = (id) => __awaiter(this, void 0, void 0, function* () {
270
+ const { data } = yield this.request.get('/v1/user/cache_token_list', {
271
+ params: {
272
+ id,
273
+ },
274
+ });
275
+ return data;
276
+ });
277
+ this.listToken = (id, chainId, isAll = false) => __awaiter(this, void 0, void 0, function* () {
278
+ const { data } = yield this.request.get('/v1/user/token_list', Object.assign({ params: {
279
+ id,
280
+ is_all: isAll,
281
+ chain_id: chainId,
282
+ } }, this._getRequestOptions(chainId)));
283
+ return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
284
+ });
285
+ this.getHistoryTokenList = (params) => __awaiter(this, void 0, void 0, function* () {
286
+ const { data } = yield this.request.get('/v1/user/history_token_list', Object.assign({ params: {
287
+ id: params.id,
288
+ chain_id: params.chainId,
289
+ time_at: params.timeAt,
290
+ date_at: params.dateAt,
291
+ } }, this._getRequestOptions(params.chainId)));
292
+ return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
293
+ });
294
+ this.customListToken = (uuids, id) => __awaiter(this, void 0, void 0, function* () {
295
+ const chain = TESTNET_CHAINS_LIST.find((item) => {
296
+ return uuids === null || uuids === void 0 ? void 0 : uuids.find((uuid) => uuid.split(':')[0] === item.serverId);
297
+ });
298
+ const { data } = yield this.request.post('/v1/user/specific_token_list', {
299
+ id,
300
+ uuids,
301
+ }, this._getRequestOptions(chain === null || chain === void 0 ? void 0 : chain.serverId));
302
+ return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
303
+ });
304
+ this.listChainAssets = (id) => __awaiter(this, void 0, void 0, function* () {
305
+ const { data } = yield this.request.get('/v1/user/simple_protocol_list', {
306
+ params: {
307
+ id,
308
+ },
309
+ });
310
+ return data;
311
+ });
312
+ this.listNFT = (id, isAll = true) => __awaiter(this, void 0, void 0, function* () {
313
+ const { data } = yield this.request.get('/v1/user/nft_list', {
314
+ params: {
315
+ id,
316
+ is_all: isAll,
317
+ },
318
+ });
319
+ return data === null || data === void 0 ? void 0 : data.filter((nft) => getChain(nft.chain));
320
+ });
321
+ this.listCollection = (params) => __awaiter(this, void 0, void 0, function* () {
322
+ const { data } = yield this.request.get('/v1/nft/collections', {
323
+ params,
324
+ });
325
+ return data;
326
+ });
327
+ this.listTxHisotry = (params) => __awaiter(this, void 0, void 0, function* () {
328
+ const { data } = yield this.request.get('/v1/user/history_list', Object.assign({ params }, this._getRequestOptions(params.chain_id)));
329
+ return data;
330
+ });
331
+ this.tokenPrice = (tokenName) => __awaiter(this, void 0, void 0, function* () {
332
+ const { data } = yield this.request.get('/v1/token/price_change', {
333
+ params: {
334
+ token: tokenName,
335
+ },
336
+ });
337
+ return data;
338
+ });
339
+ this.tokenAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
340
+ const { data } = yield this.request.get('/v1/user/token_authorized_list', Object.assign({ params: {
341
+ id,
342
+ chain_id,
343
+ } }, this._getRequestOptions(chain_id)));
344
+ return data;
345
+ });
346
+ this.userNFTAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
347
+ const { data } = yield this.request.get('/v1/user/nft_authorized_list', Object.assign({ params: {
348
+ id,
349
+ chain_id,
350
+ } }, this._getRequestOptions(chain_id)));
351
+ return data;
352
+ });
353
+ this.getDEXList = (chain_id) => __awaiter(this, void 0, void 0, function* () {
354
+ const { data } = yield this.request.get('/v1/wallet/swap_dex_list', Object.assign({ params: {
355
+ chain_id,
356
+ } }, this._getRequestOptions(chain_id)));
357
+ return data;
358
+ });
359
+ this.getSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
360
+ const { data } = yield this.request.get('/v1/wallet/swap_quote', Object.assign({ params }, this._getRequestOptions(params === null || params === void 0 ? void 0 : params.chain_id)));
361
+ return data;
362
+ });
363
+ this.getSwapTokenList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
364
+ const { data } = yield this.request.get('/v1/wallet/swap_token_list', Object.assign({ params: {
365
+ id,
366
+ chain_id: chainId,
367
+ is_all: false,
368
+ } }, this._getRequestOptions(chainId)));
369
+ return data;
370
+ });
371
+ this.postGasStationOrder = (params) => __awaiter(this, void 0, void 0, function* () {
372
+ const { data } = yield this.request.post('/v1/wallet/gas_station_order', {
373
+ order: {
374
+ user_addr: params.userAddr,
375
+ from_chain_id: params.fromChainId,
376
+ from_tx_id: params.fromTxId,
377
+ from_token_id: params.fromTokenId,
378
+ from_token_amount: params.fromTokenAmount,
379
+ to_chain_id: params.toChainId,
380
+ to_token_amount: params.toTokenAmount,
381
+ from_usd_value: params.fromUsdValue,
382
+ },
383
+ }, this._getRequestOptions(params.fromChainId));
384
+ return data;
385
+ });
386
+ this.getGasStationChainBalance = (chain_id, addr) => __awaiter(this, void 0, void 0, function* () {
387
+ const { data } = yield this.request.get('/v1/wallet/gas_station_usd_value', Object.assign({ params: {
388
+ chain_id,
389
+ addr,
390
+ } }, this._getRequestOptions(chain_id)));
391
+ return data;
392
+ });
393
+ this.getGasStationTokenList = () => __awaiter(this, void 0, void 0, function* () {
394
+ const { data } = yield this.request.get('/v1/wallet/gas_station_token_list');
395
+ return data;
396
+ });
397
+ this.explainTypedData = (user_addr, origin, data) => __awaiter(this, void 0, void 0, function* () {
398
+ const { data: resData } = yield this.request.post('/v1/wallet/explain_typed_data', {
399
+ user_addr,
400
+ origin,
401
+ data,
402
+ });
403
+ return resData;
404
+ });
405
+ this.checkTypedData = (user_addr, origin, data) => __awaiter(this, void 0, void 0, function* () {
406
+ const { data: resData } = yield this.request.post('/v1/wallet/check_typed_data', {
407
+ user_addr,
408
+ origin,
409
+ data,
410
+ });
411
+ return resData;
412
+ });
413
+ this.approvalStatus = (id) => __awaiter(this, void 0, void 0, function* () {
414
+ const { data } = yield this.request.get('/v1/user/approval_status', {
415
+ params: {
416
+ id,
417
+ },
418
+ });
419
+ return data;
420
+ });
421
+ this.usedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
422
+ const { data } = yield this.request.get('/v1/user/used_chain_list', {
423
+ params: {
424
+ id,
425
+ },
426
+ });
427
+ return data;
428
+ });
429
+ this.getLatestVersion = () => __awaiter(this, void 0, void 0, function* () {
430
+ const { data } = yield this.request.get('/v1/wallet/version');
431
+ return data;
432
+ });
433
+ this.addOriginFeedback = (params) => __awaiter(this, void 0, void 0, function* () {
434
+ const { data } = yield this.request.post('/v1/wallet/add_origin_feedback', {
435
+ user_addr: params.user_addr,
436
+ origin: params.origin,
437
+ is_safe: params.is_safe,
438
+ });
439
+ return data;
440
+ });
441
+ this.getProtocolList = (addr) => __awaiter(this, void 0, void 0, function* () {
442
+ const { data } = yield this.request.get('/v1/user/protocol_list', {
443
+ params: {
444
+ id: addr,
445
+ },
446
+ });
447
+ return data;
448
+ });
449
+ this.getComplexProtocolList = (addr) => __awaiter(this, void 0, void 0, function* () {
450
+ const { data } = yield this.request.get('/v1/user/complex_protocol_list', {
451
+ params: {
452
+ id: addr,
453
+ },
454
+ });
455
+ return data;
456
+ });
457
+ this.getProtocol = ({ addr, id, }) => __awaiter(this, void 0, void 0, function* () {
458
+ const { data } = yield this.request.get('/v1/user/protocol', {
459
+ params: {
460
+ id: addr,
461
+ protocol_id: id,
462
+ },
463
+ });
464
+ return data;
465
+ });
466
+ this.getHistoryProtocol = ({ addr, id, timeAt, dateAt, }) => __awaiter(this, void 0, void 0, function* () {
467
+ const { data } = yield this.request.get('/v1/user/history_protocol', {
468
+ params: {
469
+ id: addr,
470
+ protocol_id: id,
471
+ time_at: timeAt,
472
+ date_at: dateAt,
473
+ },
474
+ });
475
+ return data;
476
+ });
477
+ this.getTokenHistoryPrice = ({ chainId, id, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
478
+ const { data } = yield this.request.get('/v1/token/history_price', Object.assign({ params: {
479
+ chain_id: chainId,
480
+ id,
481
+ time_at: timeAt,
482
+ } }, this._getRequestOptions(chainId)));
483
+ return data;
484
+ });
485
+ this.getTokenHistoryDict = ({ chainId, ids, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
486
+ const { data } = yield this.request.get('/v1/token/history_price_dict', Object.assign({ params: {
487
+ chain_id: chainId,
488
+ ids,
489
+ time_at: timeAt,
490
+ } }, this._getRequestOptions(chainId)));
491
+ return data;
492
+ });
493
+ this.getNetCurve = (addr) => __awaiter(this, void 0, void 0, function* () {
494
+ const { data } = yield this.request.get('/v1/user/total_net_curve', {
495
+ params: {
496
+ id: addr,
497
+ },
498
+ });
499
+ return data;
500
+ });
501
+ this.getChainList = () => __awaiter(this, void 0, void 0, function* () {
502
+ const { data } = yield this.request.get('/v1/chain/list');
503
+ return data;
504
+ });
505
+ this.getCEXSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
506
+ const { data } = yield this.request.get('/v1/wallet/cex_swap_quote', Object.assign({ params }, this._getRequestOptions(params === null || params === void 0 ? void 0 : params.chain_id)));
507
+ return data;
508
+ });
509
+ this.getSwapTradeList = (params) => __awaiter(this, void 0, void 0, function* () {
510
+ const { data } = yield this.request.get('/v1/wallet/swap_trade_list', {
511
+ params,
512
+ });
513
+ return data;
514
+ });
515
+ this.postSwap = (params) => __awaiter(this, void 0, void 0, function* () {
516
+ const { data } = yield this.request.post('/v1/wallet/swap_trade', params);
517
+ return data;
518
+ });
519
+ this.checkSlippage = (params) => __awaiter(this, void 0, void 0, function* () {
520
+ const { data } = yield this.request.get('/v1/wallet/check_slippage', Object.assign({ params }, this._getRequestOptions(params === null || params === void 0 ? void 0 : params.chain_id)));
521
+ return data;
522
+ });
523
+ this.getOriginPopularityLevel = (origin) => __awaiter(this, void 0, void 0, function* () {
524
+ const { data } = yield this.request.get('/v1/engine/origin/popularity_level', {
525
+ params: {
526
+ origin,
527
+ },
528
+ });
529
+ return data;
530
+ });
531
+ this.getOriginIsScam = (origin, source) => __awaiter(this, void 0, void 0, function* () {
532
+ const { data } = yield this.request.get('/v1/engine/origin/is_scam', {
533
+ params: {
534
+ origin,
535
+ source,
536
+ },
537
+ });
538
+ return data;
539
+ });
540
+ this.getOriginThirdPartyCollectList = (origin) => __awaiter(this, void 0, void 0, function* () {
541
+ const { data } = yield this.request.get('/v1/engine/origin/third_party_collect_list', {
542
+ params: {
543
+ origin,
544
+ },
545
+ });
546
+ return data;
547
+ });
548
+ this.getSummarizedAssetList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
549
+ const { data } = yield this.request.get('/v1/user/summarized_asset_list', Object.assign({ params: {
550
+ id,
551
+ chain_id,
552
+ } }, this._getRequestOptions(chain_id)));
553
+ return data;
554
+ });
555
+ this.parseTx = ({ chainId, tx, origin, addr, }) => __awaiter(this, void 0, void 0, function* () {
556
+ const { data } = yield this.request.post('/v1/engine/action/parse_tx', {
557
+ chain_id: chainId,
558
+ tx,
559
+ origin,
560
+ user_addr: addr,
561
+ }, this._getRequestOptions(chainId));
562
+ return data;
563
+ });
564
+ this.isSuspiciousToken = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
565
+ const { data } = yield this.request.get('/v1/engine/token/is_suspicious', Object.assign({ params: {
566
+ chain_id: chainId,
567
+ id,
568
+ } }, this._getRequestOptions(chainId)));
569
+ return data;
570
+ });
571
+ this.depositCexSupport = (id, chainId, cexId) => __awaiter(this, void 0, void 0, function* () {
572
+ const { data } = yield this.request.get('/v1/engine/token/deposit_cex_support', Object.assign({ params: {
573
+ chain_id: chainId,
574
+ id,
575
+ cex_id: cexId,
576
+ } }, this._getRequestOptions(chainId)));
577
+ return data;
578
+ });
579
+ // Token 可充值的 CEX 列表
580
+ this.depositCexList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
581
+ const { data } = yield this.request.get('/v1/engine/token/deposit_cex_list', Object.assign({ params: {
582
+ chain_id: chainId,
583
+ id,
584
+ } }, this._getRequestOptions(chainId)));
585
+ return data;
586
+ });
587
+ // 合约信用分
588
+ this.getContractCredit = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
589
+ const { data } = yield this.request.get('/v1/engine/contract/credit', Object.assign({ params: {
590
+ chain_id: chainId,
591
+ id,
592
+ } }, this._getRequestOptions(chainId)));
593
+ return data;
594
+ });
595
+ // 是否跟地址交互过
596
+ this.hasInteraction = (addr, chainId, contractId) => __awaiter(this, void 0, void 0, function* () {
597
+ const { data } = yield this.request.get('/v1/engine/contract/has_interaction', Object.assign({ params: {
598
+ chain_id: chainId,
599
+ user_addr: addr,
600
+ contract_id: contractId,
601
+ } }, this._getRequestOptions(chainId)));
602
+ return data;
603
+ });
604
+ // 授权风险敞口
605
+ this.tokenApproveExposure = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
606
+ const { data } = yield this.request.get('/v1/engine/contract/token_approval_exposure', Object.assign({ params: {
607
+ chain_id: chainId,
608
+ id,
609
+ } }, this._getRequestOptions(chainId)));
610
+ return data;
611
+ });
612
+ // 地址描述
613
+ this.addrDesc = (id) => __awaiter(this, void 0, void 0, function* () {
614
+ const { data } = yield this.request.get('/v1/engine/addr/desc', {
615
+ params: {
616
+ id,
617
+ },
618
+ });
619
+ return data;
620
+ });
621
+ // 两个地址是否发生过转账
622
+ this.hasTransfer = (chainId, from, to) => __awaiter(this, void 0, void 0, function* () {
623
+ const { data } = yield this.request.get('/v1/engine/addr/has_transfer', Object.assign({ params: {
624
+ chain_id: chainId,
625
+ from_addr: from,
626
+ to_addr: to,
627
+ } }, this._getRequestOptions(chainId)));
628
+ return data;
629
+ });
630
+ this.isTokenContract = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
631
+ const { data } = yield this.request.get('/v1/engine/contract/is_token', Object.assign({ params: {
632
+ id,
633
+ chain_id: chainId,
634
+ } }, this._getRequestOptions(chainId)));
635
+ return data;
636
+ });
637
+ this.addrUsedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
638
+ const { data } = yield this.request.get('/v1/engine/addr/used_chain_list', {
639
+ params: { id },
640
+ });
641
+ return data;
642
+ });
643
+ this.getTokenNFTExposure = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
644
+ const { data } = yield this.request.get('/v1/engine/contract/top_nft_approval_exposure', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
645
+ return data;
646
+ });
647
+ this.getCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
648
+ const { data } = yield this.request.get('/v1/engine/collection', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
649
+ return data;
650
+ });
651
+ this.isSuspiciousCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
652
+ const { data } = yield this.request.get('/v1/engine/collection/is_suspicious', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
653
+ return data;
654
+ });
655
+ this.isOriginVerified = (origin) => __awaiter(this, void 0, void 0, function* () {
656
+ const { data } = yield this.request.get('/v1/engine/origin/is_verified', {
657
+ params: { origin },
658
+ });
659
+ return data;
660
+ });
661
+ this.parseTypedData = ({ typedData, origin, address, }) => __awaiter(this, void 0, void 0, function* () {
662
+ const { data } = yield this.request.post('/v1/engine/action/parse_typed_data', {
663
+ typed_data: typedData,
664
+ origin,
665
+ user_addr: address,
666
+ });
667
+ return data;
668
+ });
669
+ this.parseText = ({ text, origin, address, }) => __awaiter(this, void 0, void 0, function* () {
670
+ const { data } = yield this.request.post('/v1/engine/action/parse_text', {
671
+ text,
672
+ origin,
673
+ user_addr: address,
674
+ });
675
+ return data;
676
+ });
677
+ this.collectionList = ({ id, chainId, isAll, }) => __awaiter(this, void 0, void 0, function* () {
678
+ const { data } = yield this.request.get('/v1/user/collection_list', Object.assign({ params: {
679
+ id,
680
+ chain_id: chainId,
681
+ is_all: isAll,
682
+ } }, this._getRequestOptions(chainId)));
683
+ return data;
684
+ });
685
+ this.store = store;
686
+ this.adapter = adapter;
687
+ }
688
+ }