@one_deploy/sdk 1.0.4 → 1.0.6

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