@rabby-wallet/rabby-api 0.7.4 → 0.7.6

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,946 +1,965 @@
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
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
- if (kind === "m") throw new TypeError("Private method is not writable");
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
- };
16
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
- };
21
- var _OpenApiService_adapter, _OpenApiService_plugin, _OpenApiService_clientName, _OpenApiService_clientVersion;
22
- import axios from 'axios';
23
- import rateLimit from 'axios-rate-limit';
24
- import { ethErrors } from 'eth-rpc-errors';
25
- import { CHAINS, genSignParams, getChain, getChainByNetwork, sleep, } from './utils';
26
- import { ASYNC_JOB_RETRY_DELAY, ASYNC_JOB_TIMEOUT } from './const';
27
- import { omit } from 'lodash';
28
- const maxRPS = 500;
29
- export class OpenApiService {
30
- constructor(_a) {
31
- var _b;
32
- var { store, plugin, adapter, clientName = 'Rabby', clientVersion = (_b = process.env.release) !== null && _b !== void 0 ? _b : '0.0.0', } = _a;
33
- _OpenApiService_adapter.set(this, void 0);
34
- _OpenApiService_plugin.set(this, void 0);
35
- _OpenApiService_clientName.set(this, void 0);
36
- _OpenApiService_clientVersion.set(this, void 0);
37
- this.setHost = (host) => __awaiter(this, void 0, void 0, function* () {
38
- this.store.host = host;
39
- yield this.init();
40
- });
41
- this.setHostSync = (host) => {
42
- this.store.host = host;
43
- this.initSync();
44
- };
45
- this.getHost = () => {
46
- return this.store.host;
47
- };
48
- this.setTestnetHost = (host) => __awaiter(this, void 0, void 0, function* () {
49
- this.store.testnetHost = host;
50
- });
51
- this.getTestnetHost = () => {
52
- return this.store.testnetHost;
53
- };
54
- this.ethRpc = () => __awaiter(this, void 0, void 0, function* () {
55
- throw ethErrors.provider.disconnected();
56
- });
57
- this.init = (options) => __awaiter(this, void 0, void 0, function* () {
58
- var _c, _d;
59
- options = typeof options === 'string' ? { webHf: options } : options;
60
- yield ((_d = (_c = __classPrivateFieldGet(this, _OpenApiService_plugin, "f")).onInitiateAsync) === null || _d === void 0 ? void 0 : _d.call(_c, Object.assign({}, options)));
61
- this.initSync(Object.assign({}, options));
62
- });
63
- this.asyncJob = (url, options) => {
64
- const _option = Object.assign({ timeout: ASYNC_JOB_TIMEOUT, retryDelay: ASYNC_JOB_RETRY_DELAY }, options);
65
- const startTime = +new Date();
66
- return this.request(url, omit(Object.assign({ method: 'GET' }, _option), 'retryDelay')).then((res) => {
67
- const data = res.data;
68
- if (data.result) {
69
- return data.result.data;
70
- }
71
- const deltaTime = +new Date() - startTime;
72
- _option.timeout = _option.timeout - deltaTime - _option.retryDelay;
73
- return sleep(_option.retryDelay, _option.signal).then(() => this.asyncJob(url, _option));
74
- });
75
- };
76
- this._getRequestOptions = (chainId) => {
77
- if (!chainId) {
78
- return;
79
- }
80
- const testnetHost = this.getTestnetHost();
81
- if (!testnetHost) {
82
- return;
83
- }
84
- const chain = getChain(chainId);
85
- if (!(chain === null || chain === void 0 ? void 0 : chain.isTestnet)) {
86
- return;
87
- }
88
- return {
89
- baseURL: testnetHost,
90
- };
91
- };
92
- this._mountMethods = () => {
93
- this.ethRpc = (chain_id, { origin = 'rabby', method, params }) => {
94
- return this.request
95
- .post(`/v1/wallet/eth_rpc?origin=${origin}&method=${method}`, {
96
- chain_id,
97
- method,
98
- params,
99
- }, this._getRequestOptions(chain_id))
100
- .then(({ data }) => {
101
- if (data === null || data === void 0 ? void 0 : data.error) {
102
- throw data.error;
103
- }
104
- return data === null || data === void 0 ? void 0 : data.result;
105
- });
106
- };
107
- };
108
- this.getRecommendChains = (address, origin) => __awaiter(this, void 0, void 0, function* () {
109
- const { data } = yield this.request.get('/v1/wallet/recommend_chains', {
110
- params: {
111
- user_addr: address,
112
- origin,
113
- },
114
- });
115
- return data;
116
- });
117
- this.getTotalBalance = (address) => __awaiter(this, void 0, void 0, function* () {
118
- const { data } = yield this.request.get('/v1/user/total_balance', {
119
- params: {
120
- id: address,
121
- },
122
- });
123
- return Object.assign(Object.assign({}, data), { chain_list: data.chain_list.filter((item) => !!Object.values(CHAINS).find((chain) => chain.serverId === item.id)) });
124
- });
125
- this.getPendingCount = (address) => __awaiter(this, void 0, void 0, function* () {
126
- const { data } = yield this.request.get('/v1/wallet/pending_tx_count', {
127
- params: {
128
- user_addr: address,
129
- },
130
- });
131
- return data;
132
- });
133
- this.checkOrigin = (address, origin) => __awaiter(this, void 0, void 0, function* () {
134
- const { data } = yield this.request.post('/v1/wallet/check_origin', {
135
- user_addr: address,
136
- origin,
137
- });
138
- return data;
139
- });
140
- this.checkText = (address, origin, text) => __awaiter(this, void 0, void 0, function* () {
141
- const { data } = yield this.request.post('/v1/wallet/check_text', {
142
- user_addr: address,
143
- origin,
144
- text,
145
- });
146
- return data;
147
- });
148
- this.checkTx = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
149
- var _e;
150
- const { data } = yield this.request.post('/v1/wallet/check_tx', {
151
- user_addr: address,
152
- origin,
153
- tx,
154
- update_nonce,
155
- }, this._getRequestOptions((_e = getChainByNetwork(tx.chainId)) === null || _e === void 0 ? void 0 : _e.serverId));
156
- return data;
157
- });
158
- this.preExecTx = ({ tx, origin, address, updateNonce = false, pending_tx_list = [], }) => __awaiter(this, void 0, void 0, function* () {
159
- var _f;
160
- const { data } = yield this.request.post('/v1/wallet/pre_exec_tx', {
161
- tx,
162
- user_addr: address,
163
- origin,
164
- update_nonce: updateNonce,
165
- pending_tx_list,
166
- }, this._getRequestOptions((_f = getChainByNetwork(tx.chainId)) === null || _f === void 0 ? void 0 : _f.serverId));
167
- return data;
168
- });
169
- this.historyGasUsed = (params) => __awaiter(this, void 0, void 0, function* () {
170
- var _g, _h;
171
- const { data } = yield this.request.post('/v1/wallet/history_tx_used_gas', Object.assign({}, params), this._getRequestOptions((_h = getChainByNetwork((_g = params === null || params === void 0 ? void 0 : params.tx) === null || _g === void 0 ? void 0 : _g.chainId)) === null || _h === void 0 ? void 0 : _h.serverId));
172
- return data;
173
- });
174
- this.pendingTxList = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
175
- var _j;
176
- const { data } = yield this.request.post('/v1/wallet/pending_tx_list', {
177
- tx,
178
- user_addr: address,
179
- origin,
180
- update_nonce,
181
- }, this._getRequestOptions((_j = getChainByNetwork(tx.chainId)) === null || _j === void 0 ? void 0 : _j.serverId));
182
- return data;
183
- });
184
- this.traceTx = (txId, traceId, chainId) => __awaiter(this, void 0, void 0, function* () {
185
- const { data } = yield this.request.post('/v1/wallet/trace_tx', {
186
- tx_id: txId,
187
- trace_id: traceId,
188
- chain_id: chainId,
189
- }, this._getRequestOptions(chainId));
190
- return data;
191
- });
192
- this.pushTx = (tx, traceId) => __awaiter(this, void 0, void 0, function* () {
193
- var _k;
194
- const { data } = yield this.request.post('/v1/wallet/push_tx', {
195
- tx,
196
- trace_id: traceId,
197
- }, this._getRequestOptions((_k = getChainByNetwork(tx.chainId)) === null || _k === void 0 ? void 0 : _k.serverId));
198
- return data;
199
- });
200
- this.explainText = (origin, address, text) => __awaiter(this, void 0, void 0, function* () {
201
- const { data } = yield this.request.post('/v1/wallet/explain_text', {
202
- user_addr: address,
203
- origin,
204
- text,
205
- });
206
- return data;
207
- });
208
- this.gasMarket = (chainId, customGas) => __awaiter(this, void 0, void 0, function* () {
209
- const { data } = yield this.request.get('/v1/wallet/gas_market', Object.assign({ params: {
210
- chain_id: chainId,
211
- custom_price: customGas,
212
- } }, this._getRequestOptions(chainId)));
213
- return data;
214
- });
215
- this.getTx = (chainId, hash, gasPrice) => __awaiter(this, void 0, void 0, function* () {
216
- const { data } = yield this.request.get('/v1/wallet/get_tx', Object.assign({ params: {
217
- chain_id: chainId,
218
- gas_price: gasPrice,
219
- tx_id: hash,
220
- } }, this._getRequestOptions(chainId)));
221
- return data;
222
- });
223
- this.getEnsAddressByName = (name) => __awaiter(this, void 0, void 0, function* () {
224
- const { data } = yield this.request.get('/v1/wallet/ens', {
225
- params: {
226
- text: name,
227
- },
228
- });
229
- return data;
230
- });
231
- this.searchToken = (id, q, chainId, is_all = false) => __awaiter(this, void 0, void 0, function* () {
232
- const { data } = yield this.request.get('/v1/user/token_search', Object.assign({ params: {
233
- id,
234
- q,
235
- has_balance: false,
236
- is_all,
237
- chain_id: chainId,
238
- } }, this._getRequestOptions(chainId)));
239
- return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
240
- });
241
- this.searchSwapToken = (id, chainId, q, is_all = false) => __awaiter(this, void 0, void 0, function* () {
242
- const { data } = yield this.request.get('/v1/user/token_search', Object.assign({ params: {
243
- id,
244
- chain_id: chainId,
245
- q,
246
- is_all,
247
- } }, this._getRequestOptions(chainId)));
248
- return data;
249
- });
250
- this.getToken = (id, chainId, tokenId) => __awaiter(this, void 0, void 0, function* () {
251
- const { data } = yield this.request.get('/v1/user/token', Object.assign({ params: {
252
- id,
253
- chain_id: chainId,
254
- token_id: tokenId,
255
- } }, this._getRequestOptions(chainId)));
256
- return data;
257
- });
258
- this.getCachedTokenList = (id) => __awaiter(this, void 0, void 0, function* () {
259
- const { data } = yield this.request.get('/v1/user/cache_token_list', {
260
- params: {
261
- id,
262
- },
263
- });
264
- return data;
265
- });
266
- this.listToken = (id, chainId, isAll = false) => __awaiter(this, void 0, void 0, function* () {
267
- const { data } = yield this.request.get('/v1/user/token_list', Object.assign({ params: {
268
- id,
269
- is_all: isAll,
270
- chain_id: chainId,
271
- } }, this._getRequestOptions(chainId)));
272
- return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
273
- });
274
- this.getHistoryTokenList = (params) => __awaiter(this, void 0, void 0, function* () {
275
- const { data } = yield this.request.get('/v1/user/history_token_list', Object.assign({ params: {
276
- id: params.id,
277
- chain_id: params.chainId,
278
- time_at: params.timeAt,
279
- date_at: params.dateAt,
280
- } }, this._getRequestOptions(params.chainId)));
281
- return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
282
- });
283
- this._customListToken = (uuids, id, isTestnet = false) => __awaiter(this, void 0, void 0, function* () {
284
- if (!(uuids === null || uuids === void 0 ? void 0 : uuids.length) || !id) {
285
- return [];
286
- }
287
- const { data } = yield this.request.post('/v1/user/specific_token_list', {
288
- id,
289
- uuids,
290
- }, isTestnet && this.store.testnetHost
291
- ? { baseURL: this.store.testnetHost }
292
- : undefined);
293
- return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
294
- });
295
- this.customListToken = (uuids, id) => __awaiter(this, void 0, void 0, function* () {
296
- const mainnetIds = [];
297
- const testnetIds = [];
298
- uuids.forEach((uuid) => {
299
- const serverId = uuid.split(':')[0];
300
- const chain = getChain(serverId);
301
- if (chain === null || chain === void 0 ? void 0 : chain.isTestnet) {
302
- testnetIds.push(uuid);
303
- }
304
- else {
305
- mainnetIds.push(uuid);
306
- }
307
- });
308
- const res = yield Promise.all([
309
- this._customListToken(mainnetIds, id),
310
- this._customListToken(testnetIds, id, true),
311
- ]);
312
- return res.flat();
313
- });
314
- this.listChainAssets = (id) => __awaiter(this, void 0, void 0, function* () {
315
- const { data } = yield this.request.get('/v1/user/simple_protocol_list', {
316
- params: {
317
- id,
318
- },
319
- });
320
- return data;
321
- });
322
- this.listNFT = (id, isAll = true) => __awaiter(this, void 0, void 0, function* () {
323
- const { data } = yield this.request.get('/v1/user/nft_list', {
324
- params: {
325
- id,
326
- is_all: isAll,
327
- },
328
- });
329
- return data === null || data === void 0 ? void 0 : data.filter((nft) => getChain(nft.chain));
330
- });
331
- this.listCollection = (params) => __awaiter(this, void 0, void 0, function* () {
332
- const { data } = yield this.request.get('/v1/nft/collections', {
333
- params,
334
- });
335
- return data;
336
- });
337
- this.listTxHisotry = (params) => __awaiter(this, void 0, void 0, function* () {
338
- const { data } = yield this.request.get('/v1/user/history_list', Object.assign({ params }, this._getRequestOptions(params.chain_id)));
339
- return data;
340
- });
341
- this.getAllTxHistory = (params, options) => __awaiter(this, void 0, void 0, function* () {
342
- const data = yield this.asyncJob('/v1/user/history_all_list', Object.assign({ method: 'GET', params }, options));
343
- return data;
344
- });
345
- this.tokenPrice = (tokenName) => __awaiter(this, void 0, void 0, function* () {
346
- var _l;
347
- const { data } = yield this.request.get('/v1/token/price_change', Object.assign({ params: {
348
- token: tokenName,
349
- } }, this._getRequestOptions((_l = tokenName === null || tokenName === void 0 ? void 0 : tokenName.split(':')) === null || _l === void 0 ? void 0 : _l[0])));
350
- return data;
351
- });
352
- this.tokenAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
353
- const { data } = yield this.request.get('/v1/user/token_authorized_list', Object.assign({ params: {
354
- id,
355
- chain_id,
356
- } }, this._getRequestOptions(chain_id)));
357
- return data;
358
- });
359
- this.userNFTAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
360
- const { data } = yield this.request.get('/v1/user/nft_authorized_list', Object.assign({ params: {
361
- id,
362
- chain_id,
363
- } }, this._getRequestOptions(chain_id)));
364
- return data;
365
- });
366
- this.getDEXList = (chain_id) => __awaiter(this, void 0, void 0, function* () {
367
- const { data } = yield this.request.get('/v1/wallet/swap_dex_list', Object.assign({ params: {
368
- chain_id,
369
- } }, this._getRequestOptions(chain_id)));
370
- return data;
371
- });
372
- this.getSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
373
- 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)));
374
- return data;
375
- });
376
- this.getSwapTokenList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
377
- const { data } = yield this.request.get('/v1/wallet/swap_token_list', Object.assign({ params: {
378
- id,
379
- chain_id: chainId,
380
- is_all: false,
381
- } }, this._getRequestOptions(chainId)));
382
- return data;
383
- });
384
- this.postGasStationOrder = (params) => __awaiter(this, void 0, void 0, function* () {
385
- const { data } = yield this.request.post('/v1/wallet/gas_station_order', {
386
- order: {
387
- user_addr: params.userAddr,
388
- from_chain_id: params.fromChainId,
389
- from_tx_id: params.fromTxId,
390
- from_token_id: params.fromTokenId,
391
- from_token_amount: params.fromTokenAmount,
392
- to_chain_id: params.toChainId,
393
- to_token_amount: params.toTokenAmount,
394
- from_usd_value: params.fromUsdValue,
395
- },
396
- }, this._getRequestOptions(params.fromChainId));
397
- return data;
398
- });
399
- this.getGasStationChainBalance = (chain_id, addr) => __awaiter(this, void 0, void 0, function* () {
400
- const { data } = yield this.request.get('/v1/wallet/gas_station_usd_value', Object.assign({ params: {
401
- chain_id,
402
- addr,
403
- } }, this._getRequestOptions(chain_id)));
404
- return data;
405
- });
406
- this.getGasStationTokenList = () => __awaiter(this, void 0, void 0, function* () {
407
- const { data } = yield this.request.get('/v1/wallet/gas_station_token_list');
408
- return data;
409
- });
410
- this.explainTypedData = (user_addr, origin, data) => __awaiter(this, void 0, void 0, function* () {
411
- const { data: resData } = yield this.request.post('/v1/wallet/explain_typed_data', {
412
- user_addr,
413
- origin,
414
- data,
415
- });
416
- return resData;
417
- });
418
- this.checkTypedData = (user_addr, origin, data) => __awaiter(this, void 0, void 0, function* () {
419
- const { data: resData } = yield this.request.post('/v1/wallet/check_typed_data', {
420
- user_addr,
421
- origin,
422
- data,
423
- });
424
- return resData;
425
- });
426
- this.approvalStatus = (id) => __awaiter(this, void 0, void 0, function* () {
427
- const { data } = yield this.request.get('/v1/user/approval_status', {
428
- params: {
429
- id,
430
- },
431
- });
432
- return data;
433
- });
434
- this.usedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
435
- const { data } = yield this.request.get('/v1/user/used_chain_list', {
436
- params: {
437
- id,
438
- },
439
- });
440
- return data;
441
- });
442
- this.getLatestVersion = () => __awaiter(this, void 0, void 0, function* () {
443
- const { data } = yield this.request.get('/v1/wallet/version');
444
- return data;
445
- });
446
- this.addOriginFeedback = (params) => __awaiter(this, void 0, void 0, function* () {
447
- const { data } = yield this.request.post('/v1/wallet/add_origin_feedback', {
448
- user_addr: params.user_addr,
449
- origin: params.origin,
450
- is_safe: params.is_safe,
451
- });
452
- return data;
453
- });
454
- this.getProtocolList = (addr) => __awaiter(this, void 0, void 0, function* () {
455
- const { data } = yield this.request.get('/v1/user/protocol_list', {
456
- params: {
457
- id: addr,
458
- },
459
- });
460
- return data;
461
- });
462
- this.getComplexProtocolList = (addr) => __awaiter(this, void 0, void 0, function* () {
463
- const { data } = yield this.request.get('/v1/user/complex_protocol_list', {
464
- params: {
465
- id: addr,
466
- },
467
- });
468
- return data;
469
- });
470
- this.getProtocol = ({ addr, id, }) => __awaiter(this, void 0, void 0, function* () {
471
- const { data } = yield this.request.get('/v1/user/protocol', {
472
- params: {
473
- id: addr,
474
- protocol_id: id,
475
- },
476
- });
477
- return data;
478
- });
479
- this.getHistoryProtocol = ({ addr, id, timeAt, dateAt, }) => __awaiter(this, void 0, void 0, function* () {
480
- const { data } = yield this.request.get('/v1/user/history_protocol', {
481
- params: {
482
- id: addr,
483
- protocol_id: id,
484
- time_at: timeAt,
485
- date_at: dateAt,
486
- },
487
- });
488
- return data;
489
- });
490
- this.getTokenHistoryPrice = ({ chainId, id, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
491
- const { data } = yield this.request.get('/v1/token/history_price', Object.assign({ params: {
492
- chain_id: chainId,
493
- id,
494
- time_at: timeAt,
495
- } }, this._getRequestOptions(chainId)));
496
- return data;
497
- });
498
- this.getTokenHistoryDict = ({ chainId, ids, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
499
- const { data } = yield this.request.get('/v1/token/history_price_dict', Object.assign({ params: {
500
- chain_id: chainId,
501
- ids,
502
- time_at: timeAt,
503
- } }, this._getRequestOptions(chainId)));
504
- return data;
505
- });
506
- this.getNetCurve = (addr) => __awaiter(this, void 0, void 0, function* () {
507
- const { data } = yield this.request.get('/v1/user/total_net_curve', {
508
- params: {
509
- id: addr,
510
- },
511
- });
512
- return data;
513
- });
514
- this.getChainList = () => __awaiter(this, void 0, void 0, function* () {
515
- const { data } = yield this.request.get('/v1/chain/list');
516
- return data;
517
- });
518
- this.getCEXSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
519
- 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)));
520
- return data;
521
- });
522
- this.getSwapTradeList = (params) => __awaiter(this, void 0, void 0, function* () {
523
- const { data } = yield this.request.get('/v1/wallet/swap_trade_list', {
524
- params,
525
- });
526
- return data;
527
- });
528
- this.postSwap = (params) => __awaiter(this, void 0, void 0, function* () {
529
- var _m, _o;
530
- const { data } = yield this.request.post('/v1/wallet/swap_trade', params, this._getRequestOptions((_o = getChainByNetwork((_m = params === null || params === void 0 ? void 0 : params.tx) === null || _m === void 0 ? void 0 : _m.chainId)) === null || _o === void 0 ? void 0 : _o.serverId));
531
- return data;
532
- });
533
- this.checkSlippage = (params) => __awaiter(this, void 0, void 0, function* () {
534
- 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)));
535
- return data;
536
- });
537
- this.getOriginPopularityLevel = (origin) => __awaiter(this, void 0, void 0, function* () {
538
- const { data } = yield this.request.get('/v1/engine/origin/popularity_level', {
539
- params: {
540
- origin,
541
- },
542
- });
543
- return data;
544
- });
545
- this.getOriginIsScam = (origin, source) => __awaiter(this, void 0, void 0, function* () {
546
- const { data } = yield this.request.get('/v1/engine/origin/is_scam', {
547
- params: {
548
- origin,
549
- source,
550
- },
551
- });
552
- return data;
553
- });
554
- this.getOriginThirdPartyCollectList = (origin) => __awaiter(this, void 0, void 0, function* () {
555
- const { data } = yield this.request.get('/v1/engine/origin/third_party_collect_list', {
556
- params: {
557
- origin,
558
- },
559
- });
560
- return data;
561
- });
562
- this.getSummarizedAssetList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
563
- const { data } = yield this.request.get('/v1/user/summarized_asset_list', Object.assign({ params: {
564
- id,
565
- chain_id,
566
- } }, this._getRequestOptions(chain_id)));
567
- return data;
568
- });
569
- this.parseTx = ({ chainId, tx, origin, addr, }) => __awaiter(this, void 0, void 0, function* () {
570
- const { data } = yield this.request.post('/v1/engine/action/parse_tx', {
571
- chain_id: chainId,
572
- tx,
573
- origin,
574
- user_addr: addr,
575
- }, this._getRequestOptions(chainId));
576
- return data;
577
- });
578
- this.isSuspiciousToken = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
579
- const { data } = yield this.request.get('/v1/engine/token/is_suspicious', Object.assign({ params: {
580
- chain_id: chainId,
581
- id,
582
- } }, this._getRequestOptions(chainId)));
583
- return data;
584
- });
585
- this.depositCexSupport = (id, chainId, cexId) => __awaiter(this, void 0, void 0, function* () {
586
- const { data } = yield this.request.get('/v1/engine/token/deposit_cex_support', Object.assign({ params: {
587
- chain_id: chainId,
588
- id,
589
- cex_id: cexId,
590
- } }, this._getRequestOptions(chainId)));
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', Object.assign({ params: {
596
- chain_id: chainId,
597
- id,
598
- } }, this._getRequestOptions(chainId)));
599
- return data;
600
- });
601
- // 合约信用分
602
- this.getContractCredit = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
603
- const { data } = yield this.request.get('/v1/engine/contract/credit', Object.assign({ params: {
604
- chain_id: chainId,
605
- id,
606
- } }, this._getRequestOptions(chainId)));
607
- return data;
608
- });
609
- // 是否跟地址交互过
610
- this.hasInteraction = (addr, chainId, contractId) => __awaiter(this, void 0, void 0, function* () {
611
- const { data } = yield this.request.get('/v1/engine/contract/has_interaction', Object.assign({ params: {
612
- chain_id: chainId,
613
- user_addr: addr,
614
- contract_id: contractId,
615
- } }, this._getRequestOptions(chainId)));
616
- return data;
617
- });
618
- // 授权风险敞口
619
- this.tokenApproveExposure = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
620
- const { data } = yield this.request.get('/v1/engine/contract/token_approval_exposure', Object.assign({ params: {
621
- chain_id: chainId,
622
- id,
623
- } }, this._getRequestOptions(chainId)));
624
- return data;
625
- });
626
- // 地址描述
627
- this.addrDesc = (id) => __awaiter(this, void 0, void 0, function* () {
628
- const { data } = yield this.request.get('/v1/engine/addr/desc', {
629
- params: {
630
- id,
631
- },
632
- });
633
- return data;
634
- });
635
- // 两个地址是否发生过转账
636
- this.hasTransfer = (chainId, from, to) => __awaiter(this, void 0, void 0, function* () {
637
- const { data } = yield this.request.get('/v1/engine/addr/has_transfer', Object.assign({ params: {
638
- chain_id: chainId,
639
- from_addr: from,
640
- to_addr: to,
641
- } }, this._getRequestOptions(chainId)));
642
- return data;
643
- });
644
- this.isTokenContract = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
645
- const { data } = yield this.request.get('/v1/engine/contract/is_token', Object.assign({ params: {
646
- id,
647
- chain_id: chainId,
648
- } }, this._getRequestOptions(chainId)));
649
- return data;
650
- });
651
- this.addrUsedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
652
- const { data } = yield this.request.get('/v1/engine/addr/used_chain_list', {
653
- params: { id },
654
- });
655
- return data;
656
- });
657
- this.getTokenNFTExposure = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
658
- const { data } = yield this.request.get('/v1/engine/contract/top_nft_approval_exposure', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
659
- return data;
660
- });
661
- this.getCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
662
- const { data } = yield this.request.get('/v1/engine/collection', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
663
- return data;
664
- });
665
- this.isSuspiciousCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
666
- const { data } = yield this.request.get('/v1/engine/collection/is_suspicious', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
667
- return data;
668
- });
669
- this.isOriginVerified = (origin) => __awaiter(this, void 0, void 0, function* () {
670
- const { data } = yield this.request.get('/v1/engine/origin/is_verified', {
671
- params: { origin },
672
- });
673
- return data;
674
- });
675
- this.parseTypedData = ({ typedData, origin, address, }) => __awaiter(this, void 0, void 0, function* () {
676
- const { data } = yield this.request.post('/v1/engine/action/parse_typed_data', {
677
- typed_data: typedData,
678
- origin,
679
- user_addr: address,
680
- });
681
- return data;
682
- });
683
- this.parseText = ({ text, origin, address, }) => __awaiter(this, void 0, void 0, function* () {
684
- const { data } = yield this.request.post('/v1/engine/action/parse_text', {
685
- text,
686
- origin,
687
- user_addr: address,
688
- });
689
- return data;
690
- });
691
- this.collectionList = ({ id, chainId, isAll, }) => __awaiter(this, void 0, void 0, function* () {
692
- const { data } = yield this.request.get('/v1/user/collection_list', Object.assign({ params: {
693
- id,
694
- chain_id: chainId,
695
- is_all: isAll,
696
- } }, this._getRequestOptions(chainId)));
697
- return data;
698
- });
699
- this.gasPriceStats = (chainId) => __awaiter(this, void 0, void 0, function* () {
700
- const { data } = yield this.request.get('/v1/wallet/gas_price_stats', Object.assign({ params: {
701
- chain_id: chainId,
702
- } }, this._getRequestOptions(chainId)));
703
- return data;
704
- });
705
- this.badgeHasClaimed = (id) => __awaiter(this, void 0, void 0, function* () {
706
- const { data } = yield this.request.get('/v1/badge/code/user_has_claimed', {
707
- params: {
708
- user_id: id,
709
- },
710
- });
711
- return data;
712
- });
713
- this.badgeHasMinted = (id) => __awaiter(this, void 0, void 0, function* () {
714
- const { data } = yield this.request.get('/v1/badge/user_has_minted', {
715
- params: {
716
- user_id: id,
717
- },
718
- });
719
- return data;
720
- });
721
- this.mintBadge = (params) => __awaiter(this, void 0, void 0, function* () {
722
- const { data } = yield this.request.post('/v1/badge/mint', {
723
- code: params.code,
724
- user_id: params.userAddr,
725
- });
726
- return data;
727
- });
728
- this.userHasRequestedFaucet = (params) => __awaiter(this, void 0, void 0, function* () {
729
- const { data } = yield this.request.get('/v1/faucet/user_has_requested', {
730
- params,
731
- });
732
- return data;
733
- });
734
- this.requestFaucet = (params) => __awaiter(this, void 0, void 0, function* () {
735
- const { data } = yield this.request.post('/v1/faucet/request', Object.assign({}, params));
736
- return data;
737
- });
738
- this.gasSupportedPushType = (chainId) => __awaiter(this, void 0, void 0, function* () {
739
- const { data } = yield this.request.get('/v1/wallet/supported_push_type', Object.assign({ params: {
740
- chain_id: chainId,
741
- } }, this._getRequestOptions(chainId)));
742
- return data;
743
- });
744
- this.submitTx = (postData) => __awaiter(this, void 0, void 0, function* () {
745
- var _p;
746
- const { data } = yield this.request.post('/v1/wallet/submit_tx', Object.assign({}, postData), this._getRequestOptions((_p = getChainByNetwork(postData.tx.chainId)) === null || _p === void 0 ? void 0 : _p.serverId));
747
- return data;
748
- });
749
- this.getTxRequests = (ids) => __awaiter(this, void 0, void 0, function* () {
750
- const { data } = yield this.request.get('/v1/wallet/get_tx_requests', {
751
- params: {
752
- ids: Array.isArray(ids) ? ids.join(',') : ids,
753
- },
754
- });
755
- return data;
756
- });
757
- this.getTxRequest = (id) => __awaiter(this, void 0, void 0, function* () {
758
- const { data } = yield this.request.get('/v1/wallet/get_tx_request', {
759
- params: {
760
- id,
761
- },
762
- });
763
- return data;
764
- });
765
- this.withdrawTx = (reqId) => __awaiter(this, void 0, void 0, function* () {
766
- const { data } = yield this.request.post('/v1/wallet/withdraw_tx', {
767
- id: reqId,
768
- });
769
- return data;
770
- });
771
- this.retryPushTx = (reqId) => __awaiter(this, void 0, void 0, function* () {
772
- const { data } = yield this.request.post('/v1/wallet/retry_push_tx', {
773
- id: reqId,
774
- });
775
- return data;
776
- });
777
- this.mempoolChecks = (txId, chainId, node_info) => __awaiter(this, void 0, void 0, function* () {
778
- var _q;
779
- const { data } = yield this.request.get('/v1/wallet/mempool_checks', Object.assign({ params: {
780
- tx_id: txId,
781
- chain_id: chainId,
782
- node_info: node_info ? 1 : 0,
783
- } }, this._getRequestOptions((_q = getChainByNetwork(chainId)) === null || _q === void 0 ? void 0 : _q.serverId)));
784
- return data;
785
- });
786
- this.getPendingTxList = (params, options) => __awaiter(this, void 0, void 0, function* () {
787
- var _r;
788
- const data = yield this.asyncJob('/v1/wallet/get_pending_tx_list', Object.assign(Object.assign({ params }, this._getRequestOptions((_r = getChainByNetwork(params.chain_id)) === null || _r === void 0 ? void 0 : _r.serverId)), options));
789
- return data;
790
- });
791
- this.getLatestPreExec = (params) => __awaiter(this, void 0, void 0, function* () {
792
- const { data } = yield this.request.get('/v1/wallet/get_latest_pre_exec', {
793
- params,
794
- });
795
- return data;
796
- });
797
- this.walletSupportChain = (params) => __awaiter(this, void 0, void 0, function* () {
798
- const { data } = yield this.request.post('/v1/wallet/support_chain', params);
799
- return data;
800
- });
801
- this.walletSupportOrigin = (params) => __awaiter(this, void 0, void 0, function* () {
802
- const { data } = yield this.request.post('/v1/wallet/support_origin', params);
803
- return data;
804
- });
805
- this.walletSupportSelector = (params) => __awaiter(this, void 0, void 0, function* () {
806
- const { data } = yield this.request.post('/v1/wallet/support_selector', params);
807
- return data;
808
- });
809
- this.searchDapp = (params) => __awaiter(this, void 0, void 0, function* () {
810
- const { data } = yield this.request.get('/v1/dapp/search', { params });
811
- return data;
812
- });
813
- this.getDappsInfo = (params) => __awaiter(this, void 0, void 0, function* () {
814
- var _s;
815
- const { data } = yield this.request.get('/v1/dapp/list', {
816
- params: {
817
- ids: (_s = params === null || params === void 0 ? void 0 : params.ids) === null || _s === void 0 ? void 0 : _s.join(','),
818
- },
819
- });
820
- return data;
821
- });
822
- this.getDappHotTags = (params) => __awaiter(this, void 0, void 0, function* () {
823
- const { data } = yield this.request.get('/v1/dapp/hot_tags', {
824
- params,
825
- });
826
- return data;
827
- });
828
- this.getHotDapps = (params) => __awaiter(this, void 0, void 0, function* () {
829
- const { data } = yield this.request.get('/v1/dapp/hot_list', { params });
830
- return data;
831
- });
832
- this.getRabbyClaimText = (params) => __awaiter(this, void 0, void 0, function* () {
833
- const { data } = yield this.request.get('/v1/points/user/claim_text', {
834
- params,
835
- });
836
- return data;
837
- });
838
- this.getRabbySignatureText = (params) => __awaiter(this, void 0, void 0, function* () {
839
- const { data } = yield this.request.get('/v1/points/user/sign_text', {
840
- params,
841
- });
842
- return data;
843
- });
844
- this.getRabbyPoints = (params) => __awaiter(this, void 0, void 0, function* () {
845
- const { data } = yield this.request.get('/v1/points/user', { params });
846
- return data;
847
- });
848
- this.checkRabbyPointsInviteCode = (params) => __awaiter(this, void 0, void 0, function* () {
849
- const { data } = yield this.request.get('/v1/points/user/invite_code_exist', { params });
850
- return data;
851
- });
852
- this.setRabbyPointsInviteCode = (params) => __awaiter(this, void 0, void 0, function* () {
853
- const { data } = yield this.request.post('/v1/points/user/invite_code', params);
854
- return data;
855
- });
856
- this.checkRabbyPointClaimable = (params) => __awaiter(this, void 0, void 0, function* () {
857
- const { data } = yield this.request.get('/v1/points/user/claimable', {
858
- params,
859
- });
860
- return data;
861
- });
862
- this.getRabbyPointsSnapshot = (params) => __awaiter(this, void 0, void 0, function* () {
863
- const { data } = yield this.request.get('/v1/points/snapshot', { params });
864
- return data;
865
- });
866
- this.claimRabbyPointsSnapshot = (params) => __awaiter(this, void 0, void 0, function* () {
867
- const { data } = yield this.request.post('/v1/points/claim_snapshot', params);
868
- return data;
869
- });
870
- this.getRabbyPointsTopUsers = (params) => __awaiter(this, void 0, void 0, function* () {
871
- const { data } = yield this.request.get('/v1/points/top_user', { params });
872
- return data;
873
- });
874
- this.getRabbyPointsList = (params) => __awaiter(this, void 0, void 0, function* () {
875
- const { data } = yield this.request.get('/v1/points/campaign_list', {
876
- params,
877
- });
878
- return data;
879
- });
880
- this.claimRabbyPointsById = (params) => __awaiter(this, void 0, void 0, function* () {
881
- const { data } = yield this.request.post('/v1/points/claim_campaign', params);
882
- return data;
883
- });
884
- this.getSupportedChains = () => __awaiter(this, void 0, void 0, function* () {
885
- const { data } = yield this.request.get('/v1/wallet/supported_chains');
886
- return data;
887
- });
888
- if (store instanceof Promise) {
889
- store.then((resolvedStore) => {
890
- this.store = resolvedStore;
891
- });
892
- }
893
- else {
894
- this.store = store;
895
- }
896
- __classPrivateFieldSet(this, _OpenApiService_plugin, plugin, "f");
897
- __classPrivateFieldSet(this, _OpenApiService_adapter, adapter, "f");
898
- __classPrivateFieldSet(this, _OpenApiService_clientName, clientName, "f");
899
- __classPrivateFieldSet(this, _OpenApiService_clientVersion, clientVersion, "f");
900
- }
901
- initSync(options) {
902
- var _a, _b;
903
- (_b = (_a = __classPrivateFieldGet(this, _OpenApiService_plugin, "f")).onInitiate) === null || _b === void 0 ? void 0 : _b.call(_a, Object.assign({}, options));
904
- const request = axios.create({
905
- baseURL: this.store.host,
906
- adapter: __classPrivateFieldGet(this, _OpenApiService_adapter, "f"),
907
- headers: {
908
- 'X-Client': __classPrivateFieldGet(this, _OpenApiService_clientName, "f"),
909
- 'X-Version': __classPrivateFieldGet(this, _OpenApiService_clientVersion, "f"),
910
- },
911
- });
912
- // sign after rateLimit, timestamp is the latest
913
- request.interceptors.request.use((config) => __awaiter(this, void 0, void 0, function* () {
914
- const { method, url, params } = genSignParams(config);
915
- yield __classPrivateFieldGet(this, _OpenApiService_plugin, "f").onSignRequest({
916
- axiosRequestConfig: config,
917
- parsed: { method, url, params },
918
- });
919
- return config;
920
- }));
921
- this.request = rateLimit(request, { maxRPS });
922
- this.request.interceptors.response.use((response) => {
923
- var _a, _b, _c, _d;
924
- 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);
925
- 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);
926
- if (code && code !== 200) {
927
- if (msg) {
928
- let err;
929
- try {
930
- err = new Error(JSON.parse(msg));
931
- }
932
- catch (e) {
933
- err = new Error(msg);
934
- }
935
- throw err;
936
- }
937
- throw new Error(typeof response.data === 'string'
938
- ? response.data
939
- : JSON.stringify(response.data));
940
- }
941
- return response;
942
- });
943
- this._mountMethods();
944
- }
945
- }
946
- _OpenApiService_adapter = new WeakMap(), _OpenApiService_plugin = new WeakMap(), _OpenApiService_clientName = new WeakMap(), _OpenApiService_clientVersion = new WeakMap();
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
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
+ if (kind === "m") throw new TypeError("Private method is not writable");
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
+ };
16
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
17
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
18
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
+ };
21
+ var _OpenApiService_adapter, _OpenApiService_plugin, _OpenApiService_clientName, _OpenApiService_clientVersion;
22
+ import axios from 'axios';
23
+ import rateLimit from 'axios-rate-limit';
24
+ import { ethErrors } from 'eth-rpc-errors';
25
+ import { CHAINS, genSignParams, getChain, getChainByNetwork, sleep, } from './utils';
26
+ import { ASYNC_JOB_RETRY_DELAY, ASYNC_JOB_TIMEOUT } from './const';
27
+ import { omit } from 'lodash';
28
+ const maxRPS = 500;
29
+ export class OpenApiService {
30
+ constructor(_a) {
31
+ var _b;
32
+ var { store, plugin, adapter, clientName = 'Rabby', clientVersion = (_b = process.env.release) !== null && _b !== void 0 ? _b : '0.0.0', } = _a;
33
+ _OpenApiService_adapter.set(this, void 0);
34
+ _OpenApiService_plugin.set(this, void 0);
35
+ _OpenApiService_clientName.set(this, void 0);
36
+ _OpenApiService_clientVersion.set(this, void 0);
37
+ this.setHost = (host) => __awaiter(this, void 0, void 0, function* () {
38
+ this.store.host = host;
39
+ yield this.init();
40
+ });
41
+ this.setHostSync = (host) => {
42
+ this.store.host = host;
43
+ this.initSync();
44
+ };
45
+ this.getHost = () => {
46
+ return this.store.host;
47
+ };
48
+ this.setTestnetHost = (host) => __awaiter(this, void 0, void 0, function* () {
49
+ this.store.testnetHost = host;
50
+ });
51
+ this.getTestnetHost = () => {
52
+ return this.store.testnetHost;
53
+ };
54
+ this.ethRpc = () => __awaiter(this, void 0, void 0, function* () {
55
+ throw ethErrors.provider.disconnected();
56
+ });
57
+ this.init = (options) => __awaiter(this, void 0, void 0, function* () {
58
+ var _c, _d;
59
+ options = typeof options === 'string' ? { webHf: options } : options;
60
+ yield ((_d = (_c = __classPrivateFieldGet(this, _OpenApiService_plugin, "f")).onInitiateAsync) === null || _d === void 0 ? void 0 : _d.call(_c, Object.assign({}, options)));
61
+ this.initSync(Object.assign({}, options));
62
+ });
63
+ this.asyncJob = (url, options) => {
64
+ const _option = Object.assign({ timeout: ASYNC_JOB_TIMEOUT, retryDelay: ASYNC_JOB_RETRY_DELAY }, options);
65
+ const startTime = +new Date();
66
+ return this.request(url, omit(Object.assign({ method: 'GET' }, _option), 'retryDelay')).then((res) => {
67
+ const data = res.data;
68
+ if (data.result) {
69
+ return data.result.data;
70
+ }
71
+ const deltaTime = +new Date() - startTime;
72
+ _option.timeout = _option.timeout - deltaTime - _option.retryDelay;
73
+ return sleep(_option.retryDelay, _option.signal).then(() => this.asyncJob(url, _option));
74
+ });
75
+ };
76
+ this._getRequestOptions = (chainId) => {
77
+ if (!chainId) {
78
+ return;
79
+ }
80
+ const testnetHost = this.getTestnetHost();
81
+ if (!testnetHost) {
82
+ return;
83
+ }
84
+ const chain = getChain(chainId);
85
+ if (!(chain === null || chain === void 0 ? void 0 : chain.isTestnet)) {
86
+ return;
87
+ }
88
+ return {
89
+ baseURL: testnetHost,
90
+ };
91
+ };
92
+ this._mountMethods = () => {
93
+ this.ethRpc = (chain_id, { origin = 'rabby', method, params }) => {
94
+ return this.request
95
+ .post(`/v1/wallet/eth_rpc?origin=${origin}&method=${method}`, {
96
+ chain_id,
97
+ method,
98
+ params,
99
+ }, this._getRequestOptions(chain_id))
100
+ .then(({ data }) => {
101
+ if (data === null || data === void 0 ? void 0 : data.error) {
102
+ throw data.error;
103
+ }
104
+ return data === null || data === void 0 ? void 0 : data.result;
105
+ });
106
+ };
107
+ };
108
+ this.getRecommendChains = (address, origin) => __awaiter(this, void 0, void 0, function* () {
109
+ const { data } = yield this.request.get('/v1/wallet/recommend_chains', {
110
+ params: {
111
+ user_addr: address,
112
+ origin,
113
+ },
114
+ });
115
+ return data;
116
+ });
117
+ this.getTotalBalance = (address) => __awaiter(this, void 0, void 0, function* () {
118
+ const { data } = yield this.request.get('/v1/user/total_balance', {
119
+ params: {
120
+ id: address,
121
+ },
122
+ });
123
+ return Object.assign(Object.assign({}, data), { chain_list: data.chain_list.filter((item) => !!Object.values(CHAINS).find((chain) => chain.serverId === item.id)) });
124
+ });
125
+ this.getPendingCount = (address) => __awaiter(this, void 0, void 0, function* () {
126
+ const { data } = yield this.request.get('/v1/wallet/pending_tx_count', {
127
+ params: {
128
+ user_addr: address,
129
+ },
130
+ });
131
+ return data;
132
+ });
133
+ this.checkOrigin = (address, origin) => __awaiter(this, void 0, void 0, function* () {
134
+ const { data } = yield this.request.post('/v1/wallet/check_origin', {
135
+ user_addr: address,
136
+ origin,
137
+ });
138
+ return data;
139
+ });
140
+ this.checkText = (address, origin, text) => __awaiter(this, void 0, void 0, function* () {
141
+ const { data } = yield this.request.post('/v1/wallet/check_text', {
142
+ user_addr: address,
143
+ origin,
144
+ text,
145
+ });
146
+ return data;
147
+ });
148
+ this.checkTx = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
149
+ var _e;
150
+ const { data } = yield this.request.post('/v1/wallet/check_tx', {
151
+ user_addr: address,
152
+ origin,
153
+ tx,
154
+ update_nonce,
155
+ }, this._getRequestOptions((_e = getChainByNetwork(tx.chainId)) === null || _e === void 0 ? void 0 : _e.serverId));
156
+ return data;
157
+ });
158
+ this.preExecTx = ({ tx, origin, address, updateNonce = false, pending_tx_list = [], }) => __awaiter(this, void 0, void 0, function* () {
159
+ var _f;
160
+ const { data } = yield this.request.post('/v1/wallet/pre_exec_tx', {
161
+ tx,
162
+ user_addr: address,
163
+ origin,
164
+ update_nonce: updateNonce,
165
+ pending_tx_list,
166
+ }, this._getRequestOptions((_f = getChainByNetwork(tx.chainId)) === null || _f === void 0 ? void 0 : _f.serverId));
167
+ return data;
168
+ });
169
+ this.historyGasUsed = (params) => __awaiter(this, void 0, void 0, function* () {
170
+ var _g, _h;
171
+ const { data } = yield this.request.post('/v1/wallet/history_tx_used_gas', Object.assign({}, params), this._getRequestOptions((_h = getChainByNetwork((_g = params === null || params === void 0 ? void 0 : params.tx) === null || _g === void 0 ? void 0 : _g.chainId)) === null || _h === void 0 ? void 0 : _h.serverId));
172
+ return data;
173
+ });
174
+ this.pendingTxList = (tx, origin, address, update_nonce = false) => __awaiter(this, void 0, void 0, function* () {
175
+ var _j;
176
+ const { data } = yield this.request.post('/v1/wallet/pending_tx_list', {
177
+ tx,
178
+ user_addr: address,
179
+ origin,
180
+ update_nonce,
181
+ }, this._getRequestOptions((_j = getChainByNetwork(tx.chainId)) === null || _j === void 0 ? void 0 : _j.serverId));
182
+ return data;
183
+ });
184
+ this.traceTx = (txId, traceId, chainId) => __awaiter(this, void 0, void 0, function* () {
185
+ const { data } = yield this.request.post('/v1/wallet/trace_tx', {
186
+ tx_id: txId,
187
+ trace_id: traceId,
188
+ chain_id: chainId,
189
+ }, this._getRequestOptions(chainId));
190
+ return data;
191
+ });
192
+ this.pushTx = (tx, traceId) => __awaiter(this, void 0, void 0, function* () {
193
+ var _k;
194
+ const { data } = yield this.request.post('/v1/wallet/push_tx', {
195
+ tx,
196
+ trace_id: traceId,
197
+ }, this._getRequestOptions((_k = getChainByNetwork(tx.chainId)) === null || _k === void 0 ? void 0 : _k.serverId));
198
+ return data;
199
+ });
200
+ this.explainText = (origin, address, text) => __awaiter(this, void 0, void 0, function* () {
201
+ const { data } = yield this.request.post('/v1/wallet/explain_text', {
202
+ user_addr: address,
203
+ origin,
204
+ text,
205
+ });
206
+ return data;
207
+ });
208
+ this.gasMarket = (chainId, customGas) => __awaiter(this, void 0, void 0, function* () {
209
+ const { data } = yield this.request.get('/v1/wallet/gas_market', Object.assign({ params: {
210
+ chain_id: chainId,
211
+ custom_price: customGas,
212
+ } }, this._getRequestOptions(chainId)));
213
+ return data;
214
+ });
215
+ this.getTx = (chainId, hash, gasPrice) => __awaiter(this, void 0, void 0, function* () {
216
+ const { data } = yield this.request.get('/v1/wallet/get_tx', Object.assign({ params: {
217
+ chain_id: chainId,
218
+ gas_price: gasPrice,
219
+ tx_id: hash,
220
+ } }, this._getRequestOptions(chainId)));
221
+ return data;
222
+ });
223
+ this.getEnsAddressByName = (name) => __awaiter(this, void 0, void 0, function* () {
224
+ const { data } = yield this.request.get('/v1/wallet/ens', {
225
+ params: {
226
+ text: name,
227
+ },
228
+ });
229
+ return data;
230
+ });
231
+ this.searchToken = (id, q, chainId, is_all = false) => __awaiter(this, void 0, void 0, function* () {
232
+ const { data } = yield this.request.get('/v1/user/token_search', Object.assign({ params: {
233
+ id,
234
+ q,
235
+ has_balance: false,
236
+ is_all,
237
+ chain_id: chainId,
238
+ } }, this._getRequestOptions(chainId)));
239
+ return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
240
+ });
241
+ this.searchSwapToken = (id, chainId, q, is_all = false) => __awaiter(this, void 0, void 0, function* () {
242
+ const { data } = yield this.request.get('/v1/user/token_search', Object.assign({ params: {
243
+ id,
244
+ chain_id: chainId,
245
+ q,
246
+ is_all,
247
+ } }, this._getRequestOptions(chainId)));
248
+ return data;
249
+ });
250
+ this.getToken = (id, chainId, tokenId) => __awaiter(this, void 0, void 0, function* () {
251
+ const { data } = yield this.request.get('/v1/user/token', Object.assign({ params: {
252
+ id,
253
+ chain_id: chainId,
254
+ token_id: tokenId,
255
+ } }, this._getRequestOptions(chainId)));
256
+ return data;
257
+ });
258
+ this.getCachedTokenList = (id) => __awaiter(this, void 0, void 0, function* () {
259
+ const { data } = yield this.request.get('/v1/user/cache_token_list', {
260
+ params: {
261
+ id,
262
+ },
263
+ });
264
+ return data;
265
+ });
266
+ this.listToken = (id, chainId, isAll = false) => __awaiter(this, void 0, void 0, function* () {
267
+ const { data } = yield this.request.get('/v1/user/token_list', Object.assign({ params: {
268
+ id,
269
+ is_all: isAll,
270
+ chain_id: chainId,
271
+ } }, this._getRequestOptions(chainId)));
272
+ return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
273
+ });
274
+ this.getHistoryTokenList = (params) => __awaiter(this, void 0, void 0, function* () {
275
+ const { data } = yield this.request.get('/v1/user/history_token_list', Object.assign({ params: {
276
+ id: params.id,
277
+ chain_id: params.chainId,
278
+ time_at: params.timeAt,
279
+ date_at: params.dateAt,
280
+ } }, this._getRequestOptions(params.chainId)));
281
+ return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
282
+ });
283
+ this._customListToken = (uuids, id, isTestnet = false) => __awaiter(this, void 0, void 0, function* () {
284
+ if (!(uuids === null || uuids === void 0 ? void 0 : uuids.length) || !id) {
285
+ return [];
286
+ }
287
+ const { data } = yield this.request.post('/v1/user/specific_token_list', {
288
+ id,
289
+ uuids,
290
+ }, isTestnet && this.store.testnetHost
291
+ ? { baseURL: this.store.testnetHost }
292
+ : undefined);
293
+ return data === null || data === void 0 ? void 0 : data.filter((token) => getChain(token.chain));
294
+ });
295
+ this.customListToken = (uuids, id) => __awaiter(this, void 0, void 0, function* () {
296
+ const mainnetIds = [];
297
+ const testnetIds = [];
298
+ uuids.forEach((uuid) => {
299
+ const serverId = uuid.split(':')[0];
300
+ const chain = getChain(serverId);
301
+ if (chain === null || chain === void 0 ? void 0 : chain.isTestnet) {
302
+ testnetIds.push(uuid);
303
+ }
304
+ else {
305
+ mainnetIds.push(uuid);
306
+ }
307
+ });
308
+ const res = yield Promise.all([
309
+ this._customListToken(mainnetIds, id),
310
+ this._customListToken(testnetIds, id, true),
311
+ ]);
312
+ return res.flat();
313
+ });
314
+ this.listChainAssets = (id) => __awaiter(this, void 0, void 0, function* () {
315
+ const { data } = yield this.request.get('/v1/user/simple_protocol_list', {
316
+ params: {
317
+ id,
318
+ },
319
+ });
320
+ return data;
321
+ });
322
+ this.listNFT = (id, isAll = true) => __awaiter(this, void 0, void 0, function* () {
323
+ const { data } = yield this.request.get('/v1/user/nft_list', {
324
+ params: {
325
+ id,
326
+ is_all: isAll,
327
+ },
328
+ });
329
+ return data === null || data === void 0 ? void 0 : data.filter((nft) => getChain(nft.chain));
330
+ });
331
+ this.listCollection = (params) => __awaiter(this, void 0, void 0, function* () {
332
+ const { data } = yield this.request.get('/v1/nft/collections', {
333
+ params,
334
+ });
335
+ return data;
336
+ });
337
+ this.listTxHisotry = (params) => __awaiter(this, void 0, void 0, function* () {
338
+ const { data } = yield this.request.get('/v1/user/history_list', Object.assign({ params }, this._getRequestOptions(params.chain_id)));
339
+ return data;
340
+ });
341
+ this.getAllTxHistory = (params, options) => __awaiter(this, void 0, void 0, function* () {
342
+ const data = yield this.asyncJob('/v1/user/history_all_list', Object.assign({ method: 'GET', params }, options));
343
+ return data;
344
+ });
345
+ this.tokenPrice = (tokenName) => __awaiter(this, void 0, void 0, function* () {
346
+ var _l;
347
+ const { data } = yield this.request.get('/v1/token/price_change', Object.assign({ params: {
348
+ token: tokenName,
349
+ } }, this._getRequestOptions((_l = tokenName === null || tokenName === void 0 ? void 0 : tokenName.split(':')) === null || _l === void 0 ? void 0 : _l[0])));
350
+ return data;
351
+ });
352
+ this.tokenAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
353
+ const { data } = yield this.request.get('/v1/user/token_authorized_list', Object.assign({ params: {
354
+ id,
355
+ chain_id,
356
+ } }, this._getRequestOptions(chain_id)));
357
+ return data;
358
+ });
359
+ this.userNFTAuthorizedList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
360
+ const { data } = yield this.request.get('/v1/user/nft_authorized_list', Object.assign({ params: {
361
+ id,
362
+ chain_id,
363
+ } }, this._getRequestOptions(chain_id)));
364
+ return data;
365
+ });
366
+ this.getDEXList = (chain_id) => __awaiter(this, void 0, void 0, function* () {
367
+ const { data } = yield this.request.get('/v1/wallet/swap_dex_list', Object.assign({ params: {
368
+ chain_id,
369
+ } }, this._getRequestOptions(chain_id)));
370
+ return data;
371
+ });
372
+ this.getSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
373
+ 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)));
374
+ return data;
375
+ });
376
+ this.getSwapTokenList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
377
+ const { data } = yield this.request.get('/v1/wallet/swap_token_list', Object.assign({ params: {
378
+ id,
379
+ chain_id: chainId,
380
+ is_all: false,
381
+ } }, this._getRequestOptions(chainId)));
382
+ return data;
383
+ });
384
+ this.postGasStationOrder = (params) => __awaiter(this, void 0, void 0, function* () {
385
+ const { data } = yield this.request.post('/v1/wallet/gas_station_order', {
386
+ order: {
387
+ user_addr: params.userAddr,
388
+ from_chain_id: params.fromChainId,
389
+ from_tx_id: params.fromTxId,
390
+ from_token_id: params.fromTokenId,
391
+ from_token_amount: params.fromTokenAmount,
392
+ to_chain_id: params.toChainId,
393
+ to_token_amount: params.toTokenAmount,
394
+ from_usd_value: params.fromUsdValue,
395
+ },
396
+ }, this._getRequestOptions(params.fromChainId));
397
+ return data;
398
+ });
399
+ this.getGasStationChainBalance = (chain_id, addr) => __awaiter(this, void 0, void 0, function* () {
400
+ const { data } = yield this.request.get('/v1/wallet/gas_station_usd_value', Object.assign({ params: {
401
+ chain_id,
402
+ addr,
403
+ } }, this._getRequestOptions(chain_id)));
404
+ return data;
405
+ });
406
+ this.getGasStationTokenList = () => __awaiter(this, void 0, void 0, function* () {
407
+ const { data } = yield this.request.get('/v1/wallet/gas_station_token_list');
408
+ return data;
409
+ });
410
+ this.explainTypedData = (user_addr, origin, data) => __awaiter(this, void 0, void 0, function* () {
411
+ const { data: resData } = yield this.request.post('/v1/wallet/explain_typed_data', {
412
+ user_addr,
413
+ origin,
414
+ data,
415
+ });
416
+ return resData;
417
+ });
418
+ this.checkTypedData = (user_addr, origin, data) => __awaiter(this, void 0, void 0, function* () {
419
+ const { data: resData } = yield this.request.post('/v1/wallet/check_typed_data', {
420
+ user_addr,
421
+ origin,
422
+ data,
423
+ });
424
+ return resData;
425
+ });
426
+ this.approvalStatus = (id) => __awaiter(this, void 0, void 0, function* () {
427
+ const { data } = yield this.request.get('/v1/user/approval_status', {
428
+ params: {
429
+ id,
430
+ },
431
+ });
432
+ return data;
433
+ });
434
+ this.usedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
435
+ const { data } = yield this.request.get('/v1/user/used_chain_list', {
436
+ params: {
437
+ id,
438
+ },
439
+ });
440
+ return data;
441
+ });
442
+ this.getLatestVersion = () => __awaiter(this, void 0, void 0, function* () {
443
+ const { data } = yield this.request.get('/v1/wallet/version');
444
+ return data;
445
+ });
446
+ this.addOriginFeedback = (params) => __awaiter(this, void 0, void 0, function* () {
447
+ const { data } = yield this.request.post('/v1/wallet/add_origin_feedback', {
448
+ user_addr: params.user_addr,
449
+ origin: params.origin,
450
+ is_safe: params.is_safe,
451
+ });
452
+ return data;
453
+ });
454
+ this.getProtocolList = (addr) => __awaiter(this, void 0, void 0, function* () {
455
+ const { data } = yield this.request.get('/v1/user/protocol_list', {
456
+ params: {
457
+ id: addr,
458
+ },
459
+ });
460
+ return data;
461
+ });
462
+ this.getComplexProtocolList = (addr) => __awaiter(this, void 0, void 0, function* () {
463
+ const { data } = yield this.request.get('/v1/user/complex_protocol_list', {
464
+ params: {
465
+ id: addr,
466
+ },
467
+ });
468
+ return data;
469
+ });
470
+ this.getProtocol = ({ addr, id, }) => __awaiter(this, void 0, void 0, function* () {
471
+ const { data } = yield this.request.get('/v1/user/protocol', {
472
+ params: {
473
+ id: addr,
474
+ protocol_id: id,
475
+ },
476
+ });
477
+ return data;
478
+ });
479
+ this.getHistoryProtocol = ({ addr, id, timeAt, dateAt, }) => __awaiter(this, void 0, void 0, function* () {
480
+ const { data } = yield this.request.get('/v1/user/history_protocol', {
481
+ params: {
482
+ id: addr,
483
+ protocol_id: id,
484
+ time_at: timeAt,
485
+ date_at: dateAt,
486
+ },
487
+ });
488
+ return data;
489
+ });
490
+ this.getTokenHistoryPrice = ({ chainId, id, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
491
+ const { data } = yield this.request.get('/v1/token/history_price', Object.assign({ params: {
492
+ chain_id: chainId,
493
+ id,
494
+ time_at: timeAt,
495
+ } }, this._getRequestOptions(chainId)));
496
+ return data;
497
+ });
498
+ this.getTokenHistoryDict = ({ chainId, ids, timeAt, }) => __awaiter(this, void 0, void 0, function* () {
499
+ const { data } = yield this.request.get('/v1/token/history_price_dict', Object.assign({ params: {
500
+ chain_id: chainId,
501
+ ids,
502
+ time_at: timeAt,
503
+ } }, this._getRequestOptions(chainId)));
504
+ return data;
505
+ });
506
+ this.getNetCurve = (addr) => __awaiter(this, void 0, void 0, function* () {
507
+ const { data } = yield this.request.get('/v1/user/total_net_curve', {
508
+ params: {
509
+ id: addr,
510
+ },
511
+ });
512
+ return data;
513
+ });
514
+ this.getChainList = () => __awaiter(this, void 0, void 0, function* () {
515
+ const { data } = yield this.request.get('/v1/chain/list');
516
+ return data;
517
+ });
518
+ this.getCEXSwapQuote = (params) => __awaiter(this, void 0, void 0, function* () {
519
+ 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)));
520
+ return data;
521
+ });
522
+ this.getSwapTradeList = (params) => __awaiter(this, void 0, void 0, function* () {
523
+ const { data } = yield this.request.get('/v1/wallet/swap_trade_list', {
524
+ params,
525
+ });
526
+ return data;
527
+ });
528
+ this.postSwap = (params) => __awaiter(this, void 0, void 0, function* () {
529
+ var _m, _o;
530
+ const { data } = yield this.request.post('/v1/wallet/swap_trade', params, this._getRequestOptions((_o = getChainByNetwork((_m = params === null || params === void 0 ? void 0 : params.tx) === null || _m === void 0 ? void 0 : _m.chainId)) === null || _o === void 0 ? void 0 : _o.serverId));
531
+ return data;
532
+ });
533
+ this.checkSlippage = (params) => __awaiter(this, void 0, void 0, function* () {
534
+ 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)));
535
+ return data;
536
+ });
537
+ this.getOriginPopularityLevel = (origin) => __awaiter(this, void 0, void 0, function* () {
538
+ const { data } = yield this.request.get('/v1/engine/origin/popularity_level', {
539
+ params: {
540
+ origin,
541
+ },
542
+ });
543
+ return data;
544
+ });
545
+ this.getOriginIsScam = (origin, source) => __awaiter(this, void 0, void 0, function* () {
546
+ const { data } = yield this.request.get('/v1/engine/origin/is_scam', {
547
+ params: {
548
+ origin,
549
+ source,
550
+ },
551
+ });
552
+ return data;
553
+ });
554
+ this.getOriginThirdPartyCollectList = (origin) => __awaiter(this, void 0, void 0, function* () {
555
+ const { data } = yield this.request.get('/v1/engine/origin/third_party_collect_list', {
556
+ params: {
557
+ origin,
558
+ },
559
+ });
560
+ return data;
561
+ });
562
+ this.getSummarizedAssetList = (id, chain_id) => __awaiter(this, void 0, void 0, function* () {
563
+ const { data } = yield this.request.get('/v1/user/summarized_asset_list', Object.assign({ params: {
564
+ id,
565
+ chain_id,
566
+ } }, this._getRequestOptions(chain_id)));
567
+ return data;
568
+ });
569
+ this.unexpectedAddrList = ({ chainId, tx, origin, addr, }) => __awaiter(this, void 0, void 0, function* () {
570
+ const { data } = yield this.request.post('/v1/engine/addr/unexpected_list', {
571
+ chain_id: chainId,
572
+ tx,
573
+ origin,
574
+ user_addr: addr,
575
+ }, this._getRequestOptions(chainId));
576
+ return data;
577
+ });
578
+ this.parseTx = ({ chainId, tx, origin, addr, }) => __awaiter(this, void 0, void 0, function* () {
579
+ const { data } = yield this.request.post('/v1/engine/action/parse_tx', {
580
+ chain_id: chainId,
581
+ tx,
582
+ origin,
583
+ user_addr: addr,
584
+ }, this._getRequestOptions(chainId));
585
+ return data;
586
+ });
587
+ this.isSuspiciousToken = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
588
+ const { data } = yield this.request.get('/v1/engine/token/is_suspicious', Object.assign({ params: {
589
+ chain_id: chainId,
590
+ id,
591
+ } }, this._getRequestOptions(chainId)));
592
+ return data;
593
+ });
594
+ this.depositCexSupport = (id, chainId, cexId) => __awaiter(this, void 0, void 0, function* () {
595
+ const { data } = yield this.request.get('/v1/engine/token/deposit_cex_support', Object.assign({ params: {
596
+ chain_id: chainId,
597
+ id,
598
+ cex_id: cexId,
599
+ } }, this._getRequestOptions(chainId)));
600
+ return data;
601
+ });
602
+ // Token 可充值的 CEX 列表
603
+ this.depositCexList = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
604
+ const { data } = yield this.request.get('/v1/engine/token/deposit_cex_list', Object.assign({ params: {
605
+ chain_id: chainId,
606
+ id,
607
+ } }, this._getRequestOptions(chainId)));
608
+ return data;
609
+ });
610
+ // 合约信用分
611
+ this.getContractCredit = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
612
+ const { data } = yield this.request.get('/v1/engine/contract/credit', Object.assign({ params: {
613
+ chain_id: chainId,
614
+ id,
615
+ } }, this._getRequestOptions(chainId)));
616
+ return data;
617
+ });
618
+ // 是否跟地址交互过
619
+ this.hasInteraction = (addr, chainId, contractId) => __awaiter(this, void 0, void 0, function* () {
620
+ const { data } = yield this.request.get('/v1/engine/contract/has_interaction', Object.assign({ params: {
621
+ chain_id: chainId,
622
+ user_addr: addr,
623
+ contract_id: contractId,
624
+ } }, this._getRequestOptions(chainId)));
625
+ return data;
626
+ });
627
+ // 授权风险敞口
628
+ this.tokenApproveExposure = (id, chainId) => __awaiter(this, void 0, void 0, function* () {
629
+ const { data } = yield this.request.get('/v1/engine/contract/token_approval_exposure', Object.assign({ params: {
630
+ chain_id: chainId,
631
+ id,
632
+ } }, this._getRequestOptions(chainId)));
633
+ return data;
634
+ });
635
+ // 地址描述
636
+ this.addrDesc = (id) => __awaiter(this, void 0, void 0, function* () {
637
+ const { data } = yield this.request.get('/v1/engine/addr/desc', {
638
+ params: {
639
+ id,
640
+ },
641
+ });
642
+ return data;
643
+ });
644
+ // 两个地址是否发生过转账
645
+ this.hasTransfer = (chainId, from, to) => __awaiter(this, void 0, void 0, function* () {
646
+ const { data } = yield this.request.get('/v1/engine/addr/has_transfer', Object.assign({ params: {
647
+ chain_id: chainId,
648
+ from_addr: from,
649
+ to_addr: to,
650
+ } }, this._getRequestOptions(chainId)));
651
+ return data;
652
+ });
653
+ this.isTokenContract = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
654
+ const { data } = yield this.request.get('/v1/engine/contract/is_token', Object.assign({ params: {
655
+ id,
656
+ chain_id: chainId,
657
+ } }, this._getRequestOptions(chainId)));
658
+ return data;
659
+ });
660
+ this.addrUsedChainList = (id) => __awaiter(this, void 0, void 0, function* () {
661
+ const { data } = yield this.request.get('/v1/engine/addr/used_chain_list', {
662
+ params: { id },
663
+ });
664
+ return data;
665
+ });
666
+ this.getTokenNFTExposure = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
667
+ const { data } = yield this.request.get('/v1/engine/contract/top_nft_approval_exposure', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
668
+ return data;
669
+ });
670
+ this.getCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
671
+ const { data } = yield this.request.get('/v1/engine/collection', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
672
+ return data;
673
+ });
674
+ this.isSuspiciousCollection = (chainId, id) => __awaiter(this, void 0, void 0, function* () {
675
+ const { data } = yield this.request.get('/v1/engine/collection/is_suspicious', Object.assign({ params: { chain_id: chainId, id } }, this._getRequestOptions(chainId)));
676
+ return data;
677
+ });
678
+ this.isOriginVerified = (origin) => __awaiter(this, void 0, void 0, function* () {
679
+ const { data } = yield this.request.get('/v1/engine/origin/is_verified', {
680
+ params: { origin },
681
+ });
682
+ return data;
683
+ });
684
+ this.parseTypedData = ({ typedData, origin, address, }) => __awaiter(this, void 0, void 0, function* () {
685
+ const { data } = yield this.request.post('/v1/engine/action/parse_typed_data', {
686
+ typed_data: typedData,
687
+ origin,
688
+ user_addr: address,
689
+ });
690
+ return data;
691
+ });
692
+ this.parseText = ({ text, origin, address, }) => __awaiter(this, void 0, void 0, function* () {
693
+ const { data } = yield this.request.post('/v1/engine/action/parse_text', {
694
+ text,
695
+ origin,
696
+ user_addr: address,
697
+ });
698
+ return data;
699
+ });
700
+ this.collectionList = ({ id, chainId, isAll, }) => __awaiter(this, void 0, void 0, function* () {
701
+ const { data } = yield this.request.get('/v1/user/collection_list', Object.assign({ params: {
702
+ id,
703
+ chain_id: chainId,
704
+ is_all: isAll,
705
+ } }, this._getRequestOptions(chainId)));
706
+ return data;
707
+ });
708
+ this.gasPriceStats = (chainId) => __awaiter(this, void 0, void 0, function* () {
709
+ const { data } = yield this.request.get('/v1/wallet/gas_price_stats', Object.assign({ params: {
710
+ chain_id: chainId,
711
+ } }, this._getRequestOptions(chainId)));
712
+ return data;
713
+ });
714
+ this.badgeHasClaimed = (id) => __awaiter(this, void 0, void 0, function* () {
715
+ const { data } = yield this.request.get('/v1/badge/code/user_has_claimed', {
716
+ params: {
717
+ user_id: id,
718
+ },
719
+ });
720
+ return data;
721
+ });
722
+ this.badgeHasMinted = (id) => __awaiter(this, void 0, void 0, function* () {
723
+ const { data } = yield this.request.get('/v1/badge/user_has_minted', {
724
+ params: {
725
+ user_id: id,
726
+ },
727
+ });
728
+ return data;
729
+ });
730
+ this.mintBadge = (params) => __awaiter(this, void 0, void 0, function* () {
731
+ const { data } = yield this.request.post('/v1/badge/mint', {
732
+ code: params.code,
733
+ user_id: params.userAddr,
734
+ });
735
+ return data;
736
+ });
737
+ this.userHasRequestedFaucet = (params) => __awaiter(this, void 0, void 0, function* () {
738
+ const { data } = yield this.request.get('/v1/faucet/user_has_requested', {
739
+ params,
740
+ });
741
+ return data;
742
+ });
743
+ this.requestFaucet = (params) => __awaiter(this, void 0, void 0, function* () {
744
+ const { data } = yield this.request.post('/v1/faucet/request', Object.assign({}, params));
745
+ return data;
746
+ });
747
+ this.gasSupportedPushType = (chainId) => __awaiter(this, void 0, void 0, function* () {
748
+ const { data } = yield this.request.get('/v1/wallet/supported_push_type', Object.assign({ params: {
749
+ chain_id: chainId,
750
+ } }, this._getRequestOptions(chainId)));
751
+ return data;
752
+ });
753
+ this.submitTx = (postData) => __awaiter(this, void 0, void 0, function* () {
754
+ var _p;
755
+ const { data } = yield this.request.post('/v1/wallet/submit_tx', Object.assign({}, postData), this._getRequestOptions((_p = getChainByNetwork(postData.tx.chainId)) === null || _p === void 0 ? void 0 : _p.serverId));
756
+ return data;
757
+ });
758
+ this.getTxRequests = (ids) => __awaiter(this, void 0, void 0, function* () {
759
+ const { data } = yield this.request.get('/v1/wallet/get_tx_requests', {
760
+ params: {
761
+ ids: Array.isArray(ids) ? ids.join(',') : ids,
762
+ },
763
+ });
764
+ return data;
765
+ });
766
+ this.getTxRequest = (id) => __awaiter(this, void 0, void 0, function* () {
767
+ const { data } = yield this.request.get('/v1/wallet/get_tx_request', {
768
+ params: {
769
+ id,
770
+ },
771
+ });
772
+ return data;
773
+ });
774
+ this.withdrawTx = (reqId) => __awaiter(this, void 0, void 0, function* () {
775
+ const { data } = yield this.request.post('/v1/wallet/withdraw_tx', {
776
+ id: reqId,
777
+ });
778
+ return data;
779
+ });
780
+ this.retryPushTx = (reqId) => __awaiter(this, void 0, void 0, function* () {
781
+ const { data } = yield this.request.post('/v1/wallet/retry_push_tx', {
782
+ id: reqId,
783
+ });
784
+ return data;
785
+ });
786
+ this.mempoolChecks = (txId, chainId, node_info) => __awaiter(this, void 0, void 0, function* () {
787
+ var _q;
788
+ const { data } = yield this.request.get('/v1/wallet/mempool_checks', Object.assign({ params: {
789
+ tx_id: txId,
790
+ chain_id: chainId,
791
+ node_info: node_info ? 1 : 0,
792
+ } }, this._getRequestOptions((_q = getChainByNetwork(chainId)) === null || _q === void 0 ? void 0 : _q.serverId)));
793
+ return data;
794
+ });
795
+ this.getPendingTxList = (params, options) => __awaiter(this, void 0, void 0, function* () {
796
+ var _r;
797
+ const data = yield this.asyncJob('/v1/wallet/get_pending_tx_list', Object.assign(Object.assign({ params }, this._getRequestOptions((_r = getChainByNetwork(params.chain_id)) === null || _r === void 0 ? void 0 : _r.serverId)), options));
798
+ return data;
799
+ });
800
+ this.getLatestPreExec = (params) => __awaiter(this, void 0, void 0, function* () {
801
+ const { data } = yield this.request.get('/v1/wallet/get_latest_pre_exec', {
802
+ params,
803
+ });
804
+ return data;
805
+ });
806
+ this.walletSupportChain = (params) => __awaiter(this, void 0, void 0, function* () {
807
+ const { data } = yield this.request.post('/v1/wallet/support_chain', params);
808
+ return data;
809
+ });
810
+ this.walletSupportOrigin = (params) => __awaiter(this, void 0, void 0, function* () {
811
+ const { data } = yield this.request.post('/v1/wallet/support_origin', params);
812
+ return data;
813
+ });
814
+ this.walletSupportSelector = (params) => __awaiter(this, void 0, void 0, function* () {
815
+ const { data } = yield this.request.post('/v1/wallet/support_selector', params);
816
+ return data;
817
+ });
818
+ this.searchDapp = (params) => __awaiter(this, void 0, void 0, function* () {
819
+ const { data } = yield this.request.get('/v1/dapp/search', { params });
820
+ return data;
821
+ });
822
+ this.getDappsInfo = (params) => __awaiter(this, void 0, void 0, function* () {
823
+ var _s;
824
+ const { data } = yield this.request.get('/v1/dapp/list', {
825
+ params: {
826
+ ids: (_s = params === null || params === void 0 ? void 0 : params.ids) === null || _s === void 0 ? void 0 : _s.join(','),
827
+ },
828
+ });
829
+ return data;
830
+ });
831
+ this.getDappHotTags = (params) => __awaiter(this, void 0, void 0, function* () {
832
+ const { data } = yield this.request.get('/v1/dapp/hot_tags', {
833
+ params,
834
+ });
835
+ return data;
836
+ });
837
+ this.getHotDapps = (params) => __awaiter(this, void 0, void 0, function* () {
838
+ const { data } = yield this.request.get('/v1/dapp/hot_list', { params });
839
+ return data;
840
+ });
841
+ this.getRabbyClaimText = (params) => __awaiter(this, void 0, void 0, function* () {
842
+ const { data } = yield this.request.get('/v1/points/user/claim_text', {
843
+ params,
844
+ });
845
+ return data;
846
+ });
847
+ this.getRabbySignatureText = (params) => __awaiter(this, void 0, void 0, function* () {
848
+ const { data } = yield this.request.get('/v1/points/user/sign_text', {
849
+ params,
850
+ });
851
+ return data;
852
+ });
853
+ this.getRabbyPoints = (params) => __awaiter(this, void 0, void 0, function* () {
854
+ const { data } = yield this.request.get('/v1/points/user', { params });
855
+ return data;
856
+ });
857
+ this.checkRabbyPointsInviteCode = (params) => __awaiter(this, void 0, void 0, function* () {
858
+ const { data } = yield this.request.get('/v1/points/user/invite_code_exist', { params });
859
+ return data;
860
+ });
861
+ this.setRabbyPointsInviteCode = (params) => __awaiter(this, void 0, void 0, function* () {
862
+ const { data } = yield this.request.post('/v1/points/user/invite_code', params);
863
+ return data;
864
+ });
865
+ this.checkRabbyPointClaimable = (params) => __awaiter(this, void 0, void 0, function* () {
866
+ const { data } = yield this.request.get('/v1/points/user/claimable', {
867
+ params,
868
+ });
869
+ return data;
870
+ });
871
+ this.getRabbyPointsSnapshot = (params) => __awaiter(this, void 0, void 0, function* () {
872
+ const { data } = yield this.request.get('/v1/points/snapshot', { params });
873
+ return data;
874
+ });
875
+ this.claimRabbyPointsSnapshot = (params) => __awaiter(this, void 0, void 0, function* () {
876
+ const { data } = yield this.request.post('/v1/points/claim_snapshot', params);
877
+ return data;
878
+ });
879
+ this.getRabbyPointsTopUsers = (params) => __awaiter(this, void 0, void 0, function* () {
880
+ const { data } = yield this.request.get('/v1/points/top_user', { params });
881
+ return data;
882
+ });
883
+ this.getRabbyPointsList = (params) => __awaiter(this, void 0, void 0, function* () {
884
+ const { data } = yield this.request.get('/v1/points/campaign_list', {
885
+ params,
886
+ });
887
+ return data;
888
+ });
889
+ this.claimRabbyPointsById = (params) => __awaiter(this, void 0, void 0, function* () {
890
+ const { data } = yield this.request.post('/v1/points/claim_campaign', params);
891
+ return data;
892
+ });
893
+ this.getSupportedChains = () => __awaiter(this, void 0, void 0, function* () {
894
+ const { data } = yield this.request.get('/v1/wallet/supported_chains');
895
+ return data;
896
+ });
897
+ this.getHistoryCurve = (addr) => __awaiter(this, void 0, void 0, function* () {
898
+ const { data } = yield this.request.get('v1/user/history_curve', {
899
+ params: { id: addr },
900
+ });
901
+ return data;
902
+ });
903
+ this.getHistoryCurveSupportedList = () => __awaiter(this, void 0, void 0, function* () {
904
+ const { data } = yield this.request.get('v1/chain/classify_supported_list');
905
+ return data;
906
+ });
907
+ if (store instanceof Promise) {
908
+ store.then((resolvedStore) => {
909
+ this.store = resolvedStore;
910
+ });
911
+ }
912
+ else {
913
+ this.store = store;
914
+ }
915
+ __classPrivateFieldSet(this, _OpenApiService_plugin, plugin, "f");
916
+ __classPrivateFieldSet(this, _OpenApiService_adapter, adapter, "f");
917
+ __classPrivateFieldSet(this, _OpenApiService_clientName, clientName, "f");
918
+ __classPrivateFieldSet(this, _OpenApiService_clientVersion, clientVersion, "f");
919
+ }
920
+ initSync(options) {
921
+ var _a, _b;
922
+ (_b = (_a = __classPrivateFieldGet(this, _OpenApiService_plugin, "f")).onInitiate) === null || _b === void 0 ? void 0 : _b.call(_a, Object.assign({}, options));
923
+ const request = axios.create({
924
+ baseURL: this.store.host,
925
+ adapter: __classPrivateFieldGet(this, _OpenApiService_adapter, "f"),
926
+ headers: {
927
+ 'X-Client': __classPrivateFieldGet(this, _OpenApiService_clientName, "f"),
928
+ 'X-Version': __classPrivateFieldGet(this, _OpenApiService_clientVersion, "f"),
929
+ },
930
+ });
931
+ // sign after rateLimit, timestamp is the latest
932
+ request.interceptors.request.use((config) => __awaiter(this, void 0, void 0, function* () {
933
+ const { method, url, params } = genSignParams(config);
934
+ yield __classPrivateFieldGet(this, _OpenApiService_plugin, "f").onSignRequest({
935
+ axiosRequestConfig: config,
936
+ parsed: { method, url, params },
937
+ });
938
+ return config;
939
+ }));
940
+ this.request = rateLimit(request, { maxRPS });
941
+ this.request.interceptors.response.use((response) => {
942
+ var _a, _b, _c, _d;
943
+ 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);
944
+ 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);
945
+ if (code && code !== 200) {
946
+ if (msg) {
947
+ let err;
948
+ try {
949
+ err = new Error(JSON.parse(msg));
950
+ }
951
+ catch (e) {
952
+ err = new Error(msg);
953
+ }
954
+ throw err;
955
+ }
956
+ throw new Error(typeof response.data === 'string'
957
+ ? response.data
958
+ : JSON.stringify(response.data));
959
+ }
960
+ return response;
961
+ });
962
+ this._mountMethods();
963
+ }
964
+ }
965
+ _OpenApiService_adapter = new WeakMap(), _OpenApiService_plugin = new WeakMap(), _OpenApiService_clientName = new WeakMap(), _OpenApiService_clientVersion = new WeakMap();