@tcswap/helpers 4.5.15

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