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