@swapkit/helpers 4.4.5 → 4.5.2

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 (69) hide show
  1. package/dist/api/index.cjs +2 -2
  2. package/dist/api/index.cjs.map +4 -4
  3. package/dist/api/index.js +2 -2
  4. package/dist/api/index.js.map +4 -4
  5. package/dist/index.cjs +3 -3
  6. package/dist/index.cjs.map +10 -10
  7. package/dist/index.js +3 -3
  8. package/dist/index.js.map +10 -10
  9. package/dist/types/api/index.d.ts +247 -0
  10. package/dist/types/api/index.d.ts.map +1 -1
  11. package/dist/types/api/swapkitApi/endpoints.d.ts +247 -0
  12. package/dist/types/api/swapkitApi/endpoints.d.ts.map +1 -1
  13. package/dist/types/api/swapkitApi/types.d.ts +3 -1
  14. package/dist/types/api/swapkitApi/types.d.ts.map +1 -1
  15. package/dist/types/modules/assetValue.d.ts +6 -0
  16. package/dist/types/modules/assetValue.d.ts.map +1 -1
  17. package/dist/types/modules/bigIntArithmetics.d.ts.map +1 -1
  18. package/dist/types/modules/swapKitConfig.d.ts +63 -36
  19. package/dist/types/modules/swapKitConfig.d.ts.map +1 -1
  20. package/dist/types/modules/swapKitError.d.ts +20 -24
  21. package/dist/types/modules/swapKitError.d.ts.map +1 -1
  22. package/dist/types/types/wallet.d.ts +5 -1
  23. package/dist/types/types/wallet.d.ts.map +1 -1
  24. package/dist/types/utils/asset.d.ts +1 -1
  25. package/dist/types/utils/asset.d.ts.map +1 -1
  26. package/package.json +24 -12
  27. package/src/api/index.ts +9 -0
  28. package/src/api/midgard/endpoints.ts +348 -0
  29. package/src/api/midgard/types.ts +515 -0
  30. package/src/api/swapkitApi/endpoints.ts +242 -0
  31. package/src/api/swapkitApi/types.ts +624 -0
  32. package/src/api/thornode/endpoints.ts +105 -0
  33. package/src/api/thornode/types.ts +247 -0
  34. package/src/contracts.ts +1 -0
  35. package/src/index.ts +28 -0
  36. package/src/modules/__tests__/assetValue.test.ts +1637 -0
  37. package/src/modules/__tests__/bigIntArithmetics.test.ts +383 -0
  38. package/src/modules/__tests__/swapKitConfig.test.ts +425 -0
  39. package/src/modules/__tests__/swapKitNumber.test.ts +535 -0
  40. package/src/modules/assetValue.ts +532 -0
  41. package/src/modules/bigIntArithmetics.ts +363 -0
  42. package/src/modules/feeMultiplier.ts +80 -0
  43. package/src/modules/requestClient.ts +110 -0
  44. package/src/modules/swapKitConfig.ts +174 -0
  45. package/src/modules/swapKitError.ts +470 -0
  46. package/src/modules/swapKitNumber.ts +13 -0
  47. package/src/tokens.ts +1 -0
  48. package/src/types/commonTypes.ts +10 -0
  49. package/src/types/derivationPath.ts +11 -0
  50. package/src/types/errors/apiV1.ts +0 -0
  51. package/src/types/index.ts +5 -0
  52. package/src/types/quotes.ts +174 -0
  53. package/src/types/sdk.ts +38 -0
  54. package/src/types/wallet.ts +124 -0
  55. package/src/utils/__tests__/asset.test.ts +185 -0
  56. package/src/utils/__tests__/derivationPath.test.ts +16 -0
  57. package/src/utils/__tests__/explorerUrls.test.ts +59 -0
  58. package/src/utils/__tests__/memo.test.ts +99 -0
  59. package/src/utils/__tests__/others.test.ts +83 -0
  60. package/src/utils/__tests__/validators.test.ts +24 -0
  61. package/src/utils/asset.ts +395 -0
  62. package/src/utils/chains.ts +100 -0
  63. package/src/utils/derivationPath.ts +101 -0
  64. package/src/utils/explorerUrls.ts +32 -0
  65. package/src/utils/liquidity.ts +150 -0
  66. package/src/utils/memo.ts +102 -0
  67. package/src/utils/others.ts +62 -0
  68. package/src/utils/validators.ts +32 -0
  69. package/src/utils/wallets.ts +237 -0
@@ -0,0 +1,174 @@
1
+ import {
2
+ AllChains,
3
+ type Chain,
4
+ getChainConfig,
5
+ StagenetChain,
6
+ StagenetMAYAConfig,
7
+ StagenetTHORConfig,
8
+ } from "@swapkit/types";
9
+ import { create } from "zustand";
10
+ import { useShallow } from "zustand/shallow";
11
+ import type { BalanceResponse, QuoteRequest, QuoteResponse, QuoteResponseRoute } from "../api";
12
+ import { WalletOption } from "../types";
13
+ import type { FeeMultiplierConfig } from "./feeMultiplier";
14
+
15
+ export type SKConfigIntegrations = {
16
+ chainflip?: { useSDKBroker?: boolean; brokerUrl: string };
17
+ coinbase?: {
18
+ appName: string;
19
+ appLogoUrl?: string | null;
20
+ darkMode?: boolean;
21
+ linkAPIUrl?: string;
22
+ overrideIsMetaMask?: boolean;
23
+ overrideIsCoinbaseWallet?: boolean;
24
+ overrideIsCoinbaseBrowser?: boolean;
25
+ headlessMode?: boolean;
26
+ reloadOnDisconnect?: boolean;
27
+ };
28
+ nearWalletSelector?: { contractId?: string };
29
+ trezor?: { email: string; appUrl: string };
30
+ keepKey?: { name: string; imageUrl: string; basePath: string; url: string };
31
+ radix: {
32
+ dAppDefinitionAddress: string;
33
+ applicationName: string;
34
+ applicationVersion: string;
35
+ network: { networkId: number; networkName: string; dashboardBase: string };
36
+ };
37
+ };
38
+
39
+ export type CustomApiEndpoints = {
40
+ getBalance: ({ chain, address }: { chain: Chain; address: string }) => Promise<BalanceResponse>;
41
+ getQuote: (json: QuoteRequest) => Promise<QuoteResponse>;
42
+ getRouteWithTx: (json: { routeId: string }) => Promise<QuoteResponseRoute>;
43
+ };
44
+
45
+ const rpcUrls = AllChains.reduce(
46
+ (acc, chain) => {
47
+ if (!acc.THOR_STAGENET) {
48
+ acc[StagenetChain.Maya] = StagenetMAYAConfig.rpcUrls;
49
+ acc[StagenetChain.THORChain] = StagenetTHORConfig.rpcUrls;
50
+ }
51
+
52
+ acc[chain] = getChainConfig(chain).rpcUrls;
53
+ return acc;
54
+ },
55
+ {} as { [key in Chain | StagenetChain]: string[] },
56
+ );
57
+
58
+ const initialState = {
59
+ apiKeys: { blockchair: "", keepKey: "", passkeys: "", swapKit: "", walletConnectProjectId: "", xaman: "" },
60
+ chains: AllChains,
61
+ endpoints: {} as CustomApiEndpoints,
62
+ envs: {
63
+ apiUrl: "https://api.swapkit.dev",
64
+ devApiUrl: "https://dev-api.swapkit.dev",
65
+ experimental_apiKey: null as string | null,
66
+ experimental_apiUrlQuote: null as string | null,
67
+ experimental_apiUrlSwap: null as string | null,
68
+ isDev: false,
69
+ isStagenet: false,
70
+ },
71
+ feeMultipliers: undefined as FeeMultiplierConfig | undefined,
72
+ integrations: {
73
+ radix: {
74
+ applicationName: "Swapkit Playground",
75
+ applicationVersion: "0.0.1",
76
+ dAppDefinitionAddress: "account_rdx128r289p58222hcvev7frs6kue76pl7pdcnw8725aw658v0zggkh9ws",
77
+ network: { dashboardBase: "https://dashboard.radixdlt.com", networkId: 1, networkName: "mainnet" },
78
+ },
79
+ } as SKConfigIntegrations,
80
+
81
+ requestOptions: { retry: { backoffMultiplier: 2, baseDelay: 300, maxDelay: 5000, maxRetries: 3 }, timeoutMs: 30000 },
82
+ rpcUrls,
83
+ wallets: Object.values(WalletOption),
84
+ };
85
+ type SKState = typeof initialState;
86
+
87
+ export type SKConfigState = {
88
+ apiKeys?: Partial<SKState["apiKeys"]>;
89
+ chains?: SKState["chains"];
90
+ endpoints?: Partial<CustomApiEndpoints>;
91
+ envs?: Partial<SKState["envs"]>;
92
+ integrations?: Partial<SKConfigIntegrations>;
93
+ rpcUrls?: Partial<SKState["rpcUrls"]>;
94
+ wallets?: SKState["wallets"];
95
+ feeMultipliers?: FeeMultiplierConfig;
96
+ };
97
+
98
+ type SwapKitConfigStore = SKState & {
99
+ setApiKey: (key: keyof SKState["apiKeys"], apiKey: string) => void;
100
+ setConfig: (config: SKConfigState) => void;
101
+ setEnv: <T extends keyof SKState["envs"]>(key: T, value: SKState["envs"][T]) => void;
102
+ setEndpoint: <T extends keyof CustomApiEndpoints>(key: T, endpoint: CustomApiEndpoints[T]) => void;
103
+ setRpcUrl: (chain: keyof SKState["rpcUrls"], url: string[]) => void;
104
+ setRequestOptions: (options: Partial<SKState["requestOptions"]>) => void;
105
+ setIntegrationConfig: (
106
+ integration: keyof SKState["integrations"],
107
+ config: SKConfigIntegrations[keyof SKConfigIntegrations],
108
+ ) => void;
109
+ setFeeMultipliers: (multipliers: FeeMultiplierConfig) => void;
110
+ };
111
+
112
+ export const useSwapKitStore = create<SwapKitConfigStore>((set) => ({
113
+ ...initialState,
114
+
115
+ setApiKey: (key, apiKey) => set((s) => ({ apiKeys: { ...s.apiKeys, [key]: apiKey } })),
116
+ setConfig: (config) =>
117
+ set((s) => ({
118
+ apiKeys: { ...s.apiKeys, ...config?.apiKeys },
119
+ chains: s.chains.concat(config?.chains || []),
120
+ endpoints: { ...s.endpoints, ...config?.endpoints },
121
+ envs: { ...s.envs, ...config?.envs },
122
+ feeMultipliers: config?.feeMultipliers || s.feeMultipliers,
123
+ integrations: { ...s.integrations, ...config?.integrations },
124
+ rpcUrls: { ...s.rpcUrls, ...config?.rpcUrls },
125
+ wallets: s.wallets.concat(config?.wallets || []),
126
+ })),
127
+ setEndpoint: (key, endpoint) => set((s) => ({ endpoints: { ...s.endpoints, [key]: endpoint } })),
128
+ setEnv: (key, value) => set((s) => ({ envs: { ...s.envs, [key]: value } })),
129
+ setFeeMultipliers: (multipliers) => set(() => ({ feeMultipliers: multipliers })),
130
+ setIntegrationConfig: (integration, config) =>
131
+ set((s) => ({ integrations: { ...s.integrations, [integration]: config } })),
132
+ setRequestOptions: (options) =>
133
+ set((s) => ({
134
+ requestOptions: {
135
+ retry: { ...s.requestOptions.retry, ...options.retry },
136
+ timeoutMs: options.timeoutMs || s.requestOptions.timeoutMs,
137
+ },
138
+ })),
139
+ setRpcUrl: (chain, url) => set((s) => ({ rpcUrls: { ...s.rpcUrls, [chain]: url } })),
140
+ }));
141
+
142
+ export const useSwapKitConfig = () =>
143
+ useSwapKitStore(
144
+ useShallow((state) => ({
145
+ apiKeys: state?.apiKeys,
146
+ chains: state?.chains,
147
+ endpoints: state?.endpoints,
148
+ envs: state?.envs,
149
+ feeMultipliers: state?.feeMultipliers,
150
+ integrations: state?.integrations,
151
+ rpcUrls: state?.rpcUrls,
152
+ wallets: state?.wallets,
153
+ })),
154
+ );
155
+
156
+ export const SKConfig = {
157
+ get: <T extends keyof SKState>(key: T) => useSwapKitStore.getState()[key],
158
+ getState: useSwapKitStore.getState,
159
+ reinitialize: () => useSwapKitStore.setState(initialState),
160
+ set: <T extends SKConfigState>(config: T) => useSwapKitStore.getState().setConfig(config),
161
+
162
+ setApiKey: <T extends keyof SKState["apiKeys"]>(key: T, apiKey: string) =>
163
+ useSwapKitStore.getState().setApiKey(key, apiKey),
164
+ setEndpoint: <T extends keyof CustomApiEndpoints>(key: T, endpoint: CustomApiEndpoints[T]) =>
165
+ useSwapKitStore.getState().setEndpoint(key, endpoint),
166
+ setEnv: <T extends keyof SKState["envs"]>(key: T, value: SKState["envs"][T]) =>
167
+ useSwapKitStore.getState().setEnv(key, value),
168
+ setFeeMultipliers: (multipliers: FeeMultiplierConfig) => useSwapKitStore.getState().setFeeMultipliers(multipliers),
169
+ setIntegrationConfig: <T extends keyof SKState["integrations"]>(integration: T, config: SKConfigIntegrations[T]) =>
170
+ useSwapKitStore.getState().setIntegrationConfig(integration, config),
171
+ setRequestOptions: (options: SKState["requestOptions"]) => useSwapKitStore.getState().setRequestOptions(options),
172
+ setRpcUrl: <T extends keyof SKState["rpcUrls"]>(chain: T, urls: string[]) =>
173
+ useSwapKitStore.getState().setRpcUrl(chain, urls),
174
+ };
@@ -0,0 +1,470 @@
1
+ /** biome-ignore-all assist/source/useSortedKeys: its sorted by type */
2
+ const errorCodes = {
3
+ /**
4
+ * Core
5
+ */
6
+ core_estimated_max_spendable_chain_not_supported: 10001,
7
+ core_extend_error: 10002,
8
+ core_inbound_data_not_found: 10003,
9
+ core_approve_asset_address_or_from_not_found: 10004,
10
+ core_plugin_not_found: 10005,
11
+ core_plugin_swap_not_found: 10006,
12
+ core_approve_asset_target_invalid: 10007,
13
+ core_explorer_unsupported_chain: 10008,
14
+ core_verify_message_not_supported: 10009,
15
+ core_chain_halted: 10010,
16
+ /**
17
+ * Core - Wallet
18
+ */
19
+ core_wallet_connection_not_found: 10101,
20
+ core_wallet_ctrl_not_installed: 10102,
21
+ core_wallet_evmwallet_not_installed: 10103,
22
+ core_wallet_walletconnect_not_installed: 10104,
23
+ core_wallet_keystore_not_installed: 10105,
24
+ core_wallet_ledger_not_installed: 10106,
25
+ core_wallet_trezor_not_installed: 10107,
26
+ core_wallet_keplr_not_installed: 10108,
27
+ core_wallet_okx_not_installed: 10109,
28
+ core_wallet_keepkey_not_installed: 10110,
29
+ core_wallet_talisman_not_installed: 10111,
30
+ core_wallet_not_keypair_wallet: 10112,
31
+ core_wallet_sign_message_not_supported: 10113,
32
+ core_wallet_connection_failed: 10114,
33
+ core_wallet_create_not_supported: 10115,
34
+ /**
35
+ * Core - Swap
36
+ */
37
+ core_swap_invalid_params: 10201,
38
+ core_swap_route_not_complete: 10202,
39
+ core_swap_asset_not_recognized: 10203,
40
+ core_swap_contract_not_found: 10204,
41
+ core_swap_route_transaction_not_found: 10205,
42
+ core_swap_contract_not_supported: 10206,
43
+ core_swap_transaction_error: 10207,
44
+ core_swap_quote_mode_not_supported: 10208,
45
+ /**
46
+ * Core - Transaction
47
+ */
48
+ core_transaction_deposit_error: 10301,
49
+ core_transaction_create_liquidity_base_error: 10302,
50
+ core_transaction_create_liquidity_asset_error: 10303,
51
+ core_transaction_create_liquidity_invalid_params: 10304,
52
+ core_transaction_add_liquidity_invalid_params: 10305,
53
+ core_transaction_add_liquidity_base_address: 10306,
54
+ core_transaction_add_liquidity_base_error: 10307,
55
+ core_transaction_add_liquidity_asset_error: 10308,
56
+ core_transaction_withdraw_error: 10309,
57
+ core_transaction_deposit_to_pool_error: 10310,
58
+ core_transaction_deposit_insufficient_funds_error: 10311,
59
+ core_transaction_deposit_gas_error: 10312,
60
+ core_transaction_invalid_sender_address: 10313,
61
+ core_transaction_deposit_server_error: 10314,
62
+ core_transaction_user_rejected: 10315,
63
+ core_transaction_failed: 10316,
64
+ core_transaction_invalid_recipient_address: 10317,
65
+ /**
66
+ * Wallets - General
67
+ */
68
+ wallet_connection_rejected_by_user: 20001,
69
+ wallet_missing_api_key: 20002,
70
+ wallet_chain_not_supported: 20003,
71
+ wallet_missing_params: 20004,
72
+ wallet_provider_not_found: 20005,
73
+ wallet_failed_to_add_or_switch_network: 20006,
74
+ /**
75
+ * Wallets - Ledger
76
+ */
77
+ wallet_ledger_connection_error: 20101,
78
+ wallet_ledger_connection_claimed: 20102,
79
+ wallet_ledger_get_address_error: 20103,
80
+ wallet_ledger_device_not_found: 20104,
81
+ wallet_ledger_device_locked: 20105,
82
+ wallet_ledger_transport_error: 20106,
83
+ wallet_ledger_public_key_error: 20107,
84
+ wallet_ledger_derivation_path_error: 20108,
85
+ wallet_ledger_signing_error: 20109,
86
+ wallet_ledger_app_not_open: 20110,
87
+ wallet_ledger_invalid_response: 20111,
88
+ wallet_ledger_method_not_supported: 20112,
89
+ wallet_ledger_invalid_params: 20113,
90
+ wallet_ledger_invalid_signature: 20114,
91
+ wallet_ledger_no_provider: 20115,
92
+ wallet_ledger_pubkey_not_found: 20116,
93
+ wallet_ledger_transport_not_defined: 20117,
94
+ wallet_ledger_webusb_not_supported: 20118,
95
+ wallet_ledger_chain_not_supported: 20119,
96
+ wallet_ledger_invalid_asset: 20120,
97
+ wallet_ledger_invalid_account: 20121,
98
+ wallet_ledger_address_not_found: 20122,
99
+ wallet_ledger_failed_to_get_address: 20123,
100
+ wallet_ledger_webhid_not_supported: 20124,
101
+ /**
102
+ * Wallets - Phantom
103
+ */
104
+ wallet_phantom_not_found: 20201,
105
+ /**
106
+ * Wallets - Ctrl
107
+ */
108
+ wallet_ctrl_not_found: 20301,
109
+ wallet_ctrl_send_transaction_no_address: 20302,
110
+ wallet_ctrl_contract_address_not_provided: 20303,
111
+ wallet_ctrl_asset_not_defined: 20304,
112
+ /**
113
+ * Wallets - WalletConnect
114
+ */
115
+ wallet_walletconnect_project_id_not_specified: 20401,
116
+ wallet_walletconnect_connection_not_established: 20402,
117
+ wallet_walletconnect_namespace_not_supported: 20403,
118
+ wallet_walletconnect_chain_not_supported: 20404,
119
+ wallet_walletconnect_invalid_method: 20405,
120
+ wallet_walletconnect_method_not_supported: 20406,
121
+ /**
122
+ * Wallets - Trezor
123
+ */
124
+ wallet_trezor_failed_to_sign_transaction: 20501,
125
+ wallet_trezor_derivation_path_not_supported: 20502,
126
+ wallet_trezor_failed_to_get_address: 20503,
127
+ wallet_trezor_transport_error: 20504,
128
+ wallet_trezor_method_not_supported: 20505,
129
+ /**
130
+ * Wallets - Talisman
131
+ */
132
+ wallet_talisman_not_enabled: 20601,
133
+ wallet_talisman_not_found: 20602,
134
+ /**
135
+ * Wallets - Polkadot
136
+ */
137
+ wallet_polkadot_not_found: 20701,
138
+ /**
139
+ * Wallets - Radix
140
+ */
141
+ wallet_radix_not_found: 20801,
142
+ wallet_radix_transaction_failed: 20802,
143
+ wallet_radix_invalid_manifest: 20803,
144
+ wallet_radix_method_not_supported: 20804,
145
+ wallet_radix_no_account: 20805,
146
+ /**
147
+ * Wallets - KeepKey
148
+ */
149
+ wallet_keepkey_not_found: 20901,
150
+ wallet_keepkey_asset_not_defined: 20902,
151
+ wallet_keepkey_contract_address_not_provided: 20903,
152
+ wallet_keepkey_send_transaction_no_address: 20904,
153
+ wallet_keepkey_derivation_path_error: 20905,
154
+ wallet_keepkey_signing_error: 20906,
155
+ wallet_keepkey_transport_error: 20907,
156
+ wallet_keepkey_unsupported_chain: 20908,
157
+ wallet_keepkey_invalid_response: 20909,
158
+ wallet_keepkey_chain_not_supported: 20910,
159
+ wallet_keepkey_signer_not_found: 20911,
160
+ wallet_keepkey_no_accounts: 20912,
161
+ wallet_keepkey_method_not_supported: 20913,
162
+ wallet_keepkey_invalid_params: 20914,
163
+ wallet_keepkey_config_not_found: 20915,
164
+ wallet_keepkey_no_provider: 20916,
165
+ wallet_keepkey_account_not_found: 20917,
166
+ /**
167
+ * Wallets - BitKeep/BitGet
168
+ */
169
+ wallet_bitkeep_not_found: 21001,
170
+ wallet_bitkeep_failed_to_switch_network: 21002,
171
+ wallet_bitkeep_no_accounts: 21003,
172
+ /**
173
+ * Wallets - Passkeys
174
+ */
175
+ wallet_passkeys_sign_transaction_error: 21101,
176
+ wallet_passkeys_not_found: 21102,
177
+ wallet_passkeys_no_address: 21103,
178
+ wallet_passkeys_request_canceled: 21104,
179
+ wallet_passkeys_signature_canceled: 21105,
180
+ wallet_passkeys_failed_to_switch_network: 21106,
181
+ wallet_passkeys_chain_not_supported: 21107,
182
+ wallet_passkeys_instance_missing: 21108,
183
+ /**
184
+ * Wallets - OneKey
185
+ */
186
+ wallet_onekey_not_found: 21201,
187
+ wallet_onekey_sign_transaction_error: 21202,
188
+ /**
189
+ * Wallets - OKX
190
+ */
191
+ wallet_okx_not_found: 21301,
192
+ wallet_okx_chain_not_supported: 21302,
193
+ wallet_okx_failed_to_switch_network: 21303,
194
+ wallet_okx_no_accounts: 21304,
195
+ /**
196
+ * Wallets - Keplr
197
+ */
198
+ wallet_keplr_not_found: 21401,
199
+ wallet_keplr_chain_not_supported: 21402,
200
+ wallet_keplr_signer_not_found: 21403,
201
+ wallet_keplr_no_accounts: 21404,
202
+ /**
203
+ * Wallets - Cosmostation
204
+ */
205
+ wallet_cosmostation_not_found: 21501,
206
+ wallet_cosmostation_chain_not_supported: 21502,
207
+ wallet_cosmostation_evm_provider_not_found: 21503,
208
+ wallet_cosmostation_keplr_provider_not_found: 21504,
209
+ wallet_cosmostation_no_accounts: 21505,
210
+ wallet_cosmostation_no_evm_accounts: 21506,
211
+ wallet_cosmostation_no_evm_address: 21507,
212
+ wallet_cosmostation_signer_not_found: 21508,
213
+ /**
214
+ * Wallets - ###EMPTY### 21601
215
+ */
216
+
217
+ /**
218
+ * Wallets - Coinbase
219
+ */
220
+ wallet_coinbase_not_found: 21701,
221
+ wallet_coinbase_chain_not_supported: 21702,
222
+ wallet_coinbase_method_not_supported: 21703,
223
+ wallet_coinbase_no_accounts: 21704,
224
+ /**
225
+ * Wallets - EVM Extensions
226
+ */
227
+ wallet_evm_extensions_failed_to_switch_network: 21801,
228
+ wallet_evm_extensions_no_provider: 21802,
229
+ wallet_evm_extensions_not_found: 21803,
230
+ /**
231
+ * Wallets - Keystore
232
+ */
233
+ wallet_keystore_invalid_password: 21901,
234
+ wallet_keystore_unsupported_version: 21902,
235
+ /**
236
+ * Wallets - Near Extensions
237
+ */
238
+ wallet_near_extensions_failed_to_switch_network: 22001,
239
+ wallet_near_extensions_no_provider: 22002,
240
+ wallet_near_extensions_not_found: 22003,
241
+ wallet_near_method_not_supported: 22003,
242
+ /**
243
+ * Wallets - Vultisig
244
+ */
245
+ wallet_vultisig_not_found: 22101,
246
+ wallet_vultisig_contract_address_not_provided: 22102,
247
+ wallet_vultisig_asset_not_defined: 22103,
248
+ wallet_vultisig_send_transaction_no_address: 22104,
249
+
250
+ /**
251
+ * Wallets - Xaman
252
+ */
253
+ wallet_xaman_not_configured: 23001,
254
+ wallet_xaman_not_connected: 23002,
255
+ wallet_xaman_auth_failed: 23003,
256
+ wallet_xaman_connection_failed: 23004,
257
+ wallet_xaman_transaction_failed: 23005,
258
+ wallet_xaman_monitoring_failed: 23006,
259
+ /**
260
+ * Wallets - TronLink
261
+ */
262
+ wallet_tronlink_request_accounts_failed: 24001,
263
+ wallet_tronlink_locked: 24002,
264
+
265
+ /**
266
+ * Chainflip
267
+ */
268
+ chainflip_channel_error: 30001,
269
+ chainflip_unknown_asset: 30002,
270
+ /**
271
+ * Chainflip - Broker
272
+ */
273
+ chainflip_broker_invalid_params: 30101,
274
+ chainflip_broker_recipient_error: 30102,
275
+ chainflip_broker_register: 30103,
276
+ chainflip_broker_tx_error: 30104,
277
+ chainflip_broker_withdraw: 30105,
278
+ chainflip_broker_fund_only_flip_supported: 30106,
279
+ chainflip_broker_fund_invalid_address: 30107,
280
+ /**
281
+ * THORChain
282
+ */
283
+ thorchain_chain_halted: 40001,
284
+ thorchain_trading_halted: 40002,
285
+ thorchain_asset_is_not_tcy: 40003,
286
+ /**
287
+ * THORChain - Swap
288
+ */
289
+ thorchain_swapin_router_required: 40101,
290
+ thorchain_swapin_vault_required: 40102,
291
+ thorchain_swapin_memo_required: 40103,
292
+ thorchain_swapin_token_required: 40104,
293
+ thorchain_preferred_asset_payout_required: 40105,
294
+ /**
295
+ * Toolboxes - Cosmos
296
+ */
297
+ toolbox_cosmos_account_not_found: 50101,
298
+ toolbox_cosmos_invalid_fee: 50102,
299
+ toolbox_cosmos_invalid_params: 50103,
300
+ toolbox_cosmos_no_signer: 50104,
301
+ toolbox_cosmos_not_supported: 50105,
302
+ toolbox_cosmos_signer_not_defined: 50106,
303
+ toolbox_cosmos_validate_address_prefix_not_found: 50107,
304
+ toolbox_cosmos_verify_signature_no_pubkey: 50108,
305
+ /**
306
+ * Toolboxes - EVM
307
+ */
308
+ toolbox_evm_error_estimating_gas_limit: 50201,
309
+ toolbox_evm_error_sending_transaction: 50202,
310
+ toolbox_evm_gas_estimation_error: 50203,
311
+ toolbox_evm_invalid_gas_asset_address: 50204,
312
+ toolbox_evm_invalid_params: 50205,
313
+ toolbox_evm_invalid_transaction: 50206,
314
+ toolbox_evm_no_abi_fragment: 50207,
315
+ toolbox_evm_no_contract_address: 50208,
316
+ toolbox_evm_no_fee_data: 50209,
317
+ toolbox_evm_no_from_address: 50210,
318
+ toolbox_evm_no_gas_price: 50211,
319
+ toolbox_evm_no_signer_address: 50212,
320
+ toolbox_evm_no_signer: 50213,
321
+ toolbox_evm_no_to_address: 50214,
322
+ toolbox_evm_not_supported: 50215,
323
+ toolbox_evm_provider_not_eip1193_compatible: 50216,
324
+ /**
325
+ * Toolboxes - UTXO
326
+ */
327
+ toolbox_utxo_api_error: 50301,
328
+ toolbox_utxo_broadcast_failed: 50302,
329
+ toolbox_utxo_insufficient_balance: 50303,
330
+ toolbox_utxo_invalid_address: 50304,
331
+ toolbox_utxo_invalid_params: 50305,
332
+ toolbox_utxo_invalid_transaction: 50306,
333
+ toolbox_utxo_no_signer: 50307,
334
+ toolbox_utxo_not_supported: 50308,
335
+ /**
336
+ * Toolboxes - Solana
337
+ */
338
+ toolbox_solana_no_signer: 50401,
339
+ toolbox_solana_fee_estimation_failed: 50402,
340
+ /**
341
+ * Toolboxes - Substrate
342
+ */
343
+ toolbox_substrate_not_supported: 50501,
344
+ toolbox_substrate_transfer_error: 50502,
345
+ /**
346
+ * Toolboxes - Radix
347
+ */
348
+ toolbox_radix_method_not_supported: 50601,
349
+ /**
350
+ * Toolboxes - Ripple
351
+ */
352
+ toolbox_ripple_get_balance_error: 50701,
353
+ toolbox_ripple_rpc_not_configured: 50702,
354
+ toolbox_ripple_signer_not_found: 50703,
355
+ toolbox_ripple_asset_not_supported: 50704,
356
+ toolbox_ripple_broadcast_error: 50705,
357
+ /**
358
+ * Toolboxes - Tron
359
+ */
360
+ toolbox_tron_no_signer: 50801,
361
+ toolbox_tron_invalid_token_identifier: 50802,
362
+ toolbox_tron_token_transfer_failed: 50803,
363
+ toolbox_tron_transaction_creation_failed: 50804,
364
+ toolbox_tron_fee_estimation_failed: 50805,
365
+ toolbox_tron_trongrid_api_error: 50806,
366
+ toolbox_tron_approve_failed: 50807,
367
+ toolbox_tron_invalid_token_contract: 50808,
368
+ toolbox_tron_allowance_check_failed: 50809,
369
+ /**
370
+ * Toolboxes - Near
371
+ */
372
+ toolbox_near_no_signer: 90601,
373
+ toolbox_near_invalid_address: 90602,
374
+ toolbox_near_invalid_amount: 90603,
375
+ toolbox_near_transfer_failed: 90604,
376
+ toolbox_near_access_key_error: 90605,
377
+ toolbox_near_no_rpc_url: 90606,
378
+ toolbox_near_empty_batch: 90607,
379
+ toolbox_near_balance_failed: 90608,
380
+ toolbox_near_invalid_name: 90609,
381
+ toolbox_near_missing_contract_address: 90610,
382
+ toolbox_near_no_account: 90611,
383
+ toolbox_near_invalid_gas_params: 90612,
384
+ toolbox_near_no_public_key_found: 90613,
385
+ /**
386
+ * Toolboxes - SUI
387
+ */
388
+ toolbox_sui_address_required: 90701,
389
+ toolbox_sui_keypair_required: 90702,
390
+ toolbox_sui_balance_error: 90703,
391
+ toolbox_sui_transaction_creation_error: 90704,
392
+ toolbox_sui_signing_error: 90705,
393
+ toolbox_sui_broadcast_error: 90706,
394
+ toolbox_sui_no_signer: 90707,
395
+ toolbox_sui_no_sender: 90708,
396
+ /**
397
+ * Toolboxes - General
398
+ */
399
+ toolbox_not_supported: 59901,
400
+ /**
401
+ * NEAR Plugin
402
+ */
403
+ plugin_near_invalid_name: 41001,
404
+ plugin_near_no_connection: 41002,
405
+ plugin_near_name_unavailable: 41003,
406
+ plugin_near_registration_failed: 41004,
407
+ plugin_near_transfer_failed: 41005,
408
+ /**
409
+ * Garden Plugin
410
+ */
411
+ plugin_garden_missing_data: 42001,
412
+ /**
413
+ * SwapKit API
414
+ */
415
+ api_v2_invalid_response: 60001,
416
+ api_v2_server_error: 60002,
417
+ api_v2_invalid_method_key_hash: 60003,
418
+ /**
419
+ * Helpers
420
+ */
421
+ helpers_invalid_number_different_decimals: 70001,
422
+ helpers_invalid_number_of_years: 70002,
423
+ helpers_invalid_identifier: 70003,
424
+ helpers_invalid_asset_url: 70004,
425
+ helpers_invalid_asset_identifier: 70005,
426
+ helpers_invalid_memo_type: 70006,
427
+ helpers_failed_to_switch_network: 70007,
428
+ helpers_not_found_provider: 70008,
429
+ helpers_chain_not_supported: 70009,
430
+ helpers_invalid_params: 70010,
431
+ helpers_invalid_response: 70011,
432
+ helpers_chain_no_public_or_set_rpc_url: 70012,
433
+ /**
434
+ * Anything else
435
+ */
436
+ not_implemented: 99999,
437
+ } as const;
438
+
439
+ export type ErrorKeys = keyof typeof errorCodes;
440
+
441
+ export class SwapKitError extends Error {
442
+ static ErrorCode = errorCodes;
443
+
444
+ constructor(
445
+ errorOrErrorKey: ErrorKeys | { errorKey: ErrorKeys; info?: Record<string, any> },
446
+ sourceErrorOrInfo?: any,
447
+ ) {
448
+ const isErrorString = typeof errorOrErrorKey === "string";
449
+ const errorKey = isErrorString ? errorOrErrorKey : errorOrErrorKey.errorKey;
450
+ const info = isErrorString ? undefined : errorOrErrorKey.info;
451
+ const message = `${errorKey}${info ? `: ${JSON.stringify(info)}` : ""}`;
452
+
453
+ super(message);
454
+ Object.setPrototypeOf(this, SwapKitError.prototype);
455
+
456
+ this.name = "SwapKitError";
457
+ this.cause = sourceErrorOrInfo;
458
+
459
+ // Log errors for debugging - bundlers can strip this in production if needed
460
+ if (sourceErrorOrInfo) {
461
+ const errorMsg =
462
+ sourceErrorOrInfo instanceof Error
463
+ ? `${sourceErrorOrInfo.message}${sourceErrorOrInfo.cause ? ` (${sourceErrorOrInfo.cause})` : ""}`
464
+ : JSON.stringify(sourceErrorOrInfo);
465
+ console.error(`SwapKitError [${errorKey}]: ${errorMsg}`);
466
+ } else if (info) {
467
+ console.error(`SwapKitError [${errorKey}]: ${JSON.stringify(info)}`);
468
+ }
469
+ }
470
+ }
@@ -0,0 +1,13 @@
1
+ import { BigIntArithmetics, formatBigIntToSafeValue } from "./bigIntArithmetics";
2
+
3
+ export type SwapKitValueType = BigIntArithmetics | string | number;
4
+
5
+ export class SwapKitNumber extends BigIntArithmetics {
6
+ eq(value: SwapKitValueType) {
7
+ return this.eqValue(value);
8
+ }
9
+
10
+ static fromBigInt(value: bigint, decimal?: number) {
11
+ return new SwapKitNumber({ decimal, value: formatBigIntToSafeValue({ bigIntDecimal: decimal, decimal, value }) });
12
+ }
13
+ }
package/src/tokens.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "@swapkit/tokens";
@@ -0,0 +1,10 @@
1
+ import type { Chain } from "@swapkit/types";
2
+ import type { ChainWallet } from "./wallet";
3
+
4
+ export type AddChainType<M = { [key in string]: any }> = <T extends Chain>(
5
+ params: Omit<ChainWallet<T>, "balance"> & M,
6
+ ) => void;
7
+
8
+ export type Witness = { value: number; script: Buffer };
9
+
10
+ export type Asset = { chain: Chain; symbol: string; ticker: string; synth?: boolean };
@@ -0,0 +1,11 @@
1
+ import { AllChains, type Chain, getChainConfig } from "@swapkit/types";
2
+
3
+ export type DerivationPathArray = ReturnType<typeof getChainConfig>["networkDerivationPath"];
4
+
5
+ export const NetworkDerivationPath = AllChains.reduce(
6
+ (acc, chain) => {
7
+ acc[chain] = getChainConfig(chain).networkDerivationPath;
8
+ return acc;
9
+ },
10
+ {} as Record<Chain, DerivationPathArray>,
11
+ );
File without changes
@@ -0,0 +1,5 @@
1
+ export * from "./commonTypes";
2
+ export * from "./derivationPath";
3
+ export * from "./quotes";
4
+ export * from "./sdk";
5
+ export * from "./wallet";