@one_deploy/sdk 1.0.0

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