@one_deploy/sdk 1.0.0

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 (83) hide show
  1. package/.turbo/turbo-build.log +0 -0
  2. package/.turbo/turbo-type-check.log +0 -0
  3. package/dist/config/index.d.mts +74 -0
  4. package/dist/config/index.d.ts +74 -0
  5. package/dist/config/index.js +242 -0
  6. package/dist/config/index.js.map +1 -0
  7. package/dist/config/index.mjs +224 -0
  8. package/dist/config/index.mjs.map +1 -0
  9. package/dist/engine-5ndtBaCr.d.ts +1039 -0
  10. package/dist/engine-CrlhH0nw.d.mts +1039 -0
  11. package/dist/hooks/index.d.mts +56 -0
  12. package/dist/hooks/index.d.ts +56 -0
  13. package/dist/hooks/index.js +1360 -0
  14. package/dist/hooks/index.js.map +1 -0
  15. package/dist/hooks/index.mjs +1356 -0
  16. package/dist/hooks/index.mjs.map +1 -0
  17. package/dist/index.d.mts +356 -0
  18. package/dist/index.d.ts +356 -0
  19. package/dist/index.js +5068 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/index.mjs +4949 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/price-CgqXPnT3.d.ts +13 -0
  24. package/dist/price-ClbLHHjv.d.mts +13 -0
  25. package/dist/providers/index.d.mts +121 -0
  26. package/dist/providers/index.d.ts +121 -0
  27. package/dist/providers/index.js +1642 -0
  28. package/dist/providers/index.js.map +1 -0
  29. package/dist/providers/index.mjs +1600 -0
  30. package/dist/providers/index.mjs.map +1 -0
  31. package/dist/react-native.d.mts +120 -0
  32. package/dist/react-native.d.ts +120 -0
  33. package/dist/react-native.js +1792 -0
  34. package/dist/react-native.js.map +1 -0
  35. package/dist/react-native.mjs +1755 -0
  36. package/dist/react-native.mjs.map +1 -0
  37. package/dist/services/index.d.mts +85 -0
  38. package/dist/services/index.d.ts +85 -0
  39. package/dist/services/index.js +1466 -0
  40. package/dist/services/index.js.map +1 -0
  41. package/dist/services/index.mjs +1458 -0
  42. package/dist/services/index.mjs.map +1 -0
  43. package/dist/types/index.d.mts +759 -0
  44. package/dist/types/index.d.ts +759 -0
  45. package/dist/types/index.js +4 -0
  46. package/dist/types/index.js.map +1 -0
  47. package/dist/types/index.mjs +3 -0
  48. package/dist/types/index.mjs.map +1 -0
  49. package/dist/utils/index.d.mts +36 -0
  50. package/dist/utils/index.d.ts +36 -0
  51. package/dist/utils/index.js +164 -0
  52. package/dist/utils/index.js.map +1 -0
  53. package/dist/utils/index.mjs +142 -0
  54. package/dist/utils/index.mjs.map +1 -0
  55. package/package.json +101 -0
  56. package/src/components/OneConnectButton.tsx +143 -0
  57. package/src/components/OneNFTGallery.tsx +324 -0
  58. package/src/components/OneOfframpWidget.tsx +660 -0
  59. package/src/components/OneOnrampWidget.tsx +596 -0
  60. package/src/components/OnePayWidget.tsx +160 -0
  61. package/src/components/OneReceiveWidget.tsx +272 -0
  62. package/src/components/OneSendWidget.tsx +248 -0
  63. package/src/components/OneSwapWidget.tsx +715 -0
  64. package/src/components/OneTransactionButton.tsx +150 -0
  65. package/src/components/OneWalletBalance.tsx +354 -0
  66. package/src/components/index.ts +24 -0
  67. package/src/config/index.ts +299 -0
  68. package/src/hooks/index.ts +2 -0
  69. package/src/hooks/useTokenPrice.ts +162 -0
  70. package/src/hooks/useWalletBalance.ts +98 -0
  71. package/src/index.ts +193 -0
  72. package/src/providers/OneProvider.tsx +452 -0
  73. package/src/providers/ThirdwebProvider.tsx +203 -0
  74. package/src/providers/index.ts +26 -0
  75. package/src/react-native.ts +378 -0
  76. package/src/services/engine.ts +1854 -0
  77. package/src/services/index.ts +30 -0
  78. package/src/services/price.ts +164 -0
  79. package/src/services/supabase.ts +180 -0
  80. package/src/types/index.ts +887 -0
  81. package/src/utils/index.ts +200 -0
  82. package/tsconfig.json +22 -0
  83. package/tsup.config.ts +25 -0
@@ -0,0 +1,1360 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ function getConfig() {
6
+ {
7
+ throw new Error("ONE SDK not initialized. Call initOneSDK() first.");
8
+ }
9
+ }
10
+
11
+ // src/services/engine.ts
12
+ var OneEngineClient = class {
13
+ constructor(options) {
14
+ const config2 = getConfig();
15
+ this.baseUrl = options?.baseUrl || config2.oneEngineUrl;
16
+ this.clientId = options?.clientId || config2.oneClientId || "";
17
+ this.secretKey = options?.secretKey || config2.oneSecretKey;
18
+ }
19
+ /**
20
+ * Set access token for authenticated requests
21
+ */
22
+ setAccessToken(token) {
23
+ this.accessToken = token;
24
+ }
25
+ /**
26
+ * Clear access token
27
+ */
28
+ clearAccessToken() {
29
+ this.accessToken = void 0;
30
+ }
31
+ getHeaders(includeSecret = false) {
32
+ const headers = {
33
+ "Content-Type": "application/json",
34
+ "x-client-id": this.clientId
35
+ };
36
+ if (this.accessToken) {
37
+ headers["Authorization"] = `Bearer ${this.accessToken}`;
38
+ }
39
+ if (includeSecret && this.secretKey) {
40
+ headers["x-secret-key"] = this.secretKey;
41
+ }
42
+ return headers;
43
+ }
44
+ async request(endpoint, options = {}, includeSecret = false) {
45
+ try {
46
+ const response = await fetch(`${this.baseUrl}${endpoint}`, {
47
+ ...options,
48
+ headers: {
49
+ ...this.getHeaders(includeSecret),
50
+ ...options.headers
51
+ }
52
+ });
53
+ const data = await response.json();
54
+ if (!response.ok) {
55
+ return {
56
+ success: false,
57
+ error: {
58
+ code: data.error?.code || `HTTP_${response.status}`,
59
+ message: data.error?.message || "Request failed"
60
+ }
61
+ };
62
+ }
63
+ return {
64
+ success: true,
65
+ data: data.data || data
66
+ };
67
+ } catch (error) {
68
+ return {
69
+ success: false,
70
+ error: {
71
+ code: "NETWORK_ERROR",
72
+ message: error instanceof Error ? error.message : "Network request failed"
73
+ }
74
+ };
75
+ }
76
+ }
77
+ // ===============================
78
+ // AUTH ENDPOINTS
79
+ // ===============================
80
+ /**
81
+ * Send OTP to email for authentication
82
+ */
83
+ async sendEmailOtp(email) {
84
+ return this.request("/api/v1/auth/otp", {
85
+ method: "POST",
86
+ body: JSON.stringify({ email })
87
+ });
88
+ }
89
+ /**
90
+ * Verify OTP and get access token
91
+ */
92
+ async verifyEmailOtp(email, otp) {
93
+ return this.request("/api/v1/auth/otp/verify", {
94
+ method: "POST",
95
+ body: JSON.stringify({ email, otp })
96
+ });
97
+ }
98
+ /**
99
+ * Authenticate with wallet signature
100
+ */
101
+ async authWithWallet(walletAddress, signature, message) {
102
+ return this.request("/api/v1/auth/wallet", {
103
+ method: "POST",
104
+ body: JSON.stringify({ walletAddress, signature, message })
105
+ });
106
+ }
107
+ /**
108
+ * Refresh access token
109
+ */
110
+ async refreshToken(refreshToken) {
111
+ return this.request("/api/v1/auth/refresh", {
112
+ method: "POST",
113
+ body: JSON.stringify({ refreshToken })
114
+ });
115
+ }
116
+ /**
117
+ * Get current user
118
+ */
119
+ async getCurrentUser() {
120
+ return this.request("/api/v1/auth/me", { method: "GET" });
121
+ }
122
+ /**
123
+ * Sign out
124
+ */
125
+ async signOut() {
126
+ return this.request("/api/v1/auth/logout", { method: "POST" });
127
+ }
128
+ // ===============================
129
+ // WALLET/ASSETS ENDPOINTS
130
+ // ===============================
131
+ /**
132
+ * Get wallet balance across all chains
133
+ */
134
+ async getWalletBalance(walletAddress, chains) {
135
+ const params = new URLSearchParams({ address: walletAddress });
136
+ if (chains?.length && chains.length > 0) {
137
+ params.set("chainId", chains[0].toString());
138
+ }
139
+ return this.request(`/api/v1/assets?${params}`, { method: "GET" });
140
+ }
141
+ /**
142
+ * Get portfolio summary
143
+ */
144
+ async getPortfolioSummary(walletAddress) {
145
+ const params = new URLSearchParams({ address: walletAddress });
146
+ return this.request(`/api/v1/assets/portfolio?${params}`, { method: "GET" });
147
+ }
148
+ /**
149
+ * Get user's wallets
150
+ */
151
+ async getUserWallets(chainId) {
152
+ const params = chainId ? `?chainId=${chainId}` : "";
153
+ return this.request(`/api/v1/wallet${params}`, { method: "GET" });
154
+ }
155
+ /**
156
+ * Create a new wallet
157
+ */
158
+ async createWallet(chainId = 8453, type = "smart") {
159
+ return this.request("/api/v1/wallet", {
160
+ method: "POST",
161
+ body: JSON.stringify({ chainId, type })
162
+ });
163
+ }
164
+ /**
165
+ * Get wallet transactions (placeholder - needs endpoint)
166
+ */
167
+ async getWalletTransactions(walletAddress, options) {
168
+ const params = new URLSearchParams({ address: walletAddress });
169
+ if (options?.limit) params.set("limit", options.limit.toString());
170
+ if (options?.offset) params.set("offset", options.offset.toString());
171
+ if (options?.chainId) params.set("chainId", options.chainId.toString());
172
+ return this.request(`/api/v1/assets/transactions?${params}`, { method: "GET" });
173
+ }
174
+ /**
175
+ * Send native token or ERC20
176
+ */
177
+ async sendTransaction(request) {
178
+ return this.request("/api/v1/wallet/send", {
179
+ method: "POST",
180
+ body: JSON.stringify(request)
181
+ });
182
+ }
183
+ /**
184
+ * Get transaction status
185
+ */
186
+ async getTransactionStatus(txId) {
187
+ return this.request(`/api/v1/wallet/transaction/${txId}`, { method: "GET" });
188
+ }
189
+ // ===============================
190
+ // ONRAMP ENDPOINTS (Fiat-to-Crypto)
191
+ // ===============================
192
+ /**
193
+ * Get onramp quote
194
+ */
195
+ async getOnrampQuote(fiatCurrency, fiatAmount, cryptoCurrency, paymentMethod) {
196
+ const params = new URLSearchParams({
197
+ fiatCurrency,
198
+ fiatAmount: fiatAmount.toString(),
199
+ cryptoCurrency
200
+ });
201
+ if (paymentMethod) params.set("paymentMethod", paymentMethod);
202
+ return this.request(`/api/v1/fiat/onramp/quote?${params}`, { method: "GET" });
203
+ }
204
+ /**
205
+ * Create onramp session (returns widget URL)
206
+ */
207
+ async createOnrampSession(request) {
208
+ return this.request("/api/v1/fiat/onramp", {
209
+ method: "POST",
210
+ body: JSON.stringify({
211
+ fiatCurrency: request.fiatCurrency || "USD",
212
+ fiatAmount: request.fiatAmount || 100,
213
+ cryptoCurrency: request.cryptoCurrency || "ETH",
214
+ walletAddress: request.walletAddress,
215
+ chainId: 8453
216
+ // Default to Base
217
+ })
218
+ });
219
+ }
220
+ /**
221
+ * Get onramp session status
222
+ */
223
+ async getOnrampStatus(sessionId) {
224
+ return this.request(`/api/v1/fiat/onramp/${sessionId}`, { method: "GET" });
225
+ }
226
+ /**
227
+ * Get supported currencies (fiat + crypto)
228
+ */
229
+ async getSupportedCurrencies() {
230
+ return this.request("/api/v1/fiat/onramp", { method: "GET" });
231
+ }
232
+ /**
233
+ * Get supported fiat currencies
234
+ */
235
+ async getSupportedFiatCurrencies() {
236
+ const result = await this.getSupportedCurrencies();
237
+ if (result.success && result.data) {
238
+ return { success: true, data: result.data.fiatCurrencies };
239
+ }
240
+ return { success: false, error: result.error };
241
+ }
242
+ /**
243
+ * Get supported payment methods
244
+ */
245
+ async getSupportedPaymentMethods(country) {
246
+ return { success: true, data: ["card", "bank_transfer", "apple_pay", "google_pay"] };
247
+ }
248
+ // ===============================
249
+ // SWAP ENDPOINTS
250
+ // ===============================
251
+ /**
252
+ * Get swap quote
253
+ */
254
+ async getSwapQuote(request) {
255
+ return this.request("/api/v1/swap/quote", {
256
+ method: "POST",
257
+ body: JSON.stringify(request)
258
+ });
259
+ }
260
+ /**
261
+ * Execute swap
262
+ */
263
+ async executeSwap(request) {
264
+ return this.request("/api/v1/swap/execute", {
265
+ method: "POST",
266
+ body: JSON.stringify(request)
267
+ });
268
+ }
269
+ /**
270
+ * Get swap status
271
+ */
272
+ async getSwapStatus(swapId) {
273
+ return this.request(`/api/v1/swap/${swapId}`, { method: "GET" });
274
+ }
275
+ /**
276
+ * Get supported tokens for swap
277
+ */
278
+ async getSupportedSwapTokens(chainId) {
279
+ const params = chainId ? `?chainId=${chainId}` : "";
280
+ return this.request(`/api/v1/swap/tokens${params}`, { method: "GET" });
281
+ }
282
+ /**
283
+ * Get supported chains for swap
284
+ */
285
+ async getSupportedSwapChains() {
286
+ return this.request("/api/v1/swap/chains", { method: "GET" });
287
+ }
288
+ // ===============================
289
+ // AI TRADING/QUANT ENDPOINTS
290
+ // ===============================
291
+ /**
292
+ * Get available AI trading strategies
293
+ */
294
+ async getStrategies() {
295
+ return this.request("/api/v1/quant/strategies", { method: "GET" });
296
+ }
297
+ /**
298
+ * Get strategy details
299
+ */
300
+ async getStrategy(strategyId) {
301
+ return this.request(`/api/v1/quant/strategies/${strategyId}`, { method: "GET" });
302
+ }
303
+ /**
304
+ * Get user's positions
305
+ */
306
+ async getPositions() {
307
+ return this.request("/api/v1/quant/positions", { method: "GET" });
308
+ }
309
+ /**
310
+ * Create investment order
311
+ */
312
+ async createOrder(strategyId, amount, currency) {
313
+ return this.request("/api/v1/trading/orders", {
314
+ method: "POST",
315
+ body: JSON.stringify({ strategyId, amount, currency })
316
+ });
317
+ }
318
+ /**
319
+ * Get user's orders
320
+ */
321
+ async getUserOrders() {
322
+ return this.request("/api/v1/trading/orders", { method: "GET" });
323
+ }
324
+ /**
325
+ * Get user's portfolio stats from positions
326
+ */
327
+ async getPortfolioStats() {
328
+ const positionsResult = await this.getPositions();
329
+ if (positionsResult.success && positionsResult.data) {
330
+ const positions = positionsResult.data;
331
+ const totalInvested = positions.reduce((sum, p) => sum + (p.investedAmount || 0), 0);
332
+ const totalValue = positions.reduce((sum, p) => sum + (p.currentValue || 0), 0);
333
+ const totalPnl = totalValue - totalInvested;
334
+ const totalPnlPercent = totalInvested > 0 ? totalPnl / totalInvested * 100 : 0;
335
+ return {
336
+ success: true,
337
+ data: {
338
+ totalInvested,
339
+ totalValue,
340
+ totalPnl,
341
+ totalPnlPercent,
342
+ activePositions: positions.filter((p) => p.status === "active").length
343
+ }
344
+ };
345
+ }
346
+ return {
347
+ success: true,
348
+ data: { totalInvested: 0, totalValue: 0, totalPnl: 0, totalPnlPercent: 0, activePositions: 0 }
349
+ };
350
+ }
351
+ // ===============================
352
+ // MARKET/PRICE ENDPOINTS
353
+ // ===============================
354
+ /**
355
+ * Get token prices
356
+ */
357
+ async getTokenPrices(symbols) {
358
+ const bybitSymbols = symbols.map((s) => {
359
+ const upper = s.toUpperCase();
360
+ if (upper.endsWith("USDT")) return upper;
361
+ return `${upper}USDT`;
362
+ });
363
+ const result = await this.request(
364
+ `/api/v1/trading/market?symbols=${bybitSymbols.join(",")}`,
365
+ { method: "GET" }
366
+ );
367
+ if (result.success && result.data?.markets) {
368
+ const prices = {};
369
+ for (const market of result.data.markets) {
370
+ const symbol = market.symbol?.replace("USDT", "") || "";
371
+ prices[symbol] = {
372
+ price: parseFloat(market.lastPrice) || 0,
373
+ change24h: parseFloat(market.price24hPcnt) * 100 || 0,
374
+ marketCap: void 0
375
+ // Bybit doesn't provide this
376
+ };
377
+ }
378
+ return { success: true, data: prices };
379
+ }
380
+ return { success: false, error: result.error };
381
+ }
382
+ /**
383
+ * Get market data overview
384
+ */
385
+ async getMarketData() {
386
+ const result = await this.request("/api/v1/trading/market", { method: "GET" });
387
+ if (result.success && result.data?.markets) {
388
+ return {
389
+ success: true,
390
+ data: {
391
+ totalMarketCap: 0,
392
+ // Would need separate API
393
+ totalVolume24h: result.data.markets.reduce((sum, m) => sum + (parseFloat(m.volume24h) || 0), 0),
394
+ btcDominance: 0,
395
+ // Would need separate API
396
+ markets: result.data.markets
397
+ }
398
+ };
399
+ }
400
+ return { success: false, error: result.error };
401
+ }
402
+ // ===============================
403
+ // NFT ENDPOINTS
404
+ // ===============================
405
+ /**
406
+ * Get user's NFTs
407
+ */
408
+ async getUserNFTs(walletAddress, options) {
409
+ const params = new URLSearchParams({ address: walletAddress });
410
+ if (options?.chainId) params.set("chainId", options.chainId.toString());
411
+ if (options?.limit) params.set("limit", options.limit.toString());
412
+ if (options?.offset) params.set("offset", options.offset.toString());
413
+ return this.request(`/api/v1/assets/nfts?${params}`, { method: "GET" });
414
+ }
415
+ /**
416
+ * Get NFT details
417
+ */
418
+ async getNFTDetails(contractAddress, tokenId, chainId) {
419
+ return this.request(`/api/v1/assets/nfts/${contractAddress}/${tokenId}?chainId=${chainId}`, { method: "GET" });
420
+ }
421
+ /**
422
+ * Get NFT collection
423
+ */
424
+ async getNFTCollection(contractAddress, chainId) {
425
+ return this.request(`/api/v1/assets/nfts/collection/${contractAddress}?chainId=${chainId}`, { method: "GET" });
426
+ }
427
+ /**
428
+ * Transfer NFT
429
+ */
430
+ async transferNFT(params) {
431
+ return this.request("/api/v1/assets/nfts/transfer", {
432
+ method: "POST",
433
+ body: JSON.stringify(params)
434
+ });
435
+ }
436
+ // ===============================
437
+ // CONTRACT ENDPOINTS
438
+ // ===============================
439
+ /**
440
+ * Get user's contracts
441
+ */
442
+ async getUserContracts(options) {
443
+ const params = new URLSearchParams();
444
+ if (options?.chainId) params.set("chainId", options.chainId.toString());
445
+ if (options?.limit) params.set("limit", options.limit.toString());
446
+ if (options?.offset) params.set("offset", options.offset.toString());
447
+ return this.request(`/api/v1/contracts?${params}`, { method: "GET" });
448
+ }
449
+ /**
450
+ * Get contract details
451
+ */
452
+ async getContractDetails(address, chainId) {
453
+ return this.request(`/api/v1/contracts/${address}?chainId=${chainId}`, { method: "GET" });
454
+ }
455
+ /**
456
+ * Read contract (call view function)
457
+ */
458
+ async readContract(params) {
459
+ return this.request("/api/v1/contracts/read", {
460
+ method: "POST",
461
+ body: JSON.stringify(params)
462
+ });
463
+ }
464
+ /**
465
+ * Write to contract (execute transaction)
466
+ */
467
+ async writeContract(params) {
468
+ return this.request("/api/v1/contracts/write", {
469
+ method: "POST",
470
+ body: JSON.stringify(params)
471
+ });
472
+ }
473
+ /**
474
+ * Deploy contract
475
+ */
476
+ async deployContract(params) {
477
+ return this.request("/api/v1/contracts/deploy", {
478
+ method: "POST",
479
+ body: JSON.stringify(params)
480
+ });
481
+ }
482
+ // ===============================
483
+ // OFFRAMP ENDPOINTS (Crypto-to-Fiat)
484
+ // ===============================
485
+ /**
486
+ * Get offramp quote
487
+ */
488
+ async getOfframpQuote(cryptoCurrency, cryptoAmount, fiatCurrency, payoutMethod) {
489
+ const params = new URLSearchParams({
490
+ cryptoCurrency,
491
+ cryptoAmount: cryptoAmount.toString(),
492
+ fiatCurrency
493
+ });
494
+ if (payoutMethod) params.set("payoutMethod", payoutMethod);
495
+ return this.request(`/api/v1/fiat/offramp/quote?${params}`, { method: "GET" });
496
+ }
497
+ /**
498
+ * Create offramp transaction
499
+ */
500
+ async createOfframpTransaction(request) {
501
+ return this.request("/api/v1/fiat/offramp", {
502
+ method: "POST",
503
+ body: JSON.stringify(request)
504
+ });
505
+ }
506
+ /**
507
+ * Get offramp transaction status
508
+ */
509
+ async getOfframpStatus(transactionId) {
510
+ return this.request(`/api/v1/fiat/offramp/${transactionId}`, { method: "GET" });
511
+ }
512
+ /**
513
+ * Get supported payout methods
514
+ */
515
+ async getSupportedPayoutMethods(country) {
516
+ const params = country ? `?country=${country}` : "";
517
+ return this.request(`/api/v1/fiat/offramp/methods${params}`, { method: "GET" });
518
+ }
519
+ // ===============================
520
+ // BILL PAYMENT ENDPOINTS
521
+ // ===============================
522
+ /**
523
+ * Get bill providers
524
+ */
525
+ async getBillProviders(country, category) {
526
+ const params = new URLSearchParams();
527
+ if (country) params.set("country", country);
528
+ if (category) params.set("category", category);
529
+ return this.request(`/api/v1/bills/providers?${params}`, { method: "GET" });
530
+ }
531
+ /**
532
+ * Get bill details/validate account
533
+ */
534
+ async validateBillAccount(providerId, accountNumber) {
535
+ return this.request("/api/v1/bills/validate", {
536
+ method: "POST",
537
+ body: JSON.stringify({ providerId, accountNumber })
538
+ });
539
+ }
540
+ /**
541
+ * Pay bill
542
+ */
543
+ async payBill(params) {
544
+ return this.request("/api/v1/bills/pay", {
545
+ method: "POST",
546
+ body: JSON.stringify(params)
547
+ });
548
+ }
549
+ /**
550
+ * Get bill payment history
551
+ */
552
+ async getBillHistory(options) {
553
+ const params = new URLSearchParams();
554
+ if (options?.limit) params.set("limit", options.limit.toString());
555
+ if (options?.offset) params.set("offset", options.offset.toString());
556
+ return this.request(`/api/v1/bills/history?${params}`, { method: "GET" });
557
+ }
558
+ // ===============================
559
+ // STAKING ENDPOINTS
560
+ // ===============================
561
+ /**
562
+ * Get staking pools
563
+ */
564
+ async getStakingPools(chainId) {
565
+ const params = chainId ? `?chainId=${chainId}` : "";
566
+ return this.request(`/api/v1/staking/pools${params}`, { method: "GET" });
567
+ }
568
+ /**
569
+ * Get user's staking positions
570
+ */
571
+ async getStakingPositions() {
572
+ return this.request("/api/v1/staking/positions", { method: "GET" });
573
+ }
574
+ /**
575
+ * Stake tokens
576
+ */
577
+ async stake(params) {
578
+ return this.request("/api/v1/staking/stake", {
579
+ method: "POST",
580
+ body: JSON.stringify(params)
581
+ });
582
+ }
583
+ /**
584
+ * Unstake tokens
585
+ */
586
+ async unstake(params) {
587
+ return this.request("/api/v1/staking/unstake", {
588
+ method: "POST",
589
+ body: JSON.stringify(params)
590
+ });
591
+ }
592
+ /**
593
+ * Claim staking rewards
594
+ */
595
+ async claimStakingRewards(positionId) {
596
+ return this.request("/api/v1/staking/claim", {
597
+ method: "POST",
598
+ body: JSON.stringify({ positionId })
599
+ });
600
+ }
601
+ // ===============================
602
+ // USER PROFILE ENDPOINTS
603
+ // ===============================
604
+ /**
605
+ * Get user profile
606
+ */
607
+ async getUserProfile() {
608
+ return this.request("/api/v1/user/profile", { method: "GET" });
609
+ }
610
+ /**
611
+ * Update user profile
612
+ */
613
+ async updateUserProfile(updates) {
614
+ return this.request("/api/v1/user/profile", {
615
+ method: "PATCH",
616
+ body: JSON.stringify(updates)
617
+ });
618
+ }
619
+ /**
620
+ * Get user settings
621
+ */
622
+ async getUserSettings() {
623
+ return this.request("/api/v1/user/settings", { method: "GET" });
624
+ }
625
+ /**
626
+ * Update user settings
627
+ */
628
+ async updateUserSettings(updates) {
629
+ return this.request("/api/v1/user/settings", {
630
+ method: "PATCH",
631
+ body: JSON.stringify(updates)
632
+ });
633
+ }
634
+ // ===============================
635
+ // NOTIFICATION ENDPOINTS
636
+ // ===============================
637
+ /**
638
+ * Get notifications
639
+ */
640
+ async getNotifications(options) {
641
+ const params = new URLSearchParams();
642
+ if (options?.unreadOnly) params.set("unreadOnly", "true");
643
+ if (options?.limit) params.set("limit", options.limit.toString());
644
+ if (options?.offset) params.set("offset", options.offset.toString());
645
+ return this.request(`/api/v1/notifications?${params}`, { method: "GET" });
646
+ }
647
+ /**
648
+ * Mark notification as read
649
+ */
650
+ async markNotificationRead(notificationId) {
651
+ return this.request(`/api/v1/notifications/${notificationId}/read`, { method: "POST" });
652
+ }
653
+ /**
654
+ * Mark all notifications as read
655
+ */
656
+ async markAllNotificationsRead() {
657
+ return this.request("/api/v1/notifications/read-all", { method: "POST" });
658
+ }
659
+ // ===============================
660
+ // REFERRAL ENDPOINTS
661
+ // ===============================
662
+ /**
663
+ * Get referral info
664
+ */
665
+ async getReferralInfo() {
666
+ return this.request("/api/v1/referral", { method: "GET" });
667
+ }
668
+ /**
669
+ * Get referred users
670
+ */
671
+ async getReferrals() {
672
+ return this.request("/api/v1/referral/list", { method: "GET" });
673
+ }
674
+ /**
675
+ * Apply referral code
676
+ */
677
+ async applyReferralCode(code) {
678
+ return this.request("/api/v1/referral/apply", {
679
+ method: "POST",
680
+ body: JSON.stringify({ code })
681
+ });
682
+ }
683
+ /**
684
+ * Claim referral rewards
685
+ */
686
+ async claimReferralRewards() {
687
+ return this.request("/api/v1/referral/claim", { method: "POST" });
688
+ }
689
+ // ===============================
690
+ // KYC ENDPOINTS
691
+ // ===============================
692
+ /**
693
+ * Get KYC status
694
+ */
695
+ async getKycStatus() {
696
+ return this.request("/api/v1/kyc/status", { method: "GET" });
697
+ }
698
+ /**
699
+ * Start KYC verification
700
+ */
701
+ async startKycVerification(level) {
702
+ return this.request("/api/v1/kyc/start", {
703
+ method: "POST",
704
+ body: JSON.stringify({ level })
705
+ });
706
+ }
707
+ /**
708
+ * Submit KYC documents
709
+ */
710
+ async submitKycDocuments(params) {
711
+ return this.request("/api/v1/kyc/submit", {
712
+ method: "POST",
713
+ body: JSON.stringify(params)
714
+ });
715
+ }
716
+ // ===============================
717
+ // BRIDGE ENDPOINTS
718
+ // ===============================
719
+ /**
720
+ * Get bridge quote
721
+ */
722
+ async getBridgeQuote(params) {
723
+ return this.request("/api/v1/bridge/quote", {
724
+ method: "POST",
725
+ body: JSON.stringify(params)
726
+ });
727
+ }
728
+ /**
729
+ * Execute bridge transaction
730
+ */
731
+ async executeBridge(params) {
732
+ return this.request("/api/v1/bridge/execute", {
733
+ method: "POST",
734
+ body: JSON.stringify(params)
735
+ });
736
+ }
737
+ /**
738
+ * Get bridge transaction status
739
+ */
740
+ async getBridgeStatus(bridgeId) {
741
+ return this.request(`/api/v1/bridge/${bridgeId}`, { method: "GET" });
742
+ }
743
+ /**
744
+ * Get supported bridge routes
745
+ */
746
+ async getSupportedBridgeRoutes() {
747
+ return this.request("/api/v1/bridge/routes", { method: "GET" });
748
+ }
749
+ // ===============================
750
+ // GAS ENDPOINTS
751
+ // ===============================
752
+ /**
753
+ * Get gas estimate for transaction
754
+ */
755
+ async getGasEstimate(params) {
756
+ return this.request("/api/v1/gas/estimate", {
757
+ method: "POST",
758
+ body: JSON.stringify(params)
759
+ });
760
+ }
761
+ /**
762
+ * Get current gas prices for chain
763
+ */
764
+ async getGasPrice(chainId) {
765
+ return this.request(`/api/v1/gas/price?chainId=${chainId}`, { method: "GET" });
766
+ }
767
+ // ===============================
768
+ // WALLET IMPORT/EXPORT ENDPOINTS
769
+ // ===============================
770
+ /**
771
+ * Import wallet from private key or mnemonic
772
+ */
773
+ async importWallet(request) {
774
+ return this.request("/api/v1/wallet/import", {
775
+ method: "POST",
776
+ body: JSON.stringify(request)
777
+ }, true);
778
+ }
779
+ /**
780
+ * Export wallet (get encrypted private key)
781
+ * Requires additional authentication
782
+ */
783
+ async exportWallet(walletId, pin) {
784
+ return this.request("/api/v1/wallet/export", {
785
+ method: "POST",
786
+ body: JSON.stringify({ walletId, pin })
787
+ }, true);
788
+ }
789
+ /**
790
+ * Generate new mnemonic phrase
791
+ */
792
+ async generateMnemonic() {
793
+ return this.request("/api/v1/wallet/generate-mnemonic", { method: "POST" }, true);
794
+ }
795
+ /**
796
+ * Validate mnemonic phrase
797
+ */
798
+ async validateMnemonic(mnemonic) {
799
+ return this.request("/api/v1/wallet/validate-mnemonic", {
800
+ method: "POST",
801
+ body: JSON.stringify({ mnemonic })
802
+ });
803
+ }
804
+ // ===============================
805
+ // PORTFOLIO ANALYTICS ENDPOINTS
806
+ // ===============================
807
+ /**
808
+ * Get portfolio analytics with historical data
809
+ */
810
+ async getPortfolioAnalytics(walletAddress, period = "30d") {
811
+ const params = new URLSearchParams({ address: walletAddress, period });
812
+ return this.request(`/api/v1/analytics/portfolio?${params}`, { method: "GET" });
813
+ }
814
+ /**
815
+ * Get transaction analytics
816
+ */
817
+ async getTransactionAnalytics(walletAddress, period = "30d") {
818
+ const params = new URLSearchParams({ address: walletAddress, period });
819
+ return this.request(`/api/v1/analytics/transactions?${params}`, { method: "GET" });
820
+ }
821
+ // ===============================
822
+ // ADVANCED TRADING ENDPOINTS
823
+ // ===============================
824
+ /**
825
+ * Create limit order
826
+ */
827
+ async createLimitOrder(params) {
828
+ return this.request("/api/v1/trading/limit-orders", {
829
+ method: "POST",
830
+ body: JSON.stringify(params)
831
+ });
832
+ }
833
+ /**
834
+ * Get user's limit orders
835
+ */
836
+ async getLimitOrders(status) {
837
+ const params = status ? `?status=${status}` : "";
838
+ return this.request(`/api/v1/trading/limit-orders${params}`, { method: "GET" });
839
+ }
840
+ /**
841
+ * Cancel limit order
842
+ */
843
+ async cancelLimitOrder(orderId) {
844
+ return this.request(`/api/v1/trading/limit-orders/${orderId}`, { method: "DELETE" });
845
+ }
846
+ /**
847
+ * Set price alert
848
+ */
849
+ async setPriceAlert(params) {
850
+ return this.request("/api/v1/trading/alerts", {
851
+ method: "POST",
852
+ body: JSON.stringify(params)
853
+ });
854
+ }
855
+ /**
856
+ * Get price alerts
857
+ */
858
+ async getPriceAlerts() {
859
+ return this.request("/api/v1/trading/alerts", { method: "GET" });
860
+ }
861
+ /**
862
+ * Delete price alert
863
+ */
864
+ async deletePriceAlert(alertId) {
865
+ return this.request(`/api/v1/trading/alerts/${alertId}`, { method: "DELETE" });
866
+ }
867
+ // ===============================
868
+ // SESSION MANAGEMENT
869
+ // ===============================
870
+ /**
871
+ * Get active sessions
872
+ */
873
+ async getActiveSessions() {
874
+ return this.request("/api/v1/auth/sessions", { method: "GET" });
875
+ }
876
+ /**
877
+ * Revoke session
878
+ */
879
+ async revokeSession(sessionId) {
880
+ return this.request(`/api/v1/auth/sessions/${sessionId}`, { method: "DELETE" });
881
+ }
882
+ /**
883
+ * Revoke all other sessions
884
+ */
885
+ async revokeAllOtherSessions() {
886
+ return this.request("/api/v1/auth/sessions/revoke-all", { method: "POST" });
887
+ }
888
+ // ========== Webhooks ==========
889
+ /**
890
+ * List webhooks for the project
891
+ */
892
+ async listWebhooks(options) {
893
+ const params = new URLSearchParams();
894
+ if (options?.isActive !== void 0) params.set("isActive", String(options.isActive));
895
+ const query = params.toString();
896
+ return this.request(`/api/v1/webhooks${query ? `?${query}` : ""}`, { method: "GET" });
897
+ }
898
+ /**
899
+ * Get webhook by ID
900
+ */
901
+ async getWebhook(webhookId) {
902
+ return this.request(`/api/v1/webhooks/${webhookId}`, { method: "GET" });
903
+ }
904
+ /**
905
+ * Create a webhook
906
+ */
907
+ async createWebhook(input) {
908
+ return this.request("/api/v1/webhooks", {
909
+ method: "POST",
910
+ body: JSON.stringify(input)
911
+ });
912
+ }
913
+ /**
914
+ * Update a webhook
915
+ */
916
+ async updateWebhook(webhookId, input) {
917
+ return this.request(`/api/v1/webhooks/${webhookId}`, {
918
+ method: "PATCH",
919
+ body: JSON.stringify(input)
920
+ });
921
+ }
922
+ /**
923
+ * Delete a webhook
924
+ */
925
+ async deleteWebhook(webhookId) {
926
+ return this.request(`/api/v1/webhooks/${webhookId}`, { method: "DELETE" });
927
+ }
928
+ /**
929
+ * Get webhook deliveries
930
+ */
931
+ async getWebhookDeliveries(webhookId, options) {
932
+ const params = new URLSearchParams();
933
+ if (options?.status) params.set("status", options.status);
934
+ if (options?.limit) params.set("limit", String(options.limit));
935
+ if (options?.offset) params.set("offset", String(options.offset));
936
+ const query = params.toString();
937
+ return this.request(`/api/v1/webhooks/${webhookId}/deliveries${query ? `?${query}` : ""}`, { method: "GET" });
938
+ }
939
+ /**
940
+ * Test a webhook
941
+ */
942
+ async testWebhook(webhookId) {
943
+ return this.request(`/api/v1/webhooks/${webhookId}/test`, { method: "POST" });
944
+ }
945
+ // ========== Admin (requires admin role) ==========
946
+ /**
947
+ * List all users (admin only)
948
+ */
949
+ async adminListUsers(options) {
950
+ const params = new URLSearchParams();
951
+ if (options?.page) params.set("page", String(options.page));
952
+ if (options?.limit) params.set("limit", String(options.limit));
953
+ if (options?.search) params.set("search", options.search);
954
+ if (options?.sortBy) params.set("sortBy", options.sortBy);
955
+ if (options?.sortOrder) params.set("sortOrder", options.sortOrder);
956
+ if (options?.role) params.set("role", options.role);
957
+ if (options?.kycStatus) params.set("kycStatus", options.kycStatus);
958
+ if (options?.isActive !== void 0) params.set("isActive", String(options.isActive));
959
+ const query = params.toString();
960
+ return this.request(`/api/v1/admin/users${query ? `?${query}` : ""}`, { method: "GET" });
961
+ }
962
+ /**
963
+ * Get user by ID (admin only)
964
+ */
965
+ async adminGetUser(userId) {
966
+ return this.request(`/api/v1/admin/users/${userId}`, { method: "GET" });
967
+ }
968
+ /**
969
+ * Update user (admin only)
970
+ */
971
+ async adminUpdateUser(userId, data) {
972
+ return this.request(`/api/v1/admin/users/${userId}`, {
973
+ method: "PATCH",
974
+ body: JSON.stringify(data)
975
+ });
976
+ }
977
+ /**
978
+ * List all projects (admin only)
979
+ */
980
+ async adminListProjects(options) {
981
+ const params = new URLSearchParams();
982
+ if (options?.page) params.set("page", String(options.page));
983
+ if (options?.limit) params.set("limit", String(options.limit));
984
+ if (options?.search) params.set("search", options.search);
985
+ if (options?.sortBy) params.set("sortBy", options.sortBy);
986
+ if (options?.sortOrder) params.set("sortOrder", options.sortOrder);
987
+ if (options?.isActive !== void 0) params.set("isActive", String(options.isActive));
988
+ const query = params.toString();
989
+ return this.request(`/api/v1/admin/projects${query ? `?${query}` : ""}`, { method: "GET" });
990
+ }
991
+ /**
992
+ * Get project by ID (admin only)
993
+ */
994
+ async adminGetProject(projectId) {
995
+ return this.request(`/api/v1/admin/projects/${projectId}`, { method: "GET" });
996
+ }
997
+ /**
998
+ * Update project (admin only)
999
+ */
1000
+ async adminUpdateProject(projectId, data) {
1001
+ return this.request(`/api/v1/admin/projects/${projectId}`, {
1002
+ method: "PATCH",
1003
+ body: JSON.stringify(data)
1004
+ });
1005
+ }
1006
+ /**
1007
+ * Regenerate project API key (admin only)
1008
+ */
1009
+ async adminRegenerateApiKey(projectId) {
1010
+ return this.request(`/api/v1/admin/projects/${projectId}/regenerate-key`, { method: "POST" });
1011
+ }
1012
+ /**
1013
+ * Get system statistics (admin only)
1014
+ */
1015
+ async adminGetStats(days) {
1016
+ const query = days ? `?days=${days}` : "";
1017
+ return this.request(`/api/v1/admin/stats${query}`, { method: "GET" });
1018
+ }
1019
+ /**
1020
+ * Get system logs (admin only)
1021
+ */
1022
+ async adminGetLogs(options) {
1023
+ const params = new URLSearchParams();
1024
+ if (options?.level) params.set("level", options.level);
1025
+ if (options?.service) params.set("service", options.service);
1026
+ if (options?.limit) params.set("limit", String(options.limit));
1027
+ if (options?.offset) params.set("offset", String(options.offset));
1028
+ if (options?.startDate) params.set("startDate", options.startDate);
1029
+ if (options?.endDate) params.set("endDate", options.endDate);
1030
+ const query = params.toString();
1031
+ return this.request(`/api/v1/admin/logs${query ? `?${query}` : ""}`, { method: "GET" });
1032
+ }
1033
+ /**
1034
+ * Get rate limit status (admin only)
1035
+ */
1036
+ async adminGetRateLimits(options) {
1037
+ const params = new URLSearchParams();
1038
+ if (options?.identifier) params.set("identifier", options.identifier);
1039
+ if (options?.limit) params.set("limit", String(options.limit));
1040
+ const query = params.toString();
1041
+ return this.request(`/api/v1/admin/rate-limits${query ? `?${query}` : ""}`, { method: "GET" });
1042
+ }
1043
+ /**
1044
+ * Clear rate limits for an identifier (admin only)
1045
+ */
1046
+ async adminClearRateLimits(identifier) {
1047
+ return this.request(`/api/v1/admin/rate-limits/${identifier}`, { method: "DELETE" });
1048
+ }
1049
+ // ========== AI Quant Trading ==========
1050
+ /**
1051
+ * Get all AI trading strategies
1052
+ */
1053
+ async getAIStrategies(filters) {
1054
+ const params = new URLSearchParams();
1055
+ if (filters?.category) params.set("category", filters.category);
1056
+ if (filters?.riskLevel) params.set("risk_level", String(filters.riskLevel));
1057
+ if (filters?.minTvl) params.set("min_tvl", String(filters.minTvl));
1058
+ if (filters?.isActive !== void 0) params.set("is_active", String(filters.isActive));
1059
+ const query = params.toString();
1060
+ return this.request(`/api/v1/ai-quant/strategies${query ? `?${query}` : ""}`, { method: "GET" });
1061
+ }
1062
+ /**
1063
+ * Get AI strategy details
1064
+ */
1065
+ async getAIStrategy(strategyId, include) {
1066
+ const params = new URLSearchParams();
1067
+ if (include?.length) params.set("include", include.join(","));
1068
+ const query = params.toString();
1069
+ return this.request(`/api/v1/ai-quant/strategies/${strategyId}${query ? `?${query}` : ""}`, { method: "GET" });
1070
+ }
1071
+ /**
1072
+ * Get strategy performance history
1073
+ */
1074
+ async getAIStrategyPerformance(strategyId, days = 30) {
1075
+ return this.request(`/api/v1/ai-quant/strategies/${strategyId}?include=performance&days=${days}`, { method: "GET" });
1076
+ }
1077
+ /**
1078
+ * Get real-time market data for strategy pairs
1079
+ */
1080
+ async getAIStrategyMarketData(strategyId) {
1081
+ return this.request(`/api/v1/ai-quant/strategies/${strategyId}?include=market`, { method: "GET" });
1082
+ }
1083
+ /**
1084
+ * Create AI trading order
1085
+ */
1086
+ async createAIOrder(request) {
1087
+ return this.request("/api/v1/ai-quant/orders", {
1088
+ method: "POST",
1089
+ body: JSON.stringify(request)
1090
+ });
1091
+ }
1092
+ /**
1093
+ * Get user's AI orders
1094
+ */
1095
+ async getAIOrders(filters) {
1096
+ const params = new URLSearchParams();
1097
+ if (filters?.strategyId) params.set("strategy_id", filters.strategyId);
1098
+ if (filters?.status) params.set("status", filters.status);
1099
+ const query = params.toString();
1100
+ return this.request(`/api/v1/ai-quant/orders${query ? `?${query}` : ""}`, { method: "GET" });
1101
+ }
1102
+ /**
1103
+ * Get AI order details
1104
+ */
1105
+ async getAIOrder(orderId) {
1106
+ return this.request(`/api/v1/ai-quant/orders/${orderId}`, { method: "GET" });
1107
+ }
1108
+ /**
1109
+ * Pause AI order
1110
+ */
1111
+ async pauseAIOrder(orderId) {
1112
+ return this.request(`/api/v1/ai-quant/orders/${orderId}/pause`, { method: "POST" });
1113
+ }
1114
+ /**
1115
+ * Resume AI order
1116
+ */
1117
+ async resumeAIOrder(orderId) {
1118
+ return this.request(`/api/v1/ai-quant/orders/${orderId}/resume`, { method: "POST" });
1119
+ }
1120
+ /**
1121
+ * Request redemption for AI order
1122
+ */
1123
+ async redeemAIOrder(orderId) {
1124
+ return this.request(`/api/v1/ai-quant/orders/${orderId}/redeem`, { method: "POST" });
1125
+ }
1126
+ /**
1127
+ * Get AI portfolio summary
1128
+ */
1129
+ async getAIPortfolio(include) {
1130
+ const params = new URLSearchParams();
1131
+ if (include?.length) params.set("include", include.join(","));
1132
+ const query = params.toString();
1133
+ return this.request(`/api/v1/ai-quant/portfolio${query ? `?${query}` : ""}`, { method: "GET" });
1134
+ }
1135
+ /**
1136
+ * Get user's trade allocations
1137
+ */
1138
+ async getAITradeAllocations(limit = 50) {
1139
+ return this.request(`/api/v1/ai-quant/portfolio?include=allocations&limit=${limit}`, { method: "GET" });
1140
+ }
1141
+ /**
1142
+ * Get trade history for a strategy
1143
+ */
1144
+ async getAITradeHistory(strategyId, limit = 50) {
1145
+ return this.request(`/api/v1/ai-quant/strategies/${strategyId}?include=trades&limit=${limit}`, { method: "GET" });
1146
+ }
1147
+ /**
1148
+ * Execute AI signals for a strategy (admin only)
1149
+ */
1150
+ async executeAISignals(strategyId) {
1151
+ return this.request("/api/v1/ai-quant/execute", {
1152
+ method: "POST",
1153
+ body: JSON.stringify({ strategyId })
1154
+ });
1155
+ }
1156
+ // ========== Free Price APIs (No API Key Required) ==========
1157
+ /**
1158
+ * Get cryptocurrency prices (FREE - uses CoinGecko/Binance/CoinCap)
1159
+ */
1160
+ async getCryptoPrices(symbols) {
1161
+ return this.request(`/api/v1/prices?symbols=${symbols.join(",")}`, { method: "GET" });
1162
+ }
1163
+ /**
1164
+ * Get single cryptocurrency price (FREE)
1165
+ */
1166
+ async getCryptoPrice(symbol) {
1167
+ return this.request(`/api/v1/prices/${symbol}`, { method: "GET" });
1168
+ }
1169
+ /**
1170
+ * Get OHLCV candles for charting (FREE - from Binance)
1171
+ */
1172
+ async getCryptoCandles(symbol, interval = "1h", limit = 100) {
1173
+ return this.request(`/api/v1/prices/${symbol}?candles=true&interval=${interval}&limit=${limit}`, { method: "GET" });
1174
+ }
1175
+ /**
1176
+ * Get top cryptocurrencies by market cap (FREE)
1177
+ */
1178
+ async getTopCryptos(limit = 20) {
1179
+ return this.request(`/api/v1/prices?type=top&limit=${limit}`, { method: "GET" });
1180
+ }
1181
+ /**
1182
+ * Get crypto market overview (FREE)
1183
+ */
1184
+ async getCryptoMarketOverview() {
1185
+ return this.request("/api/v1/prices?type=overview", { method: "GET" });
1186
+ }
1187
+ };
1188
+ function createOneEngineClient(options) {
1189
+ return new OneEngineClient(options);
1190
+ }
1191
+
1192
+ // src/hooks/useWalletBalance.ts
1193
+ function useWalletBalance(walletAddress, options = {}) {
1194
+ const {
1195
+ chains,
1196
+ autoRefresh = false,
1197
+ refreshInterval = 6e4,
1198
+ // 1 minute
1199
+ engineUrl,
1200
+ clientId
1201
+ } = options;
1202
+ const [balance, setBalance] = react.useState(null);
1203
+ const [isLoading, setIsLoading] = react.useState(false);
1204
+ const [error, setError] = react.useState(null);
1205
+ const engineRef = react.useRef(createOneEngineClient({
1206
+ baseUrl: engineUrl,
1207
+ clientId
1208
+ }));
1209
+ const fetchBalance = react.useCallback(async () => {
1210
+ if (!walletAddress) {
1211
+ setBalance(null);
1212
+ return;
1213
+ }
1214
+ setIsLoading(true);
1215
+ setError(null);
1216
+ try {
1217
+ const result = await engineRef.current.getWalletBalance(walletAddress, chains);
1218
+ if (result.success && result.data) {
1219
+ setBalance(result.data);
1220
+ } else {
1221
+ setError(result.error?.message || "Failed to fetch balance");
1222
+ }
1223
+ } catch (err) {
1224
+ setError(err instanceof Error ? err.message : "Failed to fetch balance");
1225
+ } finally {
1226
+ setIsLoading(false);
1227
+ }
1228
+ }, [walletAddress, chains]);
1229
+ react.useEffect(() => {
1230
+ fetchBalance();
1231
+ }, [fetchBalance]);
1232
+ react.useEffect(() => {
1233
+ if (!autoRefresh || !walletAddress) return;
1234
+ const interval = setInterval(fetchBalance, refreshInterval);
1235
+ return () => clearInterval(interval);
1236
+ }, [autoRefresh, refreshInterval, fetchBalance, walletAddress]);
1237
+ return {
1238
+ balance,
1239
+ tokens: balance?.tokens || [],
1240
+ totalUsd: balance?.totalUsd || 0,
1241
+ change24h: balance?.change24h || 0,
1242
+ changePercent24h: balance?.changePercent24h || 0,
1243
+ isLoading,
1244
+ error,
1245
+ refetch: fetchBalance
1246
+ };
1247
+ }
1248
+ function useTokenPrice(symbol, options = {}) {
1249
+ const { autoRefresh = false, refreshInterval = 3e4, engineUrl, clientId } = options;
1250
+ const [price, setPrice] = react.useState(null);
1251
+ const [isLoading, setIsLoading] = react.useState(false);
1252
+ const [error, setError] = react.useState(null);
1253
+ const engineRef = react.useRef(createOneEngineClient({
1254
+ baseUrl: engineUrl,
1255
+ clientId
1256
+ }));
1257
+ const fetchPrice = react.useCallback(async () => {
1258
+ if (!symbol) return;
1259
+ setIsLoading(true);
1260
+ setError(null);
1261
+ try {
1262
+ const result = await engineRef.current.getTokenPrices([symbol]);
1263
+ if (result.success && result.data && result.data[symbol]) {
1264
+ const priceData = result.data[symbol];
1265
+ setPrice({
1266
+ symbol,
1267
+ price: priceData.price,
1268
+ change24h: priceData.change24h,
1269
+ changePercent24h: priceData.change24h,
1270
+ // Same as change24h for percentage
1271
+ marketCap: priceData.marketCap,
1272
+ volume24h: 0,
1273
+ // Not provided by engine
1274
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1275
+ });
1276
+ } else {
1277
+ setError(result.error?.message || "Failed to fetch price");
1278
+ }
1279
+ } catch (err) {
1280
+ setError(err instanceof Error ? err.message : "Failed to fetch price");
1281
+ } finally {
1282
+ setIsLoading(false);
1283
+ }
1284
+ }, [symbol]);
1285
+ react.useEffect(() => {
1286
+ fetchPrice();
1287
+ }, [fetchPrice]);
1288
+ react.useEffect(() => {
1289
+ if (!autoRefresh) return;
1290
+ const interval = setInterval(fetchPrice, refreshInterval);
1291
+ return () => clearInterval(interval);
1292
+ }, [autoRefresh, refreshInterval, fetchPrice]);
1293
+ return {
1294
+ price,
1295
+ isLoading,
1296
+ error,
1297
+ refetch: fetchPrice
1298
+ };
1299
+ }
1300
+ function useTokenPrices(symbols, options = {}) {
1301
+ const { autoRefresh = false, refreshInterval = 3e4, engineUrl, clientId } = options;
1302
+ const [prices, setPrices] = react.useState({});
1303
+ const [isLoading, setIsLoading] = react.useState(false);
1304
+ const [error, setError] = react.useState(null);
1305
+ const engineRef = react.useRef(createOneEngineClient({
1306
+ baseUrl: engineUrl,
1307
+ clientId
1308
+ }));
1309
+ const fetchPrices = react.useCallback(async () => {
1310
+ if (symbols.length === 0) return;
1311
+ setIsLoading(true);
1312
+ setError(null);
1313
+ try {
1314
+ const result = await engineRef.current.getTokenPrices(symbols);
1315
+ if (result.success && result.data) {
1316
+ const priceMap = {};
1317
+ for (const sym of symbols) {
1318
+ if (result.data[sym]) {
1319
+ priceMap[sym] = {
1320
+ symbol: sym,
1321
+ price: result.data[sym].price,
1322
+ change24h: result.data[sym].change24h,
1323
+ changePercent24h: result.data[sym].change24h,
1324
+ marketCap: result.data[sym].marketCap,
1325
+ volume24h: 0,
1326
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1327
+ };
1328
+ }
1329
+ }
1330
+ setPrices(priceMap);
1331
+ } else {
1332
+ setError(result.error?.message || "Failed to fetch prices");
1333
+ }
1334
+ } catch (err) {
1335
+ setError(err instanceof Error ? err.message : "Failed to fetch prices");
1336
+ } finally {
1337
+ setIsLoading(false);
1338
+ }
1339
+ }, [symbols]);
1340
+ react.useEffect(() => {
1341
+ fetchPrices();
1342
+ }, [fetchPrices]);
1343
+ react.useEffect(() => {
1344
+ if (!autoRefresh) return;
1345
+ const interval = setInterval(fetchPrices, refreshInterval);
1346
+ return () => clearInterval(interval);
1347
+ }, [autoRefresh, refreshInterval, fetchPrices]);
1348
+ return {
1349
+ prices,
1350
+ isLoading,
1351
+ error,
1352
+ refetch: fetchPrices
1353
+ };
1354
+ }
1355
+
1356
+ exports.useTokenPrice = useTokenPrice;
1357
+ exports.useTokenPrices = useTokenPrices;
1358
+ exports.useWalletBalance = useWalletBalance;
1359
+ //# sourceMappingURL=index.js.map
1360
+ //# sourceMappingURL=index.js.map