@swapkit/helpers 3.0.0-beta.8 → 4.0.0-beta.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/dist/api/index.cjs +2 -2
- package/dist/api/index.cjs.map +5 -5
- package/dist/api/index.js +2 -2
- package/dist/api/index.js.map +5 -5
- package/dist/{chunk-6vvdbb6s.js → chunk-7shcm26h.js} +3 -3
- package/dist/{chunk-6vvdbb6s.js.map → chunk-7shcm26h.js.map} +1 -1
- package/dist/chunk-8fdws4se.js +4 -0
- package/dist/chunk-8fdws4se.js.map +10 -0
- package/dist/{chunk-dbsrwnw2.js → chunk-b8hashv0.js} +3 -3
- package/dist/{chunk-dbsrwnw2.js.map → chunk-b8hashv0.js.map} +1 -1
- package/dist/{chunk-kdcsgh3q.js → chunk-bf0ph1bk.js} +3 -3
- package/dist/{chunk-kdcsgh3q.js.map → chunk-bf0ph1bk.js.map} +1 -1
- package/dist/{chunk-mmwvr2y8.js → chunk-bh986mnf.js} +3 -3
- package/dist/{chunk-mmwvr2y8.js.map → chunk-bh986mnf.js.map} +1 -1
- package/dist/{chunk-ahpfxkx0.js → chunk-dzypg9sp.js} +3 -3
- package/dist/{chunk-ahpfxkx0.js.map → chunk-dzypg9sp.js.map} +1 -1
- package/dist/{chunk-wmxwvv8c.js → chunk-ghdhtvtt.js} +3 -3
- package/dist/{chunk-wmxwvv8c.js.map → chunk-ghdhtvtt.js.map} +1 -1
- package/dist/{chunk-fr86y3rx.js → chunk-jhmhh7ax.js} +3 -3
- package/dist/{chunk-fr86y3rx.js.map → chunk-jhmhh7ax.js.map} +1 -1
- package/dist/{chunk-ekd1k975.js → chunk-nm1av1e6.js} +3 -3
- package/dist/{chunk-ekd1k975.js.map → chunk-nm1av1e6.js.map} +1 -1
- package/dist/{chunk-wrjh857m.js → chunk-rarep8vg.js} +3 -3
- package/dist/{chunk-wrjh857m.js.map → chunk-rarep8vg.js.map} +1 -1
- package/dist/{chunk-kr69v1tm.js → chunk-rr043vwc.js} +3 -3
- package/dist/{chunk-kr69v1tm.js.map → chunk-rr043vwc.js.map} +1 -1
- package/dist/{chunk-3wnfcm30.js → chunk-s82pm7xc.js} +2 -2
- package/dist/{chunk-3wnfcm30.js.map → chunk-s82pm7xc.js.map} +1 -1
- package/dist/chunk-sb9hymk1.js +3 -0
- package/dist/chunk-sb9hymk1.js.map +10 -0
- package/dist/{chunk-tq87xn7m.js → chunk-tn4e7zrk.js} +3 -3
- package/dist/{chunk-tq87xn7m.js.map → chunk-tn4e7zrk.js.map} +1 -1
- package/dist/{chunk-z8emzpyc.js → chunk-vadspc46.js} +3 -3
- package/dist/{chunk-z8emzpyc.js.map → chunk-vadspc46.js.map} +1 -1
- package/dist/{chunk-xyczdrny.js → chunk-vgg88vt8.js} +3 -3
- package/dist/{chunk-xyczdrny.js.map → chunk-vgg88vt8.js.map} +1 -1
- package/dist/{chunk-q8xy3739.js → chunk-wssz50sc.js} +3 -3
- package/dist/{chunk-q8xy3739.js.map → chunk-wssz50sc.js.map} +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +18 -18
- package/dist/index.js +3 -3
- package/dist/index.js.map +18 -18
- package/dist/tokens/index.js +2 -2
- package/dist/tokens/index.js.map +2 -2
- package/package.json +10 -6
- package/src/api/microgard/types.ts +0 -3
- package/src/api/midgard/endpoints.ts +1 -65
- package/src/api/midgard/types.ts +0 -49
- package/src/api/swapkitApi/endpoints.ts +16 -10
- package/src/api/swapkitApi/types.ts +1 -1
- package/src/index.ts +1 -0
- package/src/modules/__tests__/assetValue.test.ts +43 -0
- package/src/modules/__tests__/swapKitNumber.test.ts +4 -5
- package/src/modules/assetValue.ts +26 -35
- package/src/modules/bigIntArithmetics.ts +12 -1
- package/src/modules/feeMultiplier.ts +87 -0
- package/src/modules/requestClient.ts +43 -23
- package/src/modules/swapKitConfig.ts +9 -1
- package/src/modules/swapKitError.ts +325 -105
- package/src/types/chains.ts +98 -44
- package/src/types/derivationPath.ts +2 -0
- package/src/types/quotes.ts +1 -2
- package/src/types/sdk.ts +0 -2
- package/src/types/wallet.ts +5 -0
- package/src/utils/__tests__/memo.test.ts +0 -20
- package/src/utils/asset.ts +17 -30
- package/src/utils/derivationPath.ts +6 -0
- package/src/utils/memo.ts +5 -42
- package/src/utils/others.ts +1 -2
- package/src/utils/wallets.ts +6 -3
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SwapKitError } from "./swapKitError";
|
|
2
2
|
|
|
3
3
|
type Options = RequestInit & {
|
|
4
4
|
/**
|
|
5
|
-
* @deprecated Use onSuccess instead
|
|
5
|
+
* @deprecated Use onSuccess instead - will be removed in next major @MarkedV4
|
|
6
6
|
*/
|
|
7
7
|
responseHandler?: (response: any) => any;
|
|
8
8
|
json?: unknown;
|
|
9
9
|
onError?: (error: any) => any;
|
|
10
10
|
onSuccess?: (response: any) => any;
|
|
11
11
|
searchParams?: Record<string, string>;
|
|
12
|
+
dynamicHeader?: () => Record<string, string> | {};
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export const RequestClient = {
|
|
@@ -23,41 +24,60 @@ export const RequestClient = {
|
|
|
23
24
|
|
|
24
25
|
function fetchWithConfig(method: "GET" | "POST", extendOptions: Options = {}) {
|
|
25
26
|
return async <T>(url: string, options: Options = {}): Promise<T> => {
|
|
26
|
-
const {
|
|
27
|
-
|
|
27
|
+
const {
|
|
28
|
+
searchParams,
|
|
29
|
+
json,
|
|
30
|
+
body,
|
|
31
|
+
headers: headersOptions,
|
|
32
|
+
dynamicHeader,
|
|
33
|
+
} = { ...extendOptions, ...options };
|
|
28
34
|
|
|
29
|
-
const isJson = json || url.endsWith(".json");
|
|
35
|
+
const isJson = !!json || url.endsWith(".json");
|
|
30
36
|
const bodyToSend = isJson ? JSON.stringify(json) : body;
|
|
31
|
-
const urlInstance = new URL(url);
|
|
32
|
-
|
|
33
|
-
if (searchParams) {
|
|
34
|
-
urlInstance.search = new URLSearchParams(searchParams).toString();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const headers = {
|
|
38
|
-
...headersOptions,
|
|
39
|
-
...(isJson ? { "Content-Type": "application/json" } : {}),
|
|
40
|
-
...(swapKit ? { "x-api-key": swapKit } : {}),
|
|
41
|
-
};
|
|
42
37
|
|
|
43
38
|
try {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
headers,
|
|
39
|
+
const requestUrl = buildUrl(url, searchParams);
|
|
40
|
+
const headers = buildHeaders(isJson, {
|
|
41
|
+
...headersOptions,
|
|
42
|
+
...dynamicHeader?.(),
|
|
49
43
|
});
|
|
50
44
|
|
|
45
|
+
const response = await fetch(requestUrl, { ...options, method, body: bodyToSend, headers });
|
|
46
|
+
|
|
51
47
|
if (!response.ok) {
|
|
52
48
|
const message = await response.text();
|
|
53
|
-
throw new
|
|
49
|
+
throw new SwapKitError("helpers_invalid_response", {
|
|
50
|
+
status: response.status,
|
|
51
|
+
statusText: response.statusText,
|
|
52
|
+
message,
|
|
53
|
+
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const body = await response.json();
|
|
57
57
|
|
|
58
58
|
return options.onSuccess?.(body) || options.responseHandler?.(body) || body;
|
|
59
59
|
} catch (error) {
|
|
60
|
-
|
|
60
|
+
if (options.onError) {
|
|
61
|
+
return options.onError(error);
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
61
64
|
}
|
|
62
65
|
};
|
|
63
66
|
}
|
|
67
|
+
|
|
68
|
+
function buildHeaders(isJson: boolean, headersOptions?: HeadersInit) {
|
|
69
|
+
return {
|
|
70
|
+
...headersOptions,
|
|
71
|
+
...(isJson ? { "Content-Type": "application/json" } : {}),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function buildUrl(url: string, searchParams?: Record<string, string>) {
|
|
76
|
+
const urlInstance = new URL(url);
|
|
77
|
+
|
|
78
|
+
if (searchParams) {
|
|
79
|
+
urlInstance.search = new URLSearchParams(searchParams).toString();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return urlInstance.toString();
|
|
83
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createStore } from "zustand/vanilla";
|
|
2
2
|
import { Chain, EXPLORER_URLS, NODE_URLS, RPC_URLS, WalletOption } from "../types";
|
|
3
|
+
import type { FeeMultiplierConfig } from "./feeMultiplier";
|
|
3
4
|
|
|
4
5
|
export type SKConfigIntegrations = {
|
|
5
6
|
chainflip?: { useSDKBroker?: boolean; brokerUrl: string };
|
|
@@ -36,7 +37,6 @@ const initialState = {
|
|
|
36
37
|
|
|
37
38
|
apiKeys: {
|
|
38
39
|
blockchair: "",
|
|
39
|
-
kado: "",
|
|
40
40
|
keepKey: "",
|
|
41
41
|
swapKit: "",
|
|
42
42
|
walletConnectProjectId: "",
|
|
@@ -61,6 +61,8 @@ const initialState = {
|
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
63
|
} as SKConfigIntegrations,
|
|
64
|
+
|
|
65
|
+
feeMultipliers: undefined as FeeMultiplierConfig | undefined,
|
|
64
66
|
};
|
|
65
67
|
type SKState = typeof initialState;
|
|
66
68
|
|
|
@@ -73,6 +75,7 @@ export type SKConfigState = {
|
|
|
73
75
|
nodeUrls?: Partial<SKState["nodeUrls"]>;
|
|
74
76
|
rpcUrls?: Partial<SKState["rpcUrls"]>;
|
|
75
77
|
wallets?: SKState["wallets"];
|
|
78
|
+
feeMultipliers?: FeeMultiplierConfig;
|
|
76
79
|
};
|
|
77
80
|
|
|
78
81
|
type SwapKitConfigStore = SKState & {
|
|
@@ -86,6 +89,7 @@ type SwapKitConfigStore = SKState & {
|
|
|
86
89
|
integration: keyof SKState["integrations"],
|
|
87
90
|
config: SKConfigIntegrations[keyof SKConfigIntegrations],
|
|
88
91
|
) => void;
|
|
92
|
+
setFeeMultipliers: (multipliers: FeeMultiplierConfig) => void;
|
|
89
93
|
};
|
|
90
94
|
|
|
91
95
|
const swapKitState = createStore<SwapKitConfigStore>((set) => ({
|
|
@@ -99,6 +103,7 @@ const swapKitState = createStore<SwapKitConfigStore>((set) => ({
|
|
|
99
103
|
setRpcUrl: (chain, url) => set((s) => ({ rpcUrls: { ...s.rpcUrls, [chain]: url } })),
|
|
100
104
|
setIntegrationConfig: (integration, config) =>
|
|
101
105
|
set((s) => ({ integrations: { ...s.integrations, [integration]: config } })),
|
|
106
|
+
setFeeMultipliers: (multipliers) => set(() => ({ feeMultipliers: multipliers })),
|
|
102
107
|
setConfig: (config) =>
|
|
103
108
|
set((s) => ({
|
|
104
109
|
apiKeys: { ...s.apiKeys, ...config.apiKeys },
|
|
@@ -107,6 +112,7 @@ const swapKitState = createStore<SwapKitConfigStore>((set) => ({
|
|
|
107
112
|
integrations: { ...s.integrations, ...config.integrations },
|
|
108
113
|
nodeUrls: { ...s.nodeUrls, ...config.nodeUrls },
|
|
109
114
|
rpcUrls: { ...s.rpcUrls, ...config.rpcUrls },
|
|
115
|
+
feeMultipliers: config.feeMultipliers || s.feeMultipliers,
|
|
110
116
|
chains: s.chains.concat(config.chains || []),
|
|
111
117
|
wallets: s.wallets.concat(config.wallets || []),
|
|
112
118
|
})),
|
|
@@ -131,4 +137,6 @@ export const SKConfig = {
|
|
|
131
137
|
integration: T,
|
|
132
138
|
config: SKConfigIntegrations[T],
|
|
133
139
|
) => swapKitState.getState().setIntegrationConfig(integration, config),
|
|
140
|
+
setFeeMultipliers: (multipliers: FeeMultiplierConfig) =>
|
|
141
|
+
swapKitState.getState().setFeeMultipliers(multipliers),
|
|
134
142
|
};
|
|
@@ -2,44 +2,44 @@ const errorCodes = {
|
|
|
2
2
|
/**
|
|
3
3
|
* Core
|
|
4
4
|
*/
|
|
5
|
-
core_estimated_max_spendable_chain_not_supported:
|
|
6
|
-
core_extend_error:
|
|
7
|
-
core_inbound_data_not_found:
|
|
8
|
-
core_approve_asset_address_or_from_not_found:
|
|
9
|
-
core_plugin_not_found:
|
|
10
|
-
core_plugin_swap_not_found:
|
|
11
|
-
core_approve_asset_target_invalid:
|
|
12
|
-
core_explorer_unsupported_chain:
|
|
13
|
-
core_verify_message_not_supported:
|
|
14
|
-
core_chain_halted:
|
|
5
|
+
core_estimated_max_spendable_chain_not_supported: 10001,
|
|
6
|
+
core_extend_error: 10002,
|
|
7
|
+
core_inbound_data_not_found: 10003,
|
|
8
|
+
core_approve_asset_address_or_from_not_found: 10004,
|
|
9
|
+
core_plugin_not_found: 10005,
|
|
10
|
+
core_plugin_swap_not_found: 10006,
|
|
11
|
+
core_approve_asset_target_invalid: 10007,
|
|
12
|
+
core_explorer_unsupported_chain: 10008,
|
|
13
|
+
core_verify_message_not_supported: 10009,
|
|
14
|
+
core_chain_halted: 10010,
|
|
15
15
|
/**
|
|
16
16
|
* Core - Wallet
|
|
17
17
|
*/
|
|
18
|
-
core_wallet_connection_not_found:
|
|
19
|
-
core_wallet_ctrl_not_installed:
|
|
20
|
-
core_wallet_evmwallet_not_installed:
|
|
21
|
-
core_wallet_walletconnect_not_installed:
|
|
22
|
-
core_wallet_keystore_not_installed:
|
|
23
|
-
core_wallet_ledger_not_installed:
|
|
24
|
-
core_wallet_trezor_not_installed:
|
|
25
|
-
core_wallet_keplr_not_installed:
|
|
26
|
-
core_wallet_okx_not_installed:
|
|
27
|
-
core_wallet_keepkey_not_installed:
|
|
28
|
-
core_wallet_talisman_not_installed:
|
|
29
|
-
core_wallet_not_keypair_wallet:
|
|
30
|
-
core_wallet_sign_message_not_supported:
|
|
31
|
-
core_wallet_connection_failed:
|
|
18
|
+
core_wallet_connection_not_found: 10101,
|
|
19
|
+
core_wallet_ctrl_not_installed: 10102,
|
|
20
|
+
core_wallet_evmwallet_not_installed: 10103,
|
|
21
|
+
core_wallet_walletconnect_not_installed: 10104,
|
|
22
|
+
core_wallet_keystore_not_installed: 10105,
|
|
23
|
+
core_wallet_ledger_not_installed: 10106,
|
|
24
|
+
core_wallet_trezor_not_installed: 10107,
|
|
25
|
+
core_wallet_keplr_not_installed: 10108,
|
|
26
|
+
core_wallet_okx_not_installed: 10109,
|
|
27
|
+
core_wallet_keepkey_not_installed: 10110,
|
|
28
|
+
core_wallet_talisman_not_installed: 10111,
|
|
29
|
+
core_wallet_not_keypair_wallet: 10112,
|
|
30
|
+
core_wallet_sign_message_not_supported: 10113,
|
|
31
|
+
core_wallet_connection_failed: 10114,
|
|
32
32
|
/**
|
|
33
33
|
* Core - Swap
|
|
34
34
|
*/
|
|
35
|
-
core_swap_invalid_params:
|
|
36
|
-
core_swap_route_not_complete:
|
|
37
|
-
core_swap_asset_not_recognized:
|
|
38
|
-
core_swap_contract_not_found:
|
|
39
|
-
core_swap_route_transaction_not_found:
|
|
40
|
-
core_swap_contract_not_supported:
|
|
41
|
-
core_swap_transaction_error:
|
|
42
|
-
core_swap_quote_mode_not_supported:
|
|
35
|
+
core_swap_invalid_params: 10201,
|
|
36
|
+
core_swap_route_not_complete: 10202,
|
|
37
|
+
core_swap_asset_not_recognized: 10203,
|
|
38
|
+
core_swap_contract_not_found: 10204,
|
|
39
|
+
core_swap_route_transaction_not_found: 10205,
|
|
40
|
+
core_swap_contract_not_supported: 10206,
|
|
41
|
+
core_swap_transaction_error: 10207,
|
|
42
|
+
core_swap_quote_mode_not_supported: 10208,
|
|
43
43
|
/**
|
|
44
44
|
* Core - Transaction
|
|
45
45
|
*/
|
|
@@ -61,111 +61,326 @@ const errorCodes = {
|
|
|
61
61
|
core_transaction_failed: 10316,
|
|
62
62
|
core_transaction_invalid_recipient_address: 10317,
|
|
63
63
|
/**
|
|
64
|
-
* Wallets
|
|
64
|
+
* Wallets - General
|
|
65
|
+
*/
|
|
66
|
+
wallet_connection_rejected_by_user: 20001,
|
|
67
|
+
wallet_missing_api_key: 20002,
|
|
68
|
+
wallet_chain_not_supported: 20003,
|
|
69
|
+
wallet_missing_params: 20004,
|
|
70
|
+
wallet_provider_not_found: 20005,
|
|
71
|
+
wallet_failed_to_add_or_switch_network: 20006,
|
|
72
|
+
/**
|
|
73
|
+
* Wallets - Ledger
|
|
65
74
|
*/
|
|
66
|
-
wallet_connection_rejected_by_user: 20000,
|
|
67
|
-
wallet_missing_api_key: 20001,
|
|
68
|
-
wallet_chain_not_supported: 20002,
|
|
69
|
-
wallet_missing_params: 20003,
|
|
70
|
-
wallet_provider_not_found: 20004,
|
|
71
|
-
wallet_failed_to_add_or_switch_network: 20005,
|
|
72
75
|
wallet_ledger_connection_error: 20101,
|
|
73
76
|
wallet_ledger_connection_claimed: 20102,
|
|
74
77
|
wallet_ledger_get_address_error: 20103,
|
|
75
78
|
wallet_ledger_device_not_found: 20104,
|
|
76
79
|
wallet_ledger_device_locked: 20105,
|
|
80
|
+
wallet_ledger_transport_error: 20106,
|
|
81
|
+
wallet_ledger_public_key_error: 20107,
|
|
82
|
+
wallet_ledger_derivation_path_error: 20108,
|
|
83
|
+
wallet_ledger_signing_error: 20109,
|
|
84
|
+
wallet_ledger_app_not_open: 20110,
|
|
85
|
+
wallet_ledger_invalid_response: 20111,
|
|
86
|
+
wallet_ledger_method_not_supported: 20112,
|
|
87
|
+
wallet_ledger_invalid_params: 20113,
|
|
88
|
+
wallet_ledger_invalid_signature: 20114,
|
|
89
|
+
wallet_ledger_no_provider: 20115,
|
|
90
|
+
wallet_ledger_pubkey_not_found: 20116,
|
|
91
|
+
wallet_ledger_transport_not_defined: 20117,
|
|
92
|
+
wallet_ledger_webusb_not_supported: 20118,
|
|
93
|
+
wallet_ledger_chain_not_supported: 20119,
|
|
94
|
+
wallet_ledger_invalid_asset: 20120,
|
|
95
|
+
wallet_ledger_invalid_account: 20121,
|
|
96
|
+
wallet_ledger_address_not_found: 20122,
|
|
97
|
+
wallet_ledger_failed_to_get_address: 20123,
|
|
98
|
+
/**
|
|
99
|
+
* Wallets - Phantom
|
|
100
|
+
*/
|
|
77
101
|
wallet_phantom_not_found: 20201,
|
|
102
|
+
/**
|
|
103
|
+
* Wallets - Ctrl
|
|
104
|
+
*/
|
|
78
105
|
wallet_ctrl_not_found: 20301,
|
|
79
106
|
wallet_ctrl_send_transaction_no_address: 20302,
|
|
80
107
|
wallet_ctrl_contract_address_not_provided: 20303,
|
|
81
108
|
wallet_ctrl_asset_not_defined: 20304,
|
|
109
|
+
/**
|
|
110
|
+
* Wallets - WalletConnect
|
|
111
|
+
*/
|
|
82
112
|
wallet_walletconnect_project_id_not_specified: 20401,
|
|
83
113
|
wallet_walletconnect_connection_not_established: 20402,
|
|
84
114
|
wallet_walletconnect_namespace_not_supported: 20403,
|
|
115
|
+
wallet_walletconnect_chain_not_supported: 20404,
|
|
116
|
+
wallet_walletconnect_invalid_method: 20405,
|
|
117
|
+
wallet_walletconnect_method_not_supported: 20406,
|
|
118
|
+
/**
|
|
119
|
+
* Wallets - Trezor
|
|
120
|
+
*/
|
|
85
121
|
wallet_trezor_failed_to_sign_transaction: 20501,
|
|
86
122
|
wallet_trezor_derivation_path_not_supported: 20502,
|
|
87
123
|
wallet_trezor_failed_to_get_address: 20503,
|
|
124
|
+
wallet_trezor_transport_error: 20504,
|
|
125
|
+
wallet_trezor_method_not_supported: 20505,
|
|
126
|
+
/**
|
|
127
|
+
* Wallets - Talisman
|
|
128
|
+
*/
|
|
88
129
|
wallet_talisman_not_enabled: 20601,
|
|
89
130
|
wallet_talisman_not_found: 20602,
|
|
131
|
+
/**
|
|
132
|
+
* Wallets - Polkadot
|
|
133
|
+
*/
|
|
90
134
|
wallet_polkadot_not_found: 20701,
|
|
135
|
+
/**
|
|
136
|
+
* Wallets - Radix
|
|
137
|
+
*/
|
|
91
138
|
wallet_radix_not_found: 20801,
|
|
92
139
|
wallet_radix_transaction_failed: 20802,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
140
|
+
wallet_radix_invalid_manifest: 20803,
|
|
141
|
+
wallet_radix_method_not_supported: 20804,
|
|
142
|
+
wallet_radix_no_account: 20805,
|
|
143
|
+
/**
|
|
144
|
+
* Wallets - KeepKey
|
|
145
|
+
*/
|
|
146
|
+
wallet_keepkey_not_found: 20901,
|
|
147
|
+
wallet_keepkey_asset_not_defined: 20902,
|
|
148
|
+
wallet_keepkey_contract_address_not_provided: 20903,
|
|
149
|
+
wallet_keepkey_send_transaction_no_address: 20904,
|
|
150
|
+
wallet_keepkey_derivation_path_error: 20905,
|
|
151
|
+
wallet_keepkey_signing_error: 20906,
|
|
152
|
+
wallet_keepkey_transport_error: 20907,
|
|
153
|
+
wallet_keepkey_unsupported_chain: 20908,
|
|
154
|
+
wallet_keepkey_invalid_response: 20909,
|
|
155
|
+
wallet_keepkey_chain_not_supported: 20910,
|
|
156
|
+
wallet_keepkey_signer_not_found: 20911,
|
|
157
|
+
wallet_keepkey_no_accounts: 20912,
|
|
158
|
+
wallet_keepkey_method_not_supported: 20913,
|
|
159
|
+
wallet_keepkey_invalid_params: 20914,
|
|
160
|
+
wallet_keepkey_config_not_found: 20915,
|
|
161
|
+
wallet_keepkey_no_provider: 20916,
|
|
162
|
+
wallet_keepkey_account_not_found: 20917,
|
|
163
|
+
/**
|
|
164
|
+
* Wallets - BitKeep/BitGet
|
|
165
|
+
*/
|
|
97
166
|
wallet_bitkeep_not_found: 21001,
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
167
|
+
wallet_bitkeep_failed_to_switch_network: 21002,
|
|
168
|
+
wallet_bitkeep_no_accounts: 21003,
|
|
169
|
+
/**
|
|
170
|
+
* Wallets - Exodus
|
|
171
|
+
*/
|
|
172
|
+
wallet_exodus_sign_transaction_error: 21101,
|
|
173
|
+
wallet_exodus_not_found: 21102,
|
|
174
|
+
wallet_exodus_no_address: 21103,
|
|
175
|
+
wallet_exodus_request_canceled: 21104,
|
|
176
|
+
wallet_exodus_signature_canceled: 21105,
|
|
177
|
+
wallet_exodus_failed_to_switch_network: 21106,
|
|
178
|
+
wallet_exodus_chain_not_supported: 21107,
|
|
179
|
+
wallet_exodus_instance_missing: 21108,
|
|
180
|
+
/**
|
|
181
|
+
* Wallets - OneKey
|
|
182
|
+
*/
|
|
183
|
+
wallet_onekey_not_found: 21201,
|
|
184
|
+
wallet_onekey_sign_transaction_error: 21202,
|
|
185
|
+
/**
|
|
186
|
+
* Wallets - OKX
|
|
187
|
+
*/
|
|
188
|
+
wallet_okx_not_found: 21301,
|
|
189
|
+
wallet_okx_chain_not_supported: 21302,
|
|
190
|
+
wallet_okx_failed_to_switch_network: 21303,
|
|
191
|
+
wallet_okx_no_accounts: 21304,
|
|
192
|
+
/**
|
|
193
|
+
* Wallets - Keplr
|
|
194
|
+
*/
|
|
195
|
+
wallet_keplr_not_found: 21401,
|
|
196
|
+
wallet_keplr_chain_not_supported: 21402,
|
|
197
|
+
wallet_keplr_signer_not_found: 21403,
|
|
198
|
+
wallet_keplr_no_accounts: 21404,
|
|
199
|
+
/**
|
|
200
|
+
* Wallets - Cosmostation
|
|
201
|
+
*/
|
|
202
|
+
wallet_cosmostation_not_found: 21501,
|
|
203
|
+
wallet_cosmostation_chain_not_supported: 21502,
|
|
204
|
+
wallet_cosmostation_evm_provider_not_found: 21503,
|
|
205
|
+
wallet_cosmostation_keplr_provider_not_found: 21504,
|
|
206
|
+
wallet_cosmostation_no_accounts: 21505,
|
|
207
|
+
wallet_cosmostation_no_evm_accounts: 21506,
|
|
208
|
+
wallet_cosmostation_no_evm_address: 21507,
|
|
209
|
+
wallet_cosmostation_signer_not_found: 21508,
|
|
210
|
+
/**
|
|
211
|
+
* Wallets - XDefi
|
|
212
|
+
*/
|
|
213
|
+
wallet_xdefi_not_found: 21601,
|
|
214
|
+
wallet_xdefi_chain_not_supported: 21602,
|
|
215
|
+
/**
|
|
216
|
+
* Wallets - Coinbase
|
|
217
|
+
*/
|
|
218
|
+
wallet_coinbase_not_found: 21701,
|
|
219
|
+
wallet_coinbase_chain_not_supported: 21702,
|
|
220
|
+
wallet_coinbase_method_not_supported: 21703,
|
|
221
|
+
wallet_coinbase_no_accounts: 21704,
|
|
222
|
+
/**
|
|
223
|
+
* Wallets - EVM Extensions
|
|
224
|
+
*/
|
|
225
|
+
wallet_evm_extensions_failed_to_switch_network: 21801,
|
|
226
|
+
wallet_evm_extensions_no_provider: 21802,
|
|
227
|
+
wallet_evm_extensions_not_found: 21803,
|
|
228
|
+
/**
|
|
229
|
+
* Wallets - Keystore
|
|
230
|
+
*/
|
|
231
|
+
wallet_keystore_invalid_password: 21901,
|
|
232
|
+
wallet_keystore_unsupported_version: 21902,
|
|
233
|
+
/**
|
|
234
|
+
* Wallets - Near Extensions
|
|
235
|
+
*/
|
|
236
|
+
wallet_near_extensions_failed_to_switch_network: 22001,
|
|
237
|
+
wallet_near_extensions_no_provider: 22002,
|
|
238
|
+
wallet_near_extensions_not_found: 22003,
|
|
239
|
+
wallet_near_method_not_supported: 22003,
|
|
103
240
|
/**
|
|
104
241
|
* Chainflip
|
|
105
242
|
*/
|
|
106
243
|
chainflip_channel_error: 30001,
|
|
107
244
|
chainflip_unknown_asset: 30002,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
245
|
+
/**
|
|
246
|
+
* Chainflip - Broker
|
|
247
|
+
*/
|
|
248
|
+
chainflip_broker_invalid_params: 30101,
|
|
249
|
+
chainflip_broker_recipient_error: 30102,
|
|
250
|
+
chainflip_broker_register: 30103,
|
|
251
|
+
chainflip_broker_tx_error: 30104,
|
|
252
|
+
chainflip_broker_withdraw: 30105,
|
|
253
|
+
chainflip_broker_fund_only_flip_supported: 30106,
|
|
254
|
+
chainflip_broker_fund_invalid_address: 30107,
|
|
115
255
|
/**
|
|
116
256
|
* THORChain
|
|
117
257
|
*/
|
|
118
258
|
thorchain_chain_halted: 40001,
|
|
119
259
|
thorchain_trading_halted: 40002,
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
260
|
+
/**
|
|
261
|
+
* THORChain - Swap
|
|
262
|
+
*/
|
|
263
|
+
thorchain_swapin_router_required: 40101,
|
|
264
|
+
thorchain_swapin_vault_required: 40102,
|
|
265
|
+
thorchain_swapin_memo_required: 40103,
|
|
266
|
+
thorchain_swapin_token_required: 40104,
|
|
267
|
+
thorchain_preferred_asset_payout_required: 40105,
|
|
268
|
+
/**
|
|
269
|
+
* Toolboxes - Cosmos
|
|
270
|
+
*/
|
|
271
|
+
toolbox_cosmos_account_not_found: 50101,
|
|
272
|
+
toolbox_cosmos_invalid_fee: 50102,
|
|
273
|
+
toolbox_cosmos_invalid_params: 50103,
|
|
274
|
+
toolbox_cosmos_no_signer: 50104,
|
|
275
|
+
toolbox_cosmos_not_supported: 50105,
|
|
276
|
+
toolbox_cosmos_signer_not_defined: 50106,
|
|
277
|
+
toolbox_cosmos_validate_address_prefix_not_found: 50107,
|
|
278
|
+
toolbox_cosmos_verify_signature_no_pubkey: 50108,
|
|
279
|
+
/**
|
|
280
|
+
* Toolboxes - EVM
|
|
281
|
+
*/
|
|
282
|
+
toolbox_evm_error_estimating_gas_limit: 50201,
|
|
283
|
+
toolbox_evm_error_sending_transaction: 50202,
|
|
284
|
+
toolbox_evm_gas_estimation_error: 50203,
|
|
285
|
+
toolbox_evm_invalid_gas_asset_address: 50204,
|
|
286
|
+
toolbox_evm_invalid_params: 50205,
|
|
287
|
+
toolbox_evm_invalid_transaction: 50206,
|
|
288
|
+
toolbox_evm_no_abi_fragment: 50207,
|
|
289
|
+
toolbox_evm_no_contract_address: 50208,
|
|
290
|
+
toolbox_evm_no_fee_data: 50209,
|
|
291
|
+
toolbox_evm_no_from_address: 50210,
|
|
292
|
+
toolbox_evm_no_gas_price: 50211,
|
|
293
|
+
toolbox_evm_no_signer_address: 50212,
|
|
294
|
+
toolbox_evm_no_signer: 50213,
|
|
295
|
+
toolbox_evm_no_to_address: 50214,
|
|
296
|
+
toolbox_evm_not_supported: 50215,
|
|
297
|
+
toolbox_evm_provider_not_eip1193_compatible: 50216,
|
|
298
|
+
/**
|
|
299
|
+
* Toolboxes - UTXO
|
|
300
|
+
*/
|
|
301
|
+
toolbox_utxo_api_error: 50301,
|
|
302
|
+
toolbox_utxo_broadcast_failed: 50302,
|
|
303
|
+
toolbox_utxo_insufficient_balance: 50303,
|
|
304
|
+
toolbox_utxo_invalid_address: 50304,
|
|
305
|
+
toolbox_utxo_invalid_params: 50305,
|
|
306
|
+
toolbox_utxo_invalid_transaction: 50306,
|
|
307
|
+
toolbox_utxo_no_signer: 50307,
|
|
308
|
+
toolbox_utxo_not_supported: 50308,
|
|
309
|
+
/**
|
|
310
|
+
* Toolboxes - Solana
|
|
311
|
+
*/
|
|
312
|
+
toolbox_solana_no_signer: 50401,
|
|
313
|
+
toolbox_solana_fee_estimation_failed: 50402,
|
|
314
|
+
/**
|
|
315
|
+
* Toolboxes - Substrate
|
|
316
|
+
*/
|
|
317
|
+
toolbox_substrate_not_supported: 50501,
|
|
318
|
+
/**
|
|
319
|
+
* Toolboxes - Radix
|
|
320
|
+
*/
|
|
321
|
+
toolbox_radix_method_not_supported: 50601,
|
|
322
|
+
/**
|
|
323
|
+
* Toolboxes - Ripple
|
|
324
|
+
*/
|
|
325
|
+
toolbox_ripple_get_balance_error: 50701,
|
|
326
|
+
toolbox_ripple_rpc_not_configured: 50702,
|
|
327
|
+
toolbox_ripple_signer_not_found: 50703,
|
|
328
|
+
toolbox_ripple_asset_not_supported: 50704,
|
|
329
|
+
toolbox_ripple_broadcast_error: 50705,
|
|
330
|
+
/**
|
|
331
|
+
* Toolboxes - Tron
|
|
332
|
+
*/
|
|
333
|
+
toolbox_tron_no_signer: 50801,
|
|
334
|
+
toolbox_tron_invalid_token_identifier: 50802,
|
|
335
|
+
toolbox_tron_token_transfer_failed: 50803,
|
|
336
|
+
toolbox_tron_transaction_creation_failed: 50804,
|
|
337
|
+
/**
|
|
338
|
+
* Toolboxes - Near
|
|
339
|
+
*/
|
|
340
|
+
toolbox_near_no_signer: 90601,
|
|
341
|
+
toolbox_near_invalid_address: 90602,
|
|
342
|
+
toolbox_near_invalid_amount: 90603,
|
|
343
|
+
toolbox_near_transfer_failed: 90604,
|
|
344
|
+
toolbox_near_access_key_error: 90605,
|
|
345
|
+
toolbox_near_no_rpc_url: 90606,
|
|
346
|
+
toolbox_near_empty_batch: 90607,
|
|
347
|
+
toolbox_near_balance_failed: 90608,
|
|
348
|
+
toolbox_near_invalid_name: 90609,
|
|
349
|
+
toolbox_near_missing_contract_address: 90610,
|
|
350
|
+
toolbox_near_no_account: 90611,
|
|
351
|
+
toolbox_near_invalid_gas_params: 90612,
|
|
352
|
+
/**
|
|
353
|
+
* Toolboxes - General
|
|
354
|
+
*/
|
|
355
|
+
toolbox_not_supported: 59901,
|
|
356
|
+
/**
|
|
357
|
+
* NEAR Plugin
|
|
358
|
+
*/
|
|
359
|
+
plugin_near_invalid_name: 41001,
|
|
360
|
+
plugin_near_no_connection: 41002,
|
|
361
|
+
plugin_near_name_unavailable: 41003,
|
|
362
|
+
plugin_near_registration_failed: 41004,
|
|
363
|
+
plugin_near_transfer_failed: 41005,
|
|
125
364
|
/**
|
|
126
365
|
* SwapKit API
|
|
127
366
|
*/
|
|
128
|
-
api_v2_invalid_response:
|
|
129
|
-
api_v2_server_error:
|
|
130
|
-
api_v2_invalid_method_key_hash:
|
|
131
|
-
/**
|
|
132
|
-
* Toolboxes
|
|
133
|
-
*/
|
|
134
|
-
toolbox_cosmos_signer_not_defined: 90101,
|
|
135
|
-
toolbox_cosmos_no_accounts_found: 90102,
|
|
136
|
-
toolbox_cosmos_verify_signature_no_pubkey: 90103,
|
|
137
|
-
toolbox_cosmos_validate_address_prefix_not_found: 90104,
|
|
138
|
-
toolbox_evm_no_abi_fragment: 90201,
|
|
139
|
-
toolbox_evm_no_signer: 90202,
|
|
140
|
-
toolbox_evm_no_signer_address: 90203,
|
|
141
|
-
toolbox_evm_no_from_address: 90204,
|
|
142
|
-
toolbox_evm_no_contract_address: 90205,
|
|
143
|
-
toolbox_evm_no_fee_data: 90206,
|
|
144
|
-
toolbox_evm_no_gas_price: 90207,
|
|
145
|
-
toolbox_evm_no_to_address: 90208,
|
|
146
|
-
toolbox_evm_invalid_gas_asset_address: 90209,
|
|
147
|
-
toolbox_evm_provider_not_eip1193_compatible: 90210,
|
|
148
|
-
toolbox_evm_error_estimating_gas_limit: 90211,
|
|
149
|
-
toolbox_evm_error_sending_transaction: 90212,
|
|
150
|
-
toolbox_radix_signer_not_defined: 90301,
|
|
151
|
-
toolbox_solana_no_signer: 90401,
|
|
152
|
-
toolbox_solana_fee_estimation_failed: 90402,
|
|
153
|
-
toolbox_ripple_rpc_not_configured: 90501,
|
|
154
|
-
toolbox_ripple_signer_not_found: 90502,
|
|
155
|
-
toolbox_ripple_asset_not_supported: 90503,
|
|
156
|
-
toolbox_ripple_broadcast_error: 90504,
|
|
157
|
-
toolbox_ripple_get_balance_error: 90505,
|
|
367
|
+
api_v2_invalid_response: 60001,
|
|
368
|
+
api_v2_server_error: 60002,
|
|
369
|
+
api_v2_invalid_method_key_hash: 60003,
|
|
158
370
|
/**
|
|
159
371
|
* Helpers
|
|
160
372
|
*/
|
|
161
|
-
helpers_invalid_number_different_decimals:
|
|
162
|
-
helpers_invalid_number_of_years:
|
|
163
|
-
helpers_invalid_identifier:
|
|
164
|
-
helpers_invalid_asset_url:
|
|
165
|
-
helpers_invalid_asset_identifier:
|
|
166
|
-
helpers_invalid_memo_type:
|
|
167
|
-
helpers_failed_to_switch_network:
|
|
168
|
-
helpers_not_found_provider:
|
|
373
|
+
helpers_invalid_number_different_decimals: 70001,
|
|
374
|
+
helpers_invalid_number_of_years: 70002,
|
|
375
|
+
helpers_invalid_identifier: 70003,
|
|
376
|
+
helpers_invalid_asset_url: 70004,
|
|
377
|
+
helpers_invalid_asset_identifier: 70005,
|
|
378
|
+
helpers_invalid_memo_type: 70006,
|
|
379
|
+
helpers_failed_to_switch_network: 70007,
|
|
380
|
+
helpers_not_found_provider: 70008,
|
|
381
|
+
helpers_chain_not_supported: 70009,
|
|
382
|
+
helpers_invalid_params: 70010,
|
|
383
|
+
helpers_invalid_response: 70011,
|
|
169
384
|
/**
|
|
170
385
|
* Anything else
|
|
171
386
|
*/
|
|
@@ -183,15 +398,20 @@ export class SwapKitError extends Error {
|
|
|
183
398
|
) {
|
|
184
399
|
const isErrorString = typeof errorOrErrorKey === "string";
|
|
185
400
|
const errorKey = isErrorString ? errorOrErrorKey : errorOrErrorKey.errorKey;
|
|
186
|
-
const
|
|
401
|
+
const info = isErrorString ? undefined : errorOrErrorKey.info;
|
|
402
|
+
const message = `${errorKey}${info ? `: ${JSON.stringify(info)}` : ""}`;
|
|
187
403
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
404
|
+
super(message);
|
|
405
|
+
Object.setPrototypeOf(this, SwapKitError.prototype);
|
|
191
406
|
|
|
192
|
-
|
|
407
|
+
this.name = "SwapKitError";
|
|
408
|
+
this.cause = sourceErrorOrInfo;
|
|
193
409
|
|
|
194
|
-
|
|
195
|
-
|
|
410
|
+
// Log errors for debugging - bundlers can strip this in production if needed
|
|
411
|
+
if (sourceErrorOrInfo) {
|
|
412
|
+
console.error(`SwapKitError [${errorKey}]:`, sourceErrorOrInfo);
|
|
413
|
+
} else if (info) {
|
|
414
|
+
console.error(`SwapKitError [${errorKey}]:`, info);
|
|
415
|
+
}
|
|
196
416
|
}
|
|
197
417
|
}
|