@rabby-wallet/rabby-api 0.6.23 → 0.6.25-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/const.d.ts +2 -0
- package/dist/const.js +2 -0
- package/dist/index.d.ts +21 -4
- package/dist/index.js +49 -3
- package/dist/types.d.ts +82 -5
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +17 -0
- package/package.json +1 -1
package/dist/const.d.ts
ADDED
package/dist/const.js
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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, MempoolCheckDetail, NFTApprovalResponse, NFTItem, ParseTextResponse, ParseTxResponse, ParseTypedDataResponse, Protocol, SecurityCheckResponse, ServerChain, SlippageStatus, Summary, SwapTradeList, TokenApproval, TokenItem, TotalBalanceResponse, Tx, TxHistoryResult, TxPushType, TxRequest, UsedChain } from './types';
|
|
3
|
+
import { AddrDescResponse, ApprovalStatus, AssetItem, CEXQuote, Cex, ChainWithPendingCount, Collection, CollectionList, CollectionWithFloorPrice, ComplexProtocol, ContractCredit, ExplainTxResponse, ExplainTypedDataResponse, GasLevel, GetTxResponse, LatestExplainTxResponse, MempoolCheckDetail, NFTApprovalResponse, NFTItem, ParseTextResponse, ParseTxResponse, ParseTypedDataResponse, PendingTxItem, 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;
|
|
7
7
|
}
|
|
8
8
|
interface Options {
|
|
9
|
-
store: OpenApiStore
|
|
9
|
+
store: OpenApiStore | Promise<OpenApiStore>;
|
|
10
10
|
adapter?: AxiosAdapter;
|
|
11
11
|
}
|
|
12
12
|
export declare class OpenApiService {
|
|
@@ -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;
|
|
@@ -339,13 +346,23 @@ export declare class OpenApiService {
|
|
|
339
346
|
req: TxRequest;
|
|
340
347
|
}>;
|
|
341
348
|
getTxRequests: (ids: string | string[]) => Promise<TxRequest[]>;
|
|
349
|
+
getTxRequest: (id: string) => Promise<TxRequest>;
|
|
342
350
|
withdrawTx: (reqId: string) => Promise<{
|
|
343
351
|
req: TxRequest;
|
|
344
352
|
}>;
|
|
345
353
|
retryPushTx: (reqId: string) => Promise<{
|
|
346
354
|
req: TxRequest;
|
|
347
355
|
}>;
|
|
348
|
-
mempoolChecks: (txId: string, chainId: string) => Promise<MempoolCheckDetail[]>;
|
|
356
|
+
mempoolChecks: (txId: string, chainId: string, node_info?: boolean) => Promise<MempoolCheckDetail[]>;
|
|
357
|
+
getPendingTxList: (params: {
|
|
358
|
+
chain_id: string;
|
|
359
|
+
}, options?: Parameters<typeof this.asyncJob>[1]) => Promise<{
|
|
360
|
+
pending_tx_list: PendingTxItem[];
|
|
361
|
+
token_dict: Record<string, TokenItem | NFTItem>;
|
|
362
|
+
}>;
|
|
363
|
+
getLatestPreExec: (params: {
|
|
364
|
+
id: string;
|
|
365
|
+
}) => Promise<LatestExplainTxResponse>;
|
|
349
366
|
walletSupportChain: (params: {
|
|
350
367
|
chain_id: string;
|
|
351
368
|
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: {
|
|
@@ -760,6 +779,14 @@ export class OpenApiService {
|
|
|
760
779
|
});
|
|
761
780
|
return data;
|
|
762
781
|
});
|
|
782
|
+
this.getTxRequest = (id) => __awaiter(this, void 0, void 0, function* () {
|
|
783
|
+
const { data } = yield this.request.get('/v1/wallet/get_tx_request', {
|
|
784
|
+
params: {
|
|
785
|
+
id,
|
|
786
|
+
},
|
|
787
|
+
});
|
|
788
|
+
return data;
|
|
789
|
+
});
|
|
763
790
|
this.withdrawTx = (reqId) => __awaiter(this, void 0, void 0, function* () {
|
|
764
791
|
const { data } = yield this.request.post('/v1/wallet/withdraw_tx', {
|
|
765
792
|
id: reqId,
|
|
@@ -772,14 +799,26 @@ export class OpenApiService {
|
|
|
772
799
|
});
|
|
773
800
|
return data;
|
|
774
801
|
});
|
|
775
|
-
this.mempoolChecks = (txId, chainId) => __awaiter(this, void 0, void 0, function* () {
|
|
802
|
+
this.mempoolChecks = (txId, chainId, node_info) => __awaiter(this, void 0, void 0, function* () {
|
|
776
803
|
var _r;
|
|
777
804
|
const { data } = yield this.request.get('/v1/wallet/mempool_checks', Object.assign({ params: {
|
|
778
805
|
tx_id: txId,
|
|
779
806
|
chain_id: chainId,
|
|
807
|
+
node_info: node_info ? 1 : 0,
|
|
780
808
|
} }, this._getRequestOptions((_r = getChainByNetwork(chainId)) === null || _r === void 0 ? void 0 : _r.serverId)));
|
|
781
809
|
return data;
|
|
782
810
|
});
|
|
811
|
+
this.getPendingTxList = (params, options) => __awaiter(this, void 0, void 0, function* () {
|
|
812
|
+
var _s;
|
|
813
|
+
const data = yield this.asyncJob('/v1/wallet/get_pending_tx_list', Object.assign(Object.assign({ params }, this._getRequestOptions((_s = getChainByNetwork(params.chain_id)) === null || _s === void 0 ? void 0 : _s.serverId)), options));
|
|
814
|
+
return data;
|
|
815
|
+
});
|
|
816
|
+
this.getLatestPreExec = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
817
|
+
const { data } = yield this.request.get('/v1/wallet/get_latest_pre_exec', {
|
|
818
|
+
params,
|
|
819
|
+
});
|
|
820
|
+
return data;
|
|
821
|
+
});
|
|
783
822
|
this.walletSupportChain = (params) => __awaiter(this, void 0, void 0, function* () {
|
|
784
823
|
const { data } = yield this.request.post('/v1/wallet/support_chain', params);
|
|
785
824
|
return data;
|
|
@@ -792,7 +831,14 @@ export class OpenApiService {
|
|
|
792
831
|
const { data } = yield this.request.post('/v1/wallet/support_selector', params);
|
|
793
832
|
return data;
|
|
794
833
|
});
|
|
795
|
-
|
|
834
|
+
if (store instanceof Promise) {
|
|
835
|
+
store.then((resolvedStore) => {
|
|
836
|
+
this.store = resolvedStore;
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
this.store = store;
|
|
841
|
+
}
|
|
796
842
|
this.adapter = adapter;
|
|
797
843
|
}
|
|
798
844
|
}
|
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;
|
|
@@ -374,15 +377,15 @@ export interface GasLevel {
|
|
|
374
377
|
estimated_seconds: number;
|
|
375
378
|
base_fee: number;
|
|
376
379
|
}
|
|
377
|
-
export interface BalanceChange {
|
|
380
|
+
export interface BalanceChange<T = TokenItem, N = TransferingNFTItem> {
|
|
378
381
|
error?: {
|
|
379
382
|
code: number;
|
|
380
383
|
msg: string;
|
|
381
384
|
} | null;
|
|
382
|
-
receive_nft_list:
|
|
383
|
-
receive_token_list:
|
|
384
|
-
send_nft_list:
|
|
385
|
-
send_token_list:
|
|
385
|
+
receive_nft_list: N[];
|
|
386
|
+
receive_token_list: T[];
|
|
387
|
+
send_nft_list: N[];
|
|
388
|
+
send_token_list: T[];
|
|
386
389
|
success: boolean;
|
|
387
390
|
usd_value_change: number;
|
|
388
391
|
}
|
|
@@ -531,6 +534,14 @@ export interface ExplainTxResponse {
|
|
|
531
534
|
}[];
|
|
532
535
|
};
|
|
533
536
|
}
|
|
537
|
+
export interface LatestExplainTxResponse {
|
|
538
|
+
id: string;
|
|
539
|
+
tx_id: string;
|
|
540
|
+
block_height: number;
|
|
541
|
+
gas_used: number;
|
|
542
|
+
pre_exec_result: PreExecResult;
|
|
543
|
+
create_at: number;
|
|
544
|
+
}
|
|
534
545
|
export interface RPCResponse<T> {
|
|
535
546
|
result: T;
|
|
536
547
|
id: number;
|
|
@@ -984,6 +995,7 @@ export interface TxRequest {
|
|
|
984
995
|
create_at: number;
|
|
985
996
|
low_gas_deadline?: number;
|
|
986
997
|
is_finished: boolean;
|
|
998
|
+
predict_packed_at?: number;
|
|
987
999
|
}
|
|
988
1000
|
export interface MempoolCheckDetail {
|
|
989
1001
|
id: string;
|
|
@@ -992,5 +1004,70 @@ export interface MempoolCheckDetail {
|
|
|
992
1004
|
check_at: string;
|
|
993
1005
|
check_success: boolean;
|
|
994
1006
|
rpc: string;
|
|
1007
|
+
name?: string;
|
|
1008
|
+
operator?: string;
|
|
1009
|
+
packed_rate?: number;
|
|
1010
|
+
}
|
|
1011
|
+
export interface JobResponse<T = any> {
|
|
1012
|
+
create_at: number;
|
|
1013
|
+
id: string;
|
|
1014
|
+
result: {
|
|
1015
|
+
create_at: number;
|
|
1016
|
+
id: string;
|
|
1017
|
+
data: T;
|
|
1018
|
+
};
|
|
1019
|
+
job: {
|
|
1020
|
+
create_at: number;
|
|
1021
|
+
id: string;
|
|
1022
|
+
status: 'pending' | 'running';
|
|
1023
|
+
} | null;
|
|
1024
|
+
}
|
|
1025
|
+
export interface PreExecResult {
|
|
1026
|
+
balance_change: BalanceChange;
|
|
1027
|
+
gas: {
|
|
1028
|
+
success?: boolean;
|
|
1029
|
+
error?: {
|
|
1030
|
+
code: number;
|
|
1031
|
+
msg: string;
|
|
1032
|
+
} | null;
|
|
1033
|
+
gas_used: number;
|
|
1034
|
+
gas_limit: number;
|
|
1035
|
+
};
|
|
1036
|
+
is_multisig: boolean;
|
|
1037
|
+
multisig?: null;
|
|
1038
|
+
pre_exec: {
|
|
1039
|
+
success: boolean;
|
|
1040
|
+
error?: {
|
|
1041
|
+
code: number;
|
|
1042
|
+
msg: string;
|
|
1043
|
+
} | null;
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
export interface PendingTxItem {
|
|
1047
|
+
id: string;
|
|
1048
|
+
action_data: ParseTxResponse['action']['data'];
|
|
1049
|
+
action_type: ParseTxResponse['action']['type'];
|
|
1050
|
+
block_height?: number | null;
|
|
1051
|
+
gas_price?: number | null;
|
|
1052
|
+
gas_used?: number | null;
|
|
1053
|
+
pre_exec_at?: number | null;
|
|
1054
|
+
pre_exec_result?: Omit<PreExecResult, 'balance_change'> & {
|
|
1055
|
+
balance_change: BalanceChange<{
|
|
1056
|
+
token_id: string;
|
|
1057
|
+
amount: number;
|
|
1058
|
+
}, {
|
|
1059
|
+
token_id: string;
|
|
1060
|
+
amount: number;
|
|
1061
|
+
}>;
|
|
1062
|
+
};
|
|
1063
|
+
to_addr: string;
|
|
1064
|
+
to_addr_desc: {
|
|
1065
|
+
cex?: Cex | null;
|
|
1066
|
+
protocol?: {
|
|
1067
|
+
id: string;
|
|
1068
|
+
logo_url: string;
|
|
1069
|
+
name: string;
|
|
1070
|
+
};
|
|
1071
|
+
};
|
|
995
1072
|
}
|
|
996
1073
|
export {};
|
package/dist/utils.d.ts
CHANGED
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
|
+
}
|