@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,429 @@
1
+ /**
2
+ * Modifications © 2025 Horizontal Systems.
3
+ */
4
+
5
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
6
+ import { Chain } from "@tcswap/types";
7
+ import { FeeOption } from "../../types";
8
+ import { USwapConfig } from "../uSwapConfig";
9
+
10
+ beforeAll(() => {
11
+ USwapConfig.reinitialize();
12
+ });
13
+
14
+ afterAll(() => {
15
+ USwapConfig.reinitialize();
16
+ });
17
+
18
+ describe("uSwapConfig", () => {
19
+ test("properly sets api keys", () => {
20
+ const initialState = USwapConfig.get("apiKeys").uSwap;
21
+ expect(initialState).toBe("");
22
+
23
+ USwapConfig.setApiKey("uSwap", "123");
24
+
25
+ const changedState = USwapConfig.get("apiKeys").uSwap;
26
+ expect(changedState).toBe("123");
27
+ });
28
+
29
+ test("do not drop if other keys are changed", () => {
30
+ USwapConfig.setApiKey("uSwap", "123");
31
+ expect(USwapConfig.get("apiKeys").uSwap).toBe("123");
32
+
33
+ USwapConfig.setApiKey("walletConnectProjectId", "123");
34
+ expect(USwapConfig.get("apiKeys")).toMatchObject({ uSwap: "123", walletConnectProjectId: "123" });
35
+
36
+ USwapConfig.setRpcUrl(Chain.Ethereum, ["https://lul.xyz"]);
37
+ expect(USwapConfig.getState()).toMatchObject({
38
+ apiKeys: { uSwap: "123", walletConnectProjectId: "123" },
39
+ rpcUrls: { [Chain.Ethereum]: ["https://lul.xyz"] },
40
+ });
41
+ });
42
+
43
+ describe("setConfig", () => {
44
+ test("merges chains without duplicates", () => {
45
+ USwapConfig.reinitialize();
46
+
47
+ const initialChains = USwapConfig.get("chains");
48
+ const initialLength = initialChains.length;
49
+
50
+ USwapConfig.set({ chains: [Chain.Ethereum, Chain.Bitcoin] });
51
+
52
+ const newChains = USwapConfig.get("chains");
53
+ // Should add new chains (if not already present)
54
+ expect(newChains.length).toBeGreaterThanOrEqual(initialLength);
55
+ expect(newChains).toContain(Chain.Ethereum);
56
+ expect(newChains).toContain(Chain.Bitcoin);
57
+ });
58
+
59
+ test("merges wallets array", () => {
60
+ USwapConfig.reinitialize();
61
+
62
+ const initialWallets = USwapConfig.get("wallets");
63
+ USwapConfig.set({ wallets: initialWallets });
64
+
65
+ const newWallets = USwapConfig.get("wallets");
66
+ expect(newWallets.length).toBeGreaterThanOrEqual(initialWallets.length);
67
+ });
68
+
69
+ test("merges apiKeys without overwriting", () => {
70
+ USwapConfig.reinitialize();
71
+
72
+ USwapConfig.setApiKey("uSwap", "test-key-1");
73
+ USwapConfig.set({ apiKeys: { blockchair: "blockchair-key" } });
74
+
75
+ const apiKeys = USwapConfig.get("apiKeys");
76
+ expect(apiKeys.uSwap).toBe("test-key-1");
77
+ expect(apiKeys.blockchair).toBe("blockchair-key");
78
+ });
79
+
80
+ test("merges envs object", () => {
81
+ USwapConfig.reinitialize();
82
+
83
+ USwapConfig.set({ envs: { isDev: true } });
84
+
85
+ const envs = USwapConfig.get("envs");
86
+ expect(envs.isDev).toBe(true);
87
+ expect(envs.apiUrl).toBeDefined(); // Should preserve other env values
88
+ });
89
+
90
+ test("merges rpcUrls", () => {
91
+ USwapConfig.reinitialize();
92
+
93
+ USwapConfig.set({
94
+ rpcUrls: { [Chain.Ethereum]: ["https://custom-eth-rpc.com"], [Chain.Bitcoin]: ["https://custom-btc-rpc.com"] },
95
+ });
96
+
97
+ const rpcUrls = USwapConfig.get("rpcUrls");
98
+ expect(rpcUrls[Chain.Ethereum]).toEqual(["https://custom-eth-rpc.com"]);
99
+ expect(rpcUrls[Chain.Bitcoin]).toEqual(["https://custom-btc-rpc.com"]);
100
+ });
101
+
102
+ test("merges integrations config", () => {
103
+ USwapConfig.reinitialize();
104
+
105
+ USwapConfig.set({ integrations: { coinbase: { appName: "Test App", darkMode: true } } });
106
+
107
+ const integrations = USwapConfig.get("integrations");
108
+ expect(integrations.coinbase?.appName).toBe("Test App");
109
+ expect(integrations.radix).toBeDefined(); // Should preserve default radix config
110
+ });
111
+
112
+ test("sets feeMultipliers", () => {
113
+ USwapConfig.reinitialize();
114
+
115
+ const feeMultipliers = { [FeeOption.Average]: 1.0, [FeeOption.Fast]: 1.5, [FeeOption.Fastest]: 2.0 };
116
+
117
+ USwapConfig.set({ feeMultipliers });
118
+
119
+ const result = USwapConfig.get("feeMultipliers");
120
+ expect(result).toEqual(feeMultipliers);
121
+ });
122
+ });
123
+
124
+ describe("setEnv", () => {
125
+ test("sets isDev flag", () => {
126
+ USwapConfig.reinitialize();
127
+
128
+ USwapConfig.setEnv("isDev", true);
129
+ expect(USwapConfig.get("envs").isDev).toBe(true);
130
+
131
+ USwapConfig.setEnv("isDev", false);
132
+ expect(USwapConfig.get("envs").isDev).toBe(false);
133
+ });
134
+
135
+ test("sets isStagenet flag", () => {
136
+ USwapConfig.reinitialize();
137
+
138
+ USwapConfig.setEnv("isStagenet", true);
139
+ expect(USwapConfig.get("envs").isStagenet).toBe(true);
140
+
141
+ USwapConfig.setEnv("isStagenet", false);
142
+ expect(USwapConfig.get("envs").isStagenet).toBe(false);
143
+ });
144
+
145
+ test("sets apiUrl", () => {
146
+ USwapConfig.reinitialize();
147
+
148
+ const customUrl = "https://custom-api.example.com";
149
+ USwapConfig.setEnv("apiUrl", customUrl);
150
+ expect(USwapConfig.get("envs").apiUrl).toBe(customUrl);
151
+ });
152
+
153
+ test("sets devApiUrl", () => {
154
+ USwapConfig.reinitialize();
155
+
156
+ const customDevUrl = "https://custom-dev-api.example.com";
157
+ USwapConfig.setEnv("devApiUrl", customDevUrl);
158
+ expect(USwapConfig.get("envs").devApiUrl).toBe(customDevUrl);
159
+ });
160
+ });
161
+
162
+ describe("setRpcUrl", () => {
163
+ test("sets RPC URL for single chain", () => {
164
+ USwapConfig.reinitialize();
165
+
166
+ const customRpcUrls = ["https://custom-eth.rpc.com", "https://backup-eth.rpc.com"];
167
+ USwapConfig.setRpcUrl(Chain.Ethereum, customRpcUrls);
168
+
169
+ expect(USwapConfig.get("rpcUrls")[Chain.Ethereum]).toEqual(customRpcUrls);
170
+ });
171
+
172
+ test("sets RPC URL for multiple chains", () => {
173
+ USwapConfig.reinitialize();
174
+
175
+ USwapConfig.setRpcUrl(Chain.Ethereum, ["https://eth.rpc.com"]);
176
+ USwapConfig.setRpcUrl(Chain.Avalanche, ["https://avax.rpc.com"]);
177
+
178
+ const rpcUrls = USwapConfig.get("rpcUrls");
179
+ expect(rpcUrls[Chain.Ethereum]).toEqual(["https://eth.rpc.com"]);
180
+ expect(rpcUrls[Chain.Avalanche]).toEqual(["https://avax.rpc.com"]);
181
+ });
182
+
183
+ test("overwrites existing RPC URLs", () => {
184
+ USwapConfig.reinitialize();
185
+
186
+ USwapConfig.setRpcUrl(Chain.Bitcoin, ["https://btc-old.rpc.com"]);
187
+ USwapConfig.setRpcUrl(Chain.Bitcoin, ["https://btc-new.rpc.com"]);
188
+
189
+ expect(USwapConfig.get("rpcUrls")[Chain.Bitcoin]).toEqual(["https://btc-new.rpc.com"]);
190
+ });
191
+ });
192
+
193
+ describe("setIntegrationConfig", () => {
194
+ test("sets Radix integration config", () => {
195
+ USwapConfig.reinitialize();
196
+
197
+ const radixConfig = {
198
+ applicationName: "Test DApp",
199
+ applicationVersion: "1.0.0",
200
+ dAppDefinitionAddress: "account_test123",
201
+ network: { dashboardBase: "https://stokenet-dashboard.radixdlt.com", networkId: 2, networkName: "stokenet" },
202
+ };
203
+
204
+ USwapConfig.setIntegrationConfig("radix", radixConfig);
205
+
206
+ const result = USwapConfig.get("integrations").radix;
207
+ expect(result).toEqual(radixConfig);
208
+ });
209
+
210
+ test("sets Coinbase integration config", () => {
211
+ USwapConfig.reinitialize();
212
+
213
+ const coinbaseConfig = { appLogoUrl: "https://example.com/logo.png", appName: "My Coinbase App", darkMode: true };
214
+
215
+ USwapConfig.setIntegrationConfig("coinbase", coinbaseConfig);
216
+
217
+ const result = USwapConfig.get("integrations").coinbase;
218
+ expect(result?.appName).toBe("My Coinbase App");
219
+ expect(result?.darkMode).toBe(true);
220
+ });
221
+
222
+ test("sets Trezor integration config", () => {
223
+ USwapConfig.reinitialize();
224
+
225
+ const trezorConfig = { appUrl: "https://example.com", email: "test@example.com" };
226
+
227
+ USwapConfig.setIntegrationConfig("trezor", trezorConfig);
228
+
229
+ const result = USwapConfig.get("integrations").trezor;
230
+ expect(result).toEqual(trezorConfig);
231
+ });
232
+
233
+ test("sets KeepKey integration config", () => {
234
+ USwapConfig.reinitialize();
235
+
236
+ const keepKeyConfig = {
237
+ basePath: "/keepkey",
238
+ imageUrl: "https://example.com/icon.png",
239
+ name: "Test App",
240
+ url: "https://example.com",
241
+ };
242
+
243
+ USwapConfig.setIntegrationConfig("keepKey", keepKeyConfig);
244
+
245
+ const result = USwapConfig.get("integrations").keepKey;
246
+ expect(result).toEqual(keepKeyConfig);
247
+ });
248
+
249
+ test("sets Chainflip integration config", () => {
250
+ USwapConfig.reinitialize();
251
+
252
+ const chainflipConfig = { brokerUrl: "https://broker.chainflip.io", useSDKBroker: true };
253
+
254
+ USwapConfig.setIntegrationConfig("chainflip", chainflipConfig);
255
+
256
+ const result = USwapConfig.get("integrations").chainflip;
257
+ expect(result).toEqual(chainflipConfig);
258
+ });
259
+ });
260
+
261
+ describe("setRequestOptions", () => {
262
+ test("sets timeout option and preserves retry", () => {
263
+ USwapConfig.reinitialize();
264
+
265
+ const initialRetry = USwapConfig.get("requestOptions").retry;
266
+
267
+ USwapConfig.setRequestOptions({ retry: initialRetry, timeoutMs: 60000 });
268
+
269
+ const result = USwapConfig.get("requestOptions");
270
+ expect(result.timeoutMs).toBe(60000);
271
+ });
272
+
273
+ test("sets retry options with timeoutMs", () => {
274
+ USwapConfig.reinitialize();
275
+
276
+ USwapConfig.setRequestOptions({
277
+ retry: { backoffMultiplier: 3, baseDelay: 500, maxDelay: 10000, maxRetries: 5 },
278
+ timeoutMs: 30000,
279
+ });
280
+
281
+ const result = USwapConfig.get("requestOptions");
282
+ expect(result.retry.maxRetries).toBe(5);
283
+ expect(result.retry.baseDelay).toBe(500);
284
+ expect(result.retry.maxDelay).toBe(10000);
285
+ expect(result.retry.backoffMultiplier).toBe(3);
286
+ });
287
+
288
+ test("merges partial retry options", () => {
289
+ USwapConfig.reinitialize();
290
+
291
+ const initialRetry = USwapConfig.get("requestOptions").retry;
292
+ const initialTimeout = USwapConfig.get("requestOptions").timeoutMs;
293
+
294
+ USwapConfig.setRequestOptions({ retry: { ...initialRetry, maxRetries: 10 }, timeoutMs: initialTimeout });
295
+
296
+ const result = USwapConfig.get("requestOptions").retry;
297
+ expect(result.maxRetries).toBe(10);
298
+ // Should preserve other retry settings
299
+ expect(result.baseDelay).toBe(initialRetry.baseDelay);
300
+ expect(result.maxDelay).toBe(initialRetry.maxDelay);
301
+ });
302
+ });
303
+
304
+ describe("setFeeMultipliers", () => {
305
+ test("sets fee multipliers for options", () => {
306
+ USwapConfig.reinitialize();
307
+
308
+ const multipliers = { [FeeOption.Average]: 1.0, [FeeOption.Fast]: 1.5, [FeeOption.Fastest]: 2.0 };
309
+
310
+ USwapConfig.setFeeMultipliers(multipliers);
311
+
312
+ const result = USwapConfig.get("feeMultipliers");
313
+ expect(result).toEqual(multipliers);
314
+ });
315
+
316
+ test("overwrites existing fee multipliers", () => {
317
+ USwapConfig.reinitialize();
318
+
319
+ const multipliers1 = { [FeeOption.Average]: 1.0, [FeeOption.Fast]: 1.5, [FeeOption.Fastest]: 2.0 };
320
+
321
+ const multipliers2 = { [FeeOption.Average]: 1.2, [FeeOption.Fast]: 1.8, [FeeOption.Fastest]: 2.5 };
322
+
323
+ USwapConfig.setFeeMultipliers(multipliers1);
324
+ USwapConfig.setFeeMultipliers(multipliers2);
325
+
326
+ const result = USwapConfig.get("feeMultipliers");
327
+ expect(result).toEqual(multipliers2);
328
+ });
329
+ });
330
+
331
+ describe("reinitialize", () => {
332
+ test("resets all state to initial values", () => {
333
+ // Modify some state
334
+ USwapConfig.setApiKey("uSwap", "test-key");
335
+ USwapConfig.setEnv("isDev", true);
336
+ USwapConfig.setRpcUrl(Chain.Ethereum, ["https://custom.rpc.com"]);
337
+
338
+ // Reinitialize
339
+ USwapConfig.reinitialize();
340
+
341
+ // Verify reset
342
+ expect(USwapConfig.get("apiKeys").uSwap).toBe("");
343
+ expect(USwapConfig.get("envs").isDev).toBe(false);
344
+ // RPC URLs should be reset to defaults
345
+ expect(USwapConfig.get("rpcUrls")[Chain.Ethereum]).toBeDefined();
346
+ });
347
+
348
+ test("can set values after reinitialize", () => {
349
+ USwapConfig.reinitialize();
350
+
351
+ USwapConfig.setApiKey("uSwap", "new-key");
352
+ expect(USwapConfig.get("apiKeys").uSwap).toBe("new-key");
353
+ });
354
+ });
355
+
356
+ describe("getState", () => {
357
+ test("returns complete state object", () => {
358
+ USwapConfig.reinitialize();
359
+
360
+ const state = USwapConfig.getState();
361
+
362
+ expect(state).toHaveProperty("apiKeys");
363
+ expect(state).toHaveProperty("chains");
364
+ expect(state).toHaveProperty("envs");
365
+ expect(state).toHaveProperty("integrations");
366
+ expect(state).toHaveProperty("rpcUrls");
367
+ expect(state).toHaveProperty("wallets");
368
+ expect(state).toHaveProperty("requestOptions");
369
+ });
370
+
371
+ test("state contains expected structure", () => {
372
+ USwapConfig.reinitialize();
373
+
374
+ const state = USwapConfig.getState();
375
+
376
+ expect(Array.isArray(state.chains)).toBe(true);
377
+ expect(typeof state.apiKeys).toBe("object");
378
+ expect(typeof state.envs).toBe("object");
379
+ expect(typeof state.integrations).toBe("object");
380
+ expect(typeof state.rpcUrls).toBe("object");
381
+ });
382
+ });
383
+
384
+ describe("multiple API keys", () => {
385
+ test("sets and gets blockchair API key", () => {
386
+ USwapConfig.reinitialize();
387
+
388
+ USwapConfig.setApiKey("blockchair", "blockchair-key");
389
+ expect(USwapConfig.get("apiKeys").blockchair).toBe("blockchair-key");
390
+ });
391
+
392
+ test("sets and gets keepKey API key", () => {
393
+ USwapConfig.reinitialize();
394
+
395
+ USwapConfig.setApiKey("keepKey", "keepkey-key");
396
+ expect(USwapConfig.get("apiKeys").keepKey).toBe("keepkey-key");
397
+ });
398
+
399
+ test("sets and gets walletConnectProjectId", () => {
400
+ USwapConfig.reinitialize();
401
+
402
+ USwapConfig.setApiKey("walletConnectProjectId", "wc-project-id");
403
+ expect(USwapConfig.get("apiKeys").walletConnectProjectId).toBe("wc-project-id");
404
+ });
405
+
406
+ test("sets and gets xaman API key", () => {
407
+ USwapConfig.reinitialize();
408
+
409
+ USwapConfig.setApiKey("xaman", "xaman-key");
410
+ expect(USwapConfig.get("apiKeys").xaman).toBe("xaman-key");
411
+ });
412
+ });
413
+
414
+ describe("setEndpoint", () => {
415
+ test("sets endpoint", async () => {
416
+ USwapConfig.reinitialize();
417
+
418
+ USwapConfig.setEndpoint("getBalance", ({ chain }) =>
419
+ Promise.resolve([{ chain, decimal: 18, identifier: "ETH", symbol: "ETH", ticker: "ETH", value: "100" }]),
420
+ );
421
+
422
+ const result = await USwapConfig.get("endpoints").getBalance({ address: "0x123", chain: Chain.Ethereum });
423
+
424
+ expect(result).toEqual([
425
+ { chain: Chain.Ethereum, decimal: 18, identifier: "ETH", symbol: "ETH", ticker: "ETH", value: "100" },
426
+ ]);
427
+ });
428
+ });
429
+ });