@rabby-wallet/rabby-api 0.6.22 → 0.6.24

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ## Install
4
4
 
5
5
  ```bash
6
- npm install rabby-api @debank/common
6
+ npm install @rabby-wallet/rabby-api @debank/common
7
7
  ```
8
8
 
9
9
  ## Usage
@@ -13,8 +13,8 @@ import { OpenApiService } from 'rabby-api';
13
13
 
14
14
  const service = new OpenApiService({
15
15
  store: {
16
- host: 'https://api.rabby.io'
17
- }
16
+ host: 'https://api.rabby.io',
17
+ },
18
18
  });
19
19
 
20
20
  // init service
@@ -0,0 +1,2 @@
1
+ export declare const ASYNC_JOB_TIMEOUT: number;
2
+ export declare const ASYNC_JOB_RETRY_DELAY: number;
package/dist/const.js ADDED
@@ -0,0 +1,2 @@
1
+ export const ASYNC_JOB_TIMEOUT = 10 * 60 * 1000;
2
+ export const ASYNC_JOB_RETRY_DELAY = 1.5 * 1000;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { AxiosAdapter } from 'axios';
1
+ import { AxiosAdapter, AxiosRequestConfig } from 'axios';
2
2
  import { RateLimitedAxiosInstance } from 'axios-rate-limit';
3
- import { AddrDescResponse, ApprovalStatus, AssetItem, CEXQuote, Cex, ChainWithPendingCount, Collection, CollectionList, CollectionWithFloorPrice, ComplexProtocol, ContractCredit, ExplainTxResponse, ExplainTypedDataResponse, GasLevel, GetTxResponse, NFTApprovalResponse, NFTItem, ParseTextResponse, ParseTxResponse, ParseTypedDataResponse, Protocol, SecurityCheckResponse, ServerChain, SlippageStatus, Summary, SwapTradeList, TokenApproval, TokenItem, TotalBalanceResponse, Tx, TxHistoryResult, UsedChain } from './types';
3
+ import { AddrDescResponse, ApprovalStatus, AssetItem, CEXQuote, Cex, ChainWithPendingCount, Collection, CollectionList, CollectionWithFloorPrice, ComplexProtocol, ContractCredit, ExplainTxResponse, ExplainTypedDataResponse, GasLevel, GetTxResponse, MempoolCheckDetail, NFTApprovalResponse, NFTItem, ParseTextResponse, ParseTxResponse, ParseTypedDataResponse, Protocol, SecurityCheckResponse, ServerChain, SlippageStatus, Summary, SwapTradeList, TokenApproval, TokenItem, TotalBalanceResponse, Tx, TxAllHistoryResult, TxHistoryResult, TxPushType, TxRequest, UsedChain } from './types';
4
4
  interface OpenApiStore {
5
5
  host: string;
6
6
  testnetHost?: string;
@@ -24,6 +24,9 @@ export declare class OpenApiService {
24
24
  adapter?: AxiosAdapter;
25
25
  constructor({ store, adapter }: Options);
26
26
  init: (hf?: string) => Promise<void>;
27
+ asyncJob: <T = any>(url: string, options?: AxiosRequestConfig & {
28
+ retryDelay?: number;
29
+ }) => Promise<T>;
27
30
  private _getRequestOptions;
28
31
  private _mountMethods;
29
32
  getRecommendChains: (address: string, origin: string) => Promise<ServerChain[]>;
@@ -86,6 +89,10 @@ export declare class OpenApiService {
86
89
  start_time?: number;
87
90
  page_count?: number;
88
91
  }) => Promise<TxHistoryResult>;
92
+ getAllTxHistory: (params: {
93
+ id: string;
94
+ start_time?: number;
95
+ }, options?: Parameters<typeof this.asyncJob>[1]) => Promise<TxAllHistoryResult>;
89
96
  tokenPrice: (tokenName: string) => Promise<{
90
97
  change_percent: number;
91
98
  last_price: number;
@@ -325,6 +332,27 @@ export declare class OpenApiService {
325
332
  }) => Promise<{
326
333
  is_success: boolean;
327
334
  }>;
335
+ gasSupportedPushType: (chainId: string) => Promise<{
336
+ low_gas: boolean;
337
+ mev: boolean;
338
+ }>;
339
+ submitTx: (postData: {
340
+ req_id?: string;
341
+ tx: Tx;
342
+ push_type: TxPushType;
343
+ low_gas_deadline?: number;
344
+ origin?: string;
345
+ }) => Promise<{
346
+ req: TxRequest;
347
+ }>;
348
+ getTxRequests: (ids: string | string[]) => Promise<TxRequest[]>;
349
+ withdrawTx: (reqId: string) => Promise<{
350
+ req: TxRequest;
351
+ }>;
352
+ retryPushTx: (reqId: string) => Promise<{
353
+ req: TxRequest;
354
+ }>;
355
+ mempoolChecks: (txId: string, chainId: string) => Promise<MempoolCheckDetail[]>;
328
356
  walletSupportChain: (params: {
329
357
  chain_id: string;
330
358
  user_addr: string;
package/dist/index.js CHANGED
@@ -11,7 +11,9 @@ import * as sign from '@rabby-wallet/rabby-sign/umd/sign-wasm-rabby';
11
11
  import axios from 'axios';
12
12
  import rateLimit from 'axios-rate-limit';
13
13
  import { ethErrors } from 'eth-rpc-errors';
14
- import { CHAINS, SIGN_HDS, genSignParams, getChain, getChainByNetwork, } from './utils';
14
+ import { CHAINS, SIGN_HDS, genSignParams, getChain, getChainByNetwork, sleep, } from './utils';
15
+ import { ASYNC_JOB_RETRY_DELAY, ASYNC_JOB_TIMEOUT } from './const';
16
+ import { omit } from 'lodash';
15
17
  const maxRPS = 500;
16
18
  export class OpenApiService {
17
19
  constructor({ store, adapter }) {
@@ -83,6 +85,19 @@ export class OpenApiService {
83
85
  });
84
86
  this._mountMethods();
85
87
  });
88
+ this.asyncJob = (url, options) => {
89
+ const _option = Object.assign({ timeout: ASYNC_JOB_TIMEOUT, retryDelay: ASYNC_JOB_RETRY_DELAY }, options);
90
+ const startTime = +new Date();
91
+ return this.request(url, omit(Object.assign({ method: 'GET' }, _option), 'retryDelay')).then((res) => {
92
+ const data = res.data;
93
+ if (data.result) {
94
+ return data.result.data;
95
+ }
96
+ const deltaTime = +new Date() - startTime;
97
+ _option.timeout = _option.timeout - deltaTime - _option.retryDelay;
98
+ return sleep(_option.retryDelay, _option.signal).then(() => this.asyncJob(url, _option));
99
+ });
100
+ };
86
101
  this._getRequestOptions = (chainId) => {
87
102
  if (!chainId) {
88
103
  return;
@@ -348,6 +363,10 @@ export class OpenApiService {
348
363
  const { data } = yield this.request.get('/v1/user/history_list', Object.assign({ params }, this._getRequestOptions(params.chain_id)));
349
364
  return data;
350
365
  });
366
+ this.getAllTxHistory = (params, options) => __awaiter(this, void 0, void 0, function* () {
367
+ const data = yield this.asyncJob('/v1/user/history_all_list', Object.assign({ method: 'GET', params }, options));
368
+ return data;
369
+ });
351
370
  this.tokenPrice = (tokenName) => __awaiter(this, void 0, void 0, function* () {
352
371
  var _m;
353
372
  const { data } = yield this.request.get('/v1/token/price_change', Object.assign({ params: {
@@ -741,6 +760,45 @@ export class OpenApiService {
741
760
  const { data } = yield this.request.post('/v1/faucet/request', Object.assign({}, params));
742
761
  return data;
743
762
  });
763
+ this.gasSupportedPushType = (chainId) => __awaiter(this, void 0, void 0, function* () {
764
+ const { data } = yield this.request.get('/v1/wallet/supported_push_type', Object.assign({ params: {
765
+ chain_id: chainId,
766
+ } }, this._getRequestOptions(chainId)));
767
+ return data;
768
+ });
769
+ this.submitTx = (postData) => __awaiter(this, void 0, void 0, function* () {
770
+ var _q;
771
+ 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));
772
+ return data;
773
+ });
774
+ this.getTxRequests = (ids) => __awaiter(this, void 0, void 0, function* () {
775
+ const { data } = yield this.request.get('/v1/wallet/get_tx_requests', {
776
+ params: {
777
+ ids: Array.isArray(ids) ? ids.join(',') : ids,
778
+ },
779
+ });
780
+ return data;
781
+ });
782
+ this.withdrawTx = (reqId) => __awaiter(this, void 0, void 0, function* () {
783
+ const { data } = yield this.request.post('/v1/wallet/withdraw_tx', {
784
+ id: reqId,
785
+ });
786
+ return data;
787
+ });
788
+ this.retryPushTx = (reqId) => __awaiter(this, void 0, void 0, function* () {
789
+ const { data } = yield this.request.post('/v1/wallet/retry_push_tx', {
790
+ id: reqId,
791
+ });
792
+ return data;
793
+ });
794
+ this.mempoolChecks = (txId, chainId) => __awaiter(this, void 0, void 0, function* () {
795
+ var _r;
796
+ const { data } = yield this.request.get('/v1/wallet/mempool_checks', Object.assign({ params: {
797
+ tx_id: txId,
798
+ chain_id: chainId,
799
+ } }, this._getRequestOptions((_r = getChainByNetwork(chainId)) === null || _r === void 0 ? void 0 : _r.serverId)));
800
+ return data;
801
+ });
744
802
  this.walletSupportChain = (params) => __awaiter(this, void 0, void 0, function* () {
745
803
  const { data } = yield this.request.post('/v1/wallet/support_chain', params);
746
804
  return data;
package/dist/types.d.ts CHANGED
@@ -357,6 +357,9 @@ export interface TxHistoryResult {
357
357
  }>;
358
358
  token_dict: Record<string, TokenItem>;
359
359
  }
360
+ export interface TxAllHistoryResult extends Omit<TxHistoryResult, 'token_dict'> {
361
+ token_uuid_dict: Record<string, TokenItem>;
362
+ }
360
363
  export interface GasResult {
361
364
  estimated_gas_cost_usd_value: number;
362
365
  estimated_gas_cost_value: number;
@@ -969,4 +972,42 @@ export interface ParseTextResponse {
969
972
  data: CreateKeyAction | VerifyAddressAction;
970
973
  } | null;
971
974
  }
975
+ export declare type TxPushType = 'default' | 'low_gas' | 'mev';
976
+ export interface TxRequest {
977
+ id: string;
978
+ chain_id: string;
979
+ user_addr: string;
980
+ nonce: number;
981
+ signed_tx: Tx;
982
+ tx_id?: null | string;
983
+ push_type: TxPushType;
984
+ push_status?: 'success' | 'failed';
985
+ push_at?: number | null;
986
+ is_withdraw: boolean;
987
+ create_at: number;
988
+ low_gas_deadline?: number;
989
+ is_finished: boolean;
990
+ }
991
+ export interface MempoolCheckDetail {
992
+ id: string;
993
+ chain_id: string;
994
+ tx_id: string;
995
+ check_at: string;
996
+ check_success: boolean;
997
+ rpc: string;
998
+ }
999
+ export interface JobResponse<T = any> {
1000
+ create_at: number;
1001
+ id: string;
1002
+ result: {
1003
+ create_at: number;
1004
+ id: string;
1005
+ data: T;
1006
+ };
1007
+ job: {
1008
+ create_at: number;
1009
+ id: string;
1010
+ status: 'pending' | 'running';
1011
+ } | null;
1012
+ }
972
1013
  export {};
package/dist/utils.d.ts CHANGED
@@ -11,3 +11,4 @@ export declare function genSignParams(config: AxiosRequestConfig): {
11
11
  url: string;
12
12
  params: Partial<any>;
13
13
  };
14
+ export declare function sleep(ms?: number, signal?: AbortController['signal']): Promise<void>;
package/dist/utils.js CHANGED
@@ -42,3 +42,20 @@ export function genSignParams(config) {
42
42
  params,
43
43
  };
44
44
  }
45
+ export function sleep(ms = 0, signal) {
46
+ if ((signal === null || signal === void 0 ? void 0 : signal.aborted) || ms < 0) {
47
+ return Promise.reject(new DOMException('Aborted', 'AbortError'));
48
+ }
49
+ return new Promise((resolve, reject) => {
50
+ const abortHandler = () => {
51
+ clearTimeout(timer);
52
+ reject(new DOMException('Aborted', 'AbortError'));
53
+ signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', abortHandler);
54
+ };
55
+ signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', abortHandler);
56
+ const timer = setTimeout(() => {
57
+ resolve();
58
+ signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', abortHandler);
59
+ }, ms);
60
+ });
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-api",
3
- "version": "0.6.22",
3
+ "version": "0.6.24",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist"