@swapkit/helpers 3.0.0-beta.12 → 3.0.0-beta.13

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.
Files changed (64) hide show
  1. package/dist/api/index.cjs +2 -2
  2. package/dist/api/index.cjs.map +6 -6
  3. package/dist/api/index.js +2 -2
  4. package/dist/api/index.js.map +6 -6
  5. package/dist/{chunk-hk0jx7rp.js → chunk-7shcm26h.js} +3 -3
  6. package/dist/{chunk-hk0jx7rp.js.map → chunk-7shcm26h.js.map} +1 -1
  7. package/dist/chunk-8fdws4se.js +4 -0
  8. package/dist/chunk-8fdws4se.js.map +10 -0
  9. package/dist/{chunk-k2m9hvag.js → chunk-b8hashv0.js} +3 -3
  10. package/dist/{chunk-k2m9hvag.js.map → chunk-b8hashv0.js.map} +1 -1
  11. package/dist/{chunk-c4ndre32.js → chunk-bf0ph1bk.js} +3 -3
  12. package/dist/{chunk-c4ndre32.js.map → chunk-bf0ph1bk.js.map} +1 -1
  13. package/dist/{chunk-4mz4n5jc.js → chunk-bh986mnf.js} +3 -3
  14. package/dist/{chunk-4mz4n5jc.js.map → chunk-bh986mnf.js.map} +1 -1
  15. package/dist/{chunk-hbnf5tky.js → chunk-dzypg9sp.js} +3 -3
  16. package/dist/{chunk-hbnf5tky.js.map → chunk-dzypg9sp.js.map} +1 -1
  17. package/dist/{chunk-mt3sdnfg.js → chunk-ghdhtvtt.js} +3 -3
  18. package/dist/{chunk-mt3sdnfg.js.map → chunk-ghdhtvtt.js.map} +1 -1
  19. package/dist/{chunk-3ts9cha8.js → chunk-jhmhh7ax.js} +3 -3
  20. package/dist/{chunk-3ts9cha8.js.map → chunk-jhmhh7ax.js.map} +1 -1
  21. package/dist/{chunk-frkpmajq.js → chunk-nm1av1e6.js} +3 -3
  22. package/dist/{chunk-frkpmajq.js.map → chunk-nm1av1e6.js.map} +1 -1
  23. package/dist/{chunk-4edjz16h.js → chunk-rarep8vg.js} +3 -3
  24. package/dist/{chunk-4edjz16h.js.map → chunk-rarep8vg.js.map} +1 -1
  25. package/dist/{chunk-2vqx8ecy.js → chunk-rr043vwc.js} +3 -3
  26. package/dist/{chunk-2vqx8ecy.js.map → chunk-rr043vwc.js.map} +1 -1
  27. package/dist/{chunk-ganzk321.js → chunk-s82pm7xc.js} +2 -2
  28. package/dist/{chunk-ganzk321.js.map → chunk-s82pm7xc.js.map} +1 -1
  29. package/dist/chunk-sb9hymk1.js +3 -0
  30. package/dist/chunk-sb9hymk1.js.map +10 -0
  31. package/dist/{chunk-prm0g9b0.js → chunk-tn4e7zrk.js} +3 -3
  32. package/dist/{chunk-prm0g9b0.js.map → chunk-tn4e7zrk.js.map} +1 -1
  33. package/dist/{chunk-zv69dnwn.js → chunk-vadspc46.js} +3 -3
  34. package/dist/{chunk-zv69dnwn.js.map → chunk-vadspc46.js.map} +1 -1
  35. package/dist/{chunk-qpz3c078.js → chunk-vgg88vt8.js} +3 -3
  36. package/dist/{chunk-qpz3c078.js.map → chunk-vgg88vt8.js.map} +1 -1
  37. package/dist/{chunk-qkreqkaa.js → chunk-wssz50sc.js} +3 -3
  38. package/dist/{chunk-qkreqkaa.js.map → chunk-wssz50sc.js.map} +1 -1
  39. package/dist/contracts/index.js +1 -1
  40. package/dist/index.cjs +3 -3
  41. package/dist/index.cjs.map +15 -16
  42. package/dist/index.js +3 -3
  43. package/dist/index.js.map +15 -16
  44. package/dist/tokens/index.js +2 -2
  45. package/dist/tokens/index.js.map +2 -2
  46. package/package.json +2 -2
  47. package/src/api/midgard/endpoints.ts +6 -47
  48. package/src/api/swapkitApi/endpoints.ts +9 -26
  49. package/src/api/swapkitApi/types.ts +1 -1
  50. package/src/api/thornode/endpoints.ts +8 -26
  51. package/src/modules/__tests__/assetValue.test.ts +42 -0
  52. package/src/modules/__tests__/swapKitNumber.test.ts +4 -5
  53. package/src/modules/assetValue.ts +12 -28
  54. package/src/modules/bigIntArithmetics.ts +12 -1
  55. package/src/modules/requestClient.ts +36 -22
  56. package/src/modules/swapKitConfig.ts +1 -29
  57. package/src/modules/swapKitError.ts +294 -105
  58. package/src/types/chains.ts +45 -37
  59. package/src/types/derivationPath.ts +1 -0
  60. package/src/types/wallet.ts +2 -0
  61. package/src/utils/asset.ts +3 -2
  62. package/src/utils/memo.ts +5 -11
  63. package/src/utils/others.ts +1 -2
  64. package/src/utils/wallets.ts +4 -1
@@ -1,5 +1,5 @@
1
1
  import { createStore } from "zustand/vanilla";
2
- import { Chain, EXPLORER_URLS, NODE_URLS, RPC_URLS, StagenetChain, WalletOption } from "../types";
2
+ import { Chain, EXPLORER_URLS, NODE_URLS, RPC_URLS, WalletOption } from "../types";
3
3
 
4
4
  export type SKConfigIntegrations = {
5
5
  chainflip?: { useSDKBroker?: boolean; brokerUrl: string };
@@ -24,12 +24,6 @@ export type SKConfigIntegrations = {
24
24
  };
25
25
  };
26
26
 
27
- export type SKApiHeaders = {
28
- midgard?: Record<string, string>;
29
- thornode?: Record<string, string>;
30
- swapkitApi?: Record<string, string>;
31
- };
32
-
33
27
  const initialState = {
34
28
  // TODO: figure out how to type apis without using toolbox directly
35
29
  // Maybe move rpc/toolbox apis to helpers?
@@ -40,15 +34,6 @@ const initialState = {
40
34
  nodeUrls: NODE_URLS,
41
35
  rpcUrls: RPC_URLS,
42
36
 
43
- midgardUrls: {
44
- [Chain.THORChain]: "https://midgard.ninerealms.com",
45
- [Chain.Maya]: "https://midgard.mayachain.info",
46
- [StagenetChain.THORChain]: "https://stagenet-midgard.ninerealms.com",
47
- [StagenetChain.Maya]: "https://stagenet-midgard.mayachain.info",
48
- } as Partial<Record<Chain | StagenetChain, string>>,
49
-
50
- apiHeaders: {} as SKApiHeaders,
51
-
52
37
  apiKeys: {
53
38
  blockchair: "",
54
39
  keepKey: "",
@@ -80,12 +65,10 @@ type SKState = typeof initialState;
80
65
 
81
66
  export type SKConfigState = {
82
67
  apiKeys?: Partial<SKState["apiKeys"]>;
83
- apiHeaders?: Partial<SKApiHeaders>;
84
68
  chains?: SKState["chains"];
85
69
  envs?: Partial<SKState["envs"]>;
86
70
  explorerUrls?: Partial<SKState["explorerUrls"]>;
87
71
  integrations?: Partial<SKConfigIntegrations>;
88
- midgardUrls?: Partial<SKState["midgardUrls"]>;
89
72
  nodeUrls?: Partial<SKState["nodeUrls"]>;
90
73
  rpcUrls?: Partial<SKState["rpcUrls"]>;
91
74
  wallets?: SKState["wallets"];
@@ -93,11 +76,9 @@ export type SKConfigState = {
93
76
 
94
77
  type SwapKitConfigStore = SKState & {
95
78
  setApiKey: (key: keyof SKState["apiKeys"], apiKey: string) => void;
96
- setApiHeaders: (api: keyof SKApiHeaders, headers: Record<string, string>) => void;
97
79
  setConfig: (config: SKConfigState) => void;
98
80
  setEnv: <T extends keyof SKState["envs"]>(key: T, value: SKState["envs"][T]) => void;
99
81
  setExplorerUrl: (chain: keyof SKState["explorerUrls"], url: string) => void;
100
- setMidgardUrl: (chain: keyof SKState["midgardUrls"], url: string) => void;
101
82
  setNodeUrl: (chain: keyof SKState["nodeUrls"], url: string) => void;
102
83
  setRpcUrl: (chain: keyof SKState["rpcUrls"], url: string) => void;
103
84
  setIntegrationConfig: (
@@ -110,12 +91,9 @@ const swapKitState = createStore<SwapKitConfigStore>((set) => ({
110
91
  ...initialState,
111
92
 
112
93
  setApiKey: (key, apiKey) => set((s) => ({ apiKeys: { ...s.apiKeys, [key]: apiKey } })),
113
- setApiHeaders: (api, headers) =>
114
- set((s) => ({ apiHeaders: { ...s.apiHeaders, [api]: headers } })),
115
94
  setEnv: (key, value) => set((s) => ({ envs: { ...s.envs, [key]: value } })),
116
95
  setExplorerUrl: (chain, url) =>
117
96
  set((s) => ({ explorerUrls: { ...s.explorerUrls, [chain]: url } })),
118
- setMidgardUrl: (chain, url) => set((s) => ({ midgardUrls: { ...s.midgardUrls, [chain]: url } })),
119
97
  setNodeUrl: (chain, url) => set((s) => ({ nodeUrls: { ...s.nodeUrls, [chain]: url } })),
120
98
  setRpcUrl: (chain, url) => set((s) => ({ rpcUrls: { ...s.rpcUrls, [chain]: url } })),
121
99
  setIntegrationConfig: (integration, config) =>
@@ -123,11 +101,9 @@ const swapKitState = createStore<SwapKitConfigStore>((set) => ({
123
101
  setConfig: (config) =>
124
102
  set((s) => ({
125
103
  apiKeys: { ...s.apiKeys, ...config.apiKeys },
126
- apiHeaders: { ...s.apiHeaders, ...config.apiHeaders },
127
104
  envs: { ...s.envs, ...config.envs },
128
105
  explorerUrls: { ...s.explorerUrls, ...config.explorerUrls },
129
106
  integrations: { ...s.integrations, ...config.integrations },
130
- midgardUrls: { ...s.midgardUrls, ...config.midgardUrls },
131
107
  nodeUrls: { ...s.nodeUrls, ...config.nodeUrls },
132
108
  rpcUrls: { ...s.rpcUrls, ...config.rpcUrls },
133
109
  chains: s.chains.concat(config.chains || []),
@@ -142,14 +118,10 @@ export const SKConfig = {
142
118
 
143
119
  setApiKey: <T extends keyof SKState["apiKeys"]>(key: T, apiKey: string) =>
144
120
  swapKitState.getState().setApiKey(key, apiKey),
145
- setApiHeaders: <T extends keyof SKApiHeaders>(api: T, headers: Record<string, string>) =>
146
- swapKitState.getState().setApiHeaders(api, headers),
147
121
  setEnv: <T extends keyof SKState["envs"]>(key: T, value: SKState["envs"][T]) =>
148
122
  swapKitState.getState().setEnv(key, value),
149
123
  setExplorerUrl: <T extends keyof SKState["explorerUrls"]>(chain: T, url: string) =>
150
124
  swapKitState.getState().setExplorerUrl(chain, url),
151
- setMidgardUrl: <T extends keyof SKState["midgardUrls"]>(chain: T, url: string) =>
152
- swapKitState.getState().setMidgardUrl(chain, url),
153
125
  setNodeUrl: <T extends keyof SKState["nodeUrls"]>(chain: T, url: string) =>
154
126
  swapKitState.getState().setNodeUrl(chain, url),
155
127
  setRpcUrl: <T extends keyof SKState["rpcUrls"]>(chain: T, url: string) =>
@@ -2,44 +2,44 @@ const errorCodes = {
2
2
  /**
3
3
  * Core
4
4
  */
5
- core_estimated_max_spendable_chain_not_supported: 10002,
6
- core_extend_error: 10003,
7
- core_inbound_data_not_found: 10004,
8
- core_approve_asset_address_or_from_not_found: 10005,
9
- core_plugin_not_found: 10006,
10
- core_plugin_swap_not_found: 10007,
11
- core_approve_asset_target_invalid: 10008,
12
- core_explorer_unsupported_chain: 10009,
13
- core_verify_message_not_supported: 10010,
14
- core_chain_halted: 10099,
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: 10100,
19
- core_wallet_ctrl_not_installed: 10101,
20
- core_wallet_evmwallet_not_installed: 10102,
21
- core_wallet_walletconnect_not_installed: 10103,
22
- core_wallet_keystore_not_installed: 10104,
23
- core_wallet_ledger_not_installed: 10105,
24
- core_wallet_trezor_not_installed: 10106,
25
- core_wallet_keplr_not_installed: 10107,
26
- core_wallet_okx_not_installed: 10108,
27
- core_wallet_keepkey_not_installed: 10109,
28
- core_wallet_talisman_not_installed: 10110,
29
- core_wallet_not_keypair_wallet: 10111,
30
- core_wallet_sign_message_not_supported: 10110,
31
- core_wallet_connection_failed: 10112,
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: 10200,
36
- core_swap_route_not_complete: 10201,
37
- core_swap_asset_not_recognized: 10202,
38
- core_swap_contract_not_found: 10203,
39
- core_swap_route_transaction_not_found: 10204,
40
- core_swap_contract_not_supported: 10205,
41
- core_swap_transaction_error: 10206,
42
- core_swap_quote_mode_not_supported: 10207,
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,295 @@ 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
- wallet_keepkey_not_found: 20900,
94
- wallet_keepkey_asset_not_defined: 20901,
95
- wallet_keepkey_contract_address_not_provided: 20902,
96
- wallet_keepkey_send_transaction_no_address: 20903,
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
- wallet_exodus_sign_transaction_error: 21100,
99
- wallet_keystore_invalid_password: 29900,
100
- wallet_keystore_unsupported_version: 29901,
101
- wallet_onekey_not_found: 21200,
102
- wallet_onekey_sign_transaction_error: 21201,
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,
103
233
  /**
104
234
  * Chainflip
105
235
  */
106
236
  chainflip_channel_error: 30001,
107
237
  chainflip_unknown_asset: 30002,
108
- chainflip_broker_invalid_params: 30100,
109
- chainflip_broker_recipient_error: 30101,
110
- chainflip_broker_register: 30102,
111
- chainflip_broker_tx_error: 30103,
112
- chainflip_broker_withdraw: 30104,
113
- chainflip_broker_fund_only_flip_supported: 30105,
114
- chainflip_broker_fund_invalid_address: 30106,
238
+ /**
239
+ * Chainflip - Broker
240
+ */
241
+ chainflip_broker_invalid_params: 30101,
242
+ chainflip_broker_recipient_error: 30102,
243
+ chainflip_broker_register: 30103,
244
+ chainflip_broker_tx_error: 30104,
245
+ chainflip_broker_withdraw: 30105,
246
+ chainflip_broker_fund_only_flip_supported: 30106,
247
+ chainflip_broker_fund_invalid_address: 30107,
115
248
  /**
116
249
  * THORChain
117
250
  */
118
251
  thorchain_chain_halted: 40001,
119
252
  thorchain_trading_halted: 40002,
120
- thorchain_swapin_router_required: 40100,
121
- thorchain_swapin_vault_required: 40101,
122
- thorchain_swapin_memo_required: 40102,
123
- thorchain_swapin_token_required: 40103,
124
- thorchain_preferred_asset_payout_required: 40104,
253
+ /**
254
+ * THORChain - Swap
255
+ */
256
+ thorchain_swapin_router_required: 40101,
257
+ thorchain_swapin_vault_required: 40102,
258
+ thorchain_swapin_memo_required: 40103,
259
+ thorchain_swapin_token_required: 40104,
260
+ thorchain_preferred_asset_payout_required: 40105,
261
+ /**
262
+ * Toolboxes - Cosmos
263
+ */
264
+ toolbox_cosmos_account_not_found: 50101,
265
+ toolbox_cosmos_invalid_fee: 50102,
266
+ toolbox_cosmos_invalid_params: 50103,
267
+ toolbox_cosmos_no_signer: 50104,
268
+ toolbox_cosmos_not_supported: 50105,
269
+ toolbox_cosmos_signer_not_defined: 50106,
270
+ toolbox_cosmos_validate_address_prefix_not_found: 50107,
271
+ toolbox_cosmos_verify_signature_no_pubkey: 50108,
272
+ /**
273
+ * Toolboxes - EVM
274
+ */
275
+ toolbox_evm_error_estimating_gas_limit: 50201,
276
+ toolbox_evm_error_sending_transaction: 50202,
277
+ toolbox_evm_gas_estimation_error: 50203,
278
+ toolbox_evm_invalid_gas_asset_address: 50204,
279
+ toolbox_evm_invalid_params: 50205,
280
+ toolbox_evm_invalid_transaction: 50206,
281
+ toolbox_evm_no_abi_fragment: 50207,
282
+ toolbox_evm_no_contract_address: 50208,
283
+ toolbox_evm_no_fee_data: 50209,
284
+ toolbox_evm_no_from_address: 50210,
285
+ toolbox_evm_no_gas_price: 50211,
286
+ toolbox_evm_no_signer_address: 50212,
287
+ toolbox_evm_no_signer: 50213,
288
+ toolbox_evm_no_to_address: 50214,
289
+ toolbox_evm_not_supported: 50215,
290
+ toolbox_evm_provider_not_eip1193_compatible: 50216,
291
+ /**
292
+ * Toolboxes - UTXO
293
+ */
294
+ toolbox_utxo_api_error: 50301,
295
+ toolbox_utxo_broadcast_failed: 50302,
296
+ toolbox_utxo_insufficient_balance: 50303,
297
+ toolbox_utxo_invalid_address: 50304,
298
+ toolbox_utxo_invalid_params: 50305,
299
+ toolbox_utxo_invalid_transaction: 50306,
300
+ toolbox_utxo_no_signer: 50307,
301
+ toolbox_utxo_not_supported: 50308,
302
+ /**
303
+ * Toolboxes - Solana
304
+ */
305
+ toolbox_solana_no_signer: 50401,
306
+ toolbox_solana_fee_estimation_failed: 50402,
307
+ /**
308
+ * Toolboxes - Substrate
309
+ */
310
+ toolbox_substrate_not_supported: 50501,
311
+ /**
312
+ * Toolboxes - Radix
313
+ */
314
+ toolbox_radix_method_not_supported: 50601,
315
+ /**
316
+ * Toolboxes - Ripple
317
+ */
318
+ toolbox_ripple_get_balance_error: 50701,
319
+ toolbox_ripple_rpc_not_configured: 50702,
320
+ toolbox_ripple_signer_not_found: 50703,
321
+ toolbox_ripple_asset_not_supported: 50704,
322
+ toolbox_ripple_broadcast_error: 50705,
323
+ /**
324
+ * Toolboxes - Tron
325
+ */
326
+ toolbox_tron_no_signer: 50801,
327
+ toolbox_tron_invalid_token_identifier: 50802,
328
+ toolbox_tron_token_transfer_failed: 50803,
329
+ /**
330
+ * Toolboxes - General
331
+ */
332
+ toolbox_not_supported: 50801,
125
333
  /**
126
334
  * SwapKit API
127
335
  */
128
- api_v2_invalid_response: 50001,
129
- api_v2_server_error: 50002,
130
- api_v2_invalid_method_key_hash: 50003,
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,
336
+ api_v2_invalid_response: 60001,
337
+ api_v2_server_error: 60002,
338
+ api_v2_invalid_method_key_hash: 60003,
158
339
  /**
159
340
  * Helpers
160
341
  */
161
- helpers_invalid_number_different_decimals: 99000,
162
- helpers_invalid_number_of_years: 99001,
163
- helpers_invalid_identifier: 99002,
164
- helpers_invalid_asset_url: 99003,
165
- helpers_invalid_asset_identifier: 99004,
166
- helpers_invalid_memo_type: 99005,
167
- helpers_failed_to_switch_network: 99103,
168
- helpers_not_found_provider: 99200,
342
+ helpers_invalid_number_different_decimals: 70001,
343
+ helpers_invalid_number_of_years: 70002,
344
+ helpers_invalid_identifier: 70003,
345
+ helpers_invalid_asset_url: 70004,
346
+ helpers_invalid_asset_identifier: 70005,
347
+ helpers_invalid_memo_type: 70006,
348
+ helpers_failed_to_switch_network: 70007,
349
+ helpers_not_found_provider: 70008,
350
+ helpers_chain_not_supported: 70009,
351
+ helpers_invalid_params: 70010,
352
+ helpers_invalid_response: 70011,
169
353
  /**
170
354
  * Anything else
171
355
  */
@@ -183,15 +367,20 @@ export class SwapKitError extends Error {
183
367
  ) {
184
368
  const isErrorString = typeof errorOrErrorKey === "string";
185
369
  const errorKey = isErrorString ? errorOrErrorKey : errorOrErrorKey.errorKey;
186
- const message = `${errorKey}${isErrorString ? "" : `: ${JSON.stringify(errorOrErrorKey.info)}`}`;
370
+ const info = isErrorString ? undefined : errorOrErrorKey.info;
371
+ const message = `${errorKey}${info ? `: ${JSON.stringify(info)}` : ""}`;
187
372
 
188
- if (sourceErrorOrInfo) {
189
- console.error(sourceErrorOrInfo);
190
- }
373
+ super(message);
374
+ Object.setPrototypeOf(this, SwapKitError.prototype);
191
375
 
192
- console.error(errorKey, { code: SwapKitError.ErrorCode[errorKey], message });
376
+ this.name = "SwapKitError";
377
+ this.cause = sourceErrorOrInfo;
193
378
 
194
- super(errorKey);
195
- Object.setPrototypeOf(this, SwapKitError.prototype);
379
+ // Log errors for debugging - bundlers can strip this in production if needed
380
+ if (sourceErrorOrInfo) {
381
+ console.error(`SwapKitError [${errorKey}]:`, sourceErrorOrInfo);
382
+ } else if (info) {
383
+ console.error(`SwapKitError [${errorKey}]:`, info);
384
+ }
196
385
  }
197
386
  }