@one_deploy/sdk 1.0.2 → 1.0.4

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