@swapkit/helpers 3.0.0-beta.11 → 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 (67) hide show
  1. package/dist/api/index.cjs +2 -2
  2. package/dist/api/index.cjs.map +5 -5
  3. package/dist/api/index.js +2 -2
  4. package/dist/api/index.js.map +5 -5
  5. package/dist/{chunk-6vvdbb6s.js → chunk-7shcm26h.js} +3 -3
  6. package/dist/{chunk-6vvdbb6s.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-dbsrwnw2.js → chunk-b8hashv0.js} +3 -3
  10. package/dist/{chunk-dbsrwnw2.js.map → chunk-b8hashv0.js.map} +1 -1
  11. package/dist/{chunk-kdcsgh3q.js → chunk-bf0ph1bk.js} +3 -3
  12. package/dist/{chunk-kdcsgh3q.js.map → chunk-bf0ph1bk.js.map} +1 -1
  13. package/dist/{chunk-mmwvr2y8.js → chunk-bh986mnf.js} +3 -3
  14. package/dist/{chunk-mmwvr2y8.js.map → chunk-bh986mnf.js.map} +1 -1
  15. package/dist/{chunk-ahpfxkx0.js → chunk-dzypg9sp.js} +3 -3
  16. package/dist/{chunk-ahpfxkx0.js.map → chunk-dzypg9sp.js.map} +1 -1
  17. package/dist/{chunk-wmxwvv8c.js → chunk-ghdhtvtt.js} +3 -3
  18. package/dist/{chunk-wmxwvv8c.js.map → chunk-ghdhtvtt.js.map} +1 -1
  19. package/dist/{chunk-fr86y3rx.js → chunk-jhmhh7ax.js} +3 -3
  20. package/dist/{chunk-fr86y3rx.js.map → chunk-jhmhh7ax.js.map} +1 -1
  21. package/dist/{chunk-ekd1k975.js → chunk-nm1av1e6.js} +3 -3
  22. package/dist/{chunk-ekd1k975.js.map → chunk-nm1av1e6.js.map} +1 -1
  23. package/dist/{chunk-wrjh857m.js → chunk-rarep8vg.js} +3 -3
  24. package/dist/{chunk-wrjh857m.js.map → chunk-rarep8vg.js.map} +1 -1
  25. package/dist/{chunk-kr69v1tm.js → chunk-rr043vwc.js} +3 -3
  26. package/dist/{chunk-kr69v1tm.js.map → chunk-rr043vwc.js.map} +1 -1
  27. package/dist/{chunk-3wnfcm30.js → chunk-s82pm7xc.js} +2 -2
  28. package/dist/{chunk-3wnfcm30.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-tq87xn7m.js → chunk-tn4e7zrk.js} +3 -3
  32. package/dist/{chunk-tq87xn7m.js.map → chunk-tn4e7zrk.js.map} +1 -1
  33. package/dist/{chunk-z8emzpyc.js → chunk-vadspc46.js} +3 -3
  34. package/dist/{chunk-z8emzpyc.js.map → chunk-vadspc46.js.map} +1 -1
  35. package/dist/{chunk-xyczdrny.js → chunk-vgg88vt8.js} +3 -3
  36. package/dist/{chunk-xyczdrny.js.map → chunk-vgg88vt8.js.map} +1 -1
  37. package/dist/{chunk-q8xy3739.js → chunk-wssz50sc.js} +3 -3
  38. package/dist/{chunk-q8xy3739.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/microgard/types.ts +0 -3
  48. package/src/api/midgard/endpoints.ts +1 -65
  49. package/src/api/midgard/types.ts +0 -49
  50. package/src/api/swapkitApi/endpoints.ts +1 -2
  51. package/src/api/swapkitApi/types.ts +1 -1
  52. package/src/modules/__tests__/assetValue.test.ts +42 -0
  53. package/src/modules/__tests__/swapKitNumber.test.ts +4 -5
  54. package/src/modules/assetValue.ts +12 -28
  55. package/src/modules/bigIntArithmetics.ts +12 -1
  56. package/src/modules/requestClient.ts +36 -22
  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/quotes.ts +0 -2
  61. package/src/types/sdk.ts +0 -2
  62. package/src/types/wallet.ts +2 -0
  63. package/src/utils/__tests__/memo.test.ts +0 -20
  64. package/src/utils/asset.ts +3 -2
  65. package/src/utils/memo.ts +5 -42
  66. package/src/utils/others.ts +1 -2
  67. package/src/utils/wallets.ts +4 -1
@@ -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
  }
@@ -1,3 +1,6 @@
1
+ import { match } from "ts-pattern";
2
+ import { SwapKitError } from "../modules/swapKitError";
3
+
1
4
  export enum Chain {
2
5
  Arbitrum = "ARB",
3
6
  Avalanche = "AVAX",
@@ -22,6 +25,7 @@ export enum Chain {
22
25
  Ripple = "XRP",
23
26
  THORChain = "THOR",
24
27
  Solana = "SOL",
28
+ Tron = "TRX",
25
29
  }
26
30
 
27
31
  export enum StagenetChain {
@@ -62,6 +66,7 @@ export enum ChainId {
62
66
  THORChain = "thorchain-1",
63
67
  THORChainStagenet = "thorchain-stagenet-v2",
64
68
  Solana = "solana",
69
+ Tron = "tron",
65
70
  }
66
71
 
67
72
  export const ChainIdToChain: Record<ChainId, Chain> = {
@@ -97,6 +102,7 @@ export const ChainIdToChain: Record<ChainId, Chain> = {
97
102
  [ChainId.Solana]: Chain.Solana,
98
103
  [ChainId.THORChainStagenet]: Chain.THORChain,
99
104
  [ChainId.THORChain]: Chain.THORChain,
105
+ [ChainId.Tron]: Chain.Tron,
100
106
  };
101
107
 
102
108
  type ChainNameType = keyof typeof Chain;
@@ -125,6 +131,7 @@ export const BaseDecimal: Record<Chain, number> = {
125
131
  OP: 18,
126
132
  SOL: 9,
127
133
  THOR: 8,
134
+ TRX: 6,
128
135
  XRD: 18,
129
136
  XRP: 6,
130
137
  };
@@ -153,6 +160,7 @@ export const BlockTimes: Record<Partial<Chain>, number> = {
153
160
  [Chain.Ripple]: 5,
154
161
  [Chain.Solana]: 0.4,
155
162
  [Chain.THORChain]: 6,
163
+ [Chain.Tron]: 3,
156
164
  };
157
165
 
158
166
  export type SubstrateChain = Chain.Polkadot | Chain.Chainflip;
@@ -245,6 +253,7 @@ export const RPC_URLS: Record<Chain | StagenetChain, string> = {
245
253
  [Chain.Ripple]: "wss://xrpl.ws/",
246
254
  [Chain.Solana]: "https://solana-rpc.publicnode.com",
247
255
  [Chain.THORChain]: "https://rpc.thorswap.net",
256
+ [Chain.Tron]: "https://api.trongrid.io",
248
257
  [StagenetChain.Maya]: "https://stagenet.tendermint.mayachain.info",
249
258
  [StagenetChain.THORChain]: "https://stagenet-rpc.ninerealms.com",
250
259
  };
@@ -300,6 +309,7 @@ export const FALLBACK_URLS: Record<Chain | StagenetChain, string[]> = {
300
309
  [Chain.THORChain]: ["https://thornode.ninerealms.com", NODE_URLS[Chain.THORChain]],
301
310
  [StagenetChain.THORChain]: [],
302
311
  [Chain.Solana]: ["https://api.mainnet-beta.solana.com", "https://rpc.ankr.com/solana"],
312
+ [Chain.Tron]: ["https://api.tronstack.io", "https://api.tron.network"],
303
313
  };
304
314
 
305
315
  export const EXPLORER_URLS: Record<Chain, string> = {
@@ -326,51 +336,49 @@ export const EXPLORER_URLS: Record<Chain, string> = {
326
336
  [Chain.Ripple]: "https://livenet.xrpl.org/",
327
337
  [Chain.THORChain]: "https://runescan.io",
328
338
  [Chain.Solana]: "https://solscan.io",
339
+ [Chain.Tron]: "https://tronscan.org",
329
340
  };
330
341
 
331
342
  let RPCUrlsMerged = RPC_URLS;
332
343
 
333
344
  const getRpcBody = (chain: Chain | StagenetChain) => {
334
- switch (chain) {
335
- case Chain.Arbitrum:
336
- case Chain.Avalanche:
337
- case Chain.Base:
338
- case Chain.BinanceSmartChain:
339
- case Chain.Ethereum:
340
- case Chain.Optimism:
341
- case Chain.Polygon:
342
- return { id: 1, jsonrpc: "2.0", method: "eth_blockNumber", params: [] };
343
- case Chain.Bitcoin:
344
- case Chain.Dogecoin:
345
- case Chain.BitcoinCash:
346
- case Chain.Dash:
347
- case Chain.Litecoin:
348
- return { id: "test", jsonrpc: "1.0", method: "getblockchaininfo", params: [] };
349
- case Chain.Cosmos:
350
- case Chain.Kujira:
351
- case Chain.Maya:
352
- case Chain.THORChain:
353
- case StagenetChain.Maya:
354
- case StagenetChain.THORChain:
355
- return { id: 1, jsonrpc: "2.0", method: "status", params: {} };
356
- case Chain.Polkadot:
357
- return { id: 1, jsonrpc: "2.0", method: "system_health", params: [] };
358
- case Chain.Solana:
359
- return { id: 1, jsonrpc: "2.0", method: "getHealth" };
360
- case Chain.Radix:
361
- return "";
362
- default:
363
- throw new Error(`Unsupported chain: ${chain}`);
364
- }
345
+ return match(chain)
346
+ .with(
347
+ Chain.Arbitrum,
348
+ Chain.Avalanche,
349
+ Chain.Base,
350
+ Chain.BinanceSmartChain,
351
+ Chain.Ethereum,
352
+ Chain.Optimism,
353
+ Chain.Polygon,
354
+ Chain.Tron,
355
+ () => ({ id: 1, jsonrpc: "2.0", method: "eth_blockNumber", params: [] }),
356
+ )
357
+ .with(Chain.Bitcoin, Chain.Dogecoin, Chain.BitcoinCash, Chain.Dash, Chain.Litecoin, () => ({
358
+ id: "test",
359
+ jsonrpc: "1.0",
360
+ method: "getblockchaininfo",
361
+ params: [],
362
+ }))
363
+ .with(
364
+ Chain.Cosmos,
365
+ Chain.Kujira,
366
+ Chain.Maya,
367
+ Chain.THORChain,
368
+ StagenetChain.Maya,
369
+ StagenetChain.THORChain,
370
+ () => ({ id: 1, jsonrpc: "2.0", method: "status", params: {} }),
371
+ )
372
+ .with(Chain.Polkadot, () => ({ id: 1, jsonrpc: "2.0", method: "system_health", params: [] }))
373
+ .with(Chain.Solana, () => ({ id: 1, jsonrpc: "2.0", method: "getHealth" }))
374
+ .with(Chain.Radix, () => "")
375
+ .otherwise(() => {
376
+ throw new SwapKitError("helpers_chain_not_supported", { chain });
377
+ });
365
378
  };
366
379
 
367
380
  function getChainStatusEndpoint(chain: Chain | StagenetChain) {
368
- switch (chain) {
369
- case Chain.Radix:
370
- return "/status/network-configuration";
371
- default:
372
- return "";
373
- }
381
+ return chain === Chain.Radix ? "/status/network-configuration" : "";
374
382
  }
375
383
 
376
384
  const testRPCConnection = async (chain: Chain | StagenetChain, url: string) => {
@@ -32,6 +32,7 @@ export const NetworkDerivationPath: Record<Chain, DerivationPathArray> = {
32
32
  OP: [44, 60, 0, 0, 0],
33
33
  SOL: [44, 501, 0, 0, 0],
34
34
  THOR: [44, 931, 0, 0, 0],
35
+ TRX: [44, 195, 0, 0, 0],
35
36
 
36
37
  // Polkadot and related network derivation path is not number based
37
38
  DOT: [0, 0, 0, 0, 0],
@@ -76,7 +76,6 @@ export enum ErrorCode {
76
76
  addressScreeningFailed = "addressScreeningFailed",
77
77
  noLiquidtyProvidersFound = "noLiquidtyProvidersFound",
78
78
  insufficientLiquidity = "insufficientLiquidity",
79
- noSaversFound = "noSaversFound",
80
79
  noInboundDataFound = "noInbounDataFound",
81
80
  noInboundAddressesFound = "noInboundAddressesFound",
82
81
  noInboundAddressFoundForChain = "noInboundAddressFoundForChain",
@@ -110,7 +109,6 @@ export enum ErrorCode {
110
109
  thorchainPoolUnavailable = "thorchainPoolUnavailable",
111
110
  noOhlcvDataFound = "noOhlcvDataFound",
112
111
  noTradingPairs = "noTradingPairs",
113
- noLoanPositionFound = "noLoanPositionFound",
114
112
  noLendingAvailability = "noLendingAvailability",
115
113
  lendingRepayTooSmall = "lendingRepayTooSmall",
116
114
  missingState = "missingState",
package/src/types/sdk.ts CHANGED
@@ -34,8 +34,6 @@ export enum MemoType {
34
34
  LEAVE = "LEAVE",
35
35
  UNBOND = "UNBOND",
36
36
  WITHDRAW = "-",
37
- OPEN_LOAN = "$+",
38
- CLOSE_LOAN = "$-",
39
37
  RUNEPOOL_DEPOSIT = "POOL+",
40
38
  RUNEPOOL_WITHDRAW = "POOL-",
41
39
  }
@@ -4,6 +4,7 @@ import type { RadixWallet } from "@swapkit/toolboxes/radix";
4
4
  import type { RippleWallet } from "@swapkit/toolboxes/ripple";
5
5
  import type { SolanaWallet } from "@swapkit/toolboxes/solana";
6
6
  import type { SubstrateToolboxes } from "@swapkit/toolboxes/substrate";
7
+ import type { TronWallet } from "@swapkit/toolboxes/tron";
7
8
  import type { UTXOToolboxes } from "@swapkit/toolboxes/utxo";
8
9
  import type { BrowserProvider } from "ethers";
9
10
  import type { Eip1193Provider } from "ethers";
@@ -108,6 +109,7 @@ export type FullWallet = BaseWallet<
108
109
  [Chain.Radix]: RadixWallet;
109
110
  [Chain.Ripple]: RippleWallet;
110
111
  [Chain.Solana]: SolanaWallet;
112
+ [Chain.Tron]: TronWallet;
111
113
  }
112
114
  >;
113
115