@one_deploy/sdk 1.0.7 → 1.2.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 (106) hide show
  1. package/README.md +339 -0
  2. package/dist/ForexPoolDataGenerator--__twRwl.d.mts +76 -0
  3. package/dist/ForexPoolDataGenerator-eUgwsU_B.d.ts +76 -0
  4. package/dist/OneForexTradeHistory-TlKxjbFF.d.ts +250 -0
  5. package/dist/OneForexTradeHistory-iDySMcw0.d.mts +250 -0
  6. package/dist/components/index.d.mts +539 -0
  7. package/dist/components/index.d.ts +539 -0
  8. package/dist/components/index.js +7295 -0
  9. package/dist/components/index.js.map +1 -0
  10. package/dist/components/index.mjs +7243 -0
  11. package/dist/components/index.mjs.map +1 -0
  12. package/dist/config/index.d.mts +1 -0
  13. package/dist/config/index.d.ts +1 -0
  14. package/dist/console-BfTMA7ah.d.mts +504 -0
  15. package/dist/console-BfTMA7ah.d.ts +504 -0
  16. package/dist/hooks/index.d.mts +323 -1
  17. package/dist/hooks/index.d.ts +323 -1
  18. package/dist/hooks/index.js +3223 -0
  19. package/dist/hooks/index.js.map +1 -1
  20. package/dist/hooks/index.mjs +3204 -1
  21. package/dist/hooks/index.mjs.map +1 -1
  22. package/dist/index.d.mts +18 -352
  23. package/dist/index.d.ts +18 -352
  24. package/dist/index.js +8646 -574
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +8449 -432
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/providers/index.d.mts +31 -31
  29. package/dist/providers/index.d.ts +31 -31
  30. package/dist/providers/index.js +140 -153
  31. package/dist/providers/index.js.map +1 -1
  32. package/dist/providers/index.mjs +100 -109
  33. package/dist/providers/index.mjs.map +1 -1
  34. package/dist/react-native.d.mts +8 -144
  35. package/dist/react-native.d.ts +8 -144
  36. package/dist/react-native.js +2640 -689
  37. package/dist/react-native.js.map +1 -1
  38. package/dist/react-native.mjs +2610 -691
  39. package/dist/react-native.mjs.map +1 -1
  40. package/dist/services/index.d.mts +85 -4
  41. package/dist/services/index.d.ts +85 -4
  42. package/dist/services/index.js +1621 -0
  43. package/dist/services/index.js.map +1 -1
  44. package/dist/services/index.mjs +1619 -1
  45. package/dist/services/index.mjs.map +1 -1
  46. package/dist/types/index.d.mts +203 -1
  47. package/dist/types/index.d.ts +203 -1
  48. package/dist/types/index.js +275 -0
  49. package/dist/types/index.js.map +1 -1
  50. package/dist/types/index.mjs +251 -0
  51. package/dist/types/index.mjs.map +1 -1
  52. package/dist/useForexTrading-BleeSor8.d.mts +80 -0
  53. package/dist/useForexTrading-ZgW_G40Q.d.ts +80 -0
  54. package/package.json +9 -2
  55. package/src/components/OneConnectButton.tsx +24 -1
  56. package/src/components/OneNFTGallery.tsx +13 -7
  57. package/src/components/OneOfframpWidget.tsx +4 -3
  58. package/src/components/OnePayWidget.tsx +10 -1
  59. package/src/components/OneSendWidget.tsx +3 -3
  60. package/src/components/OneSwapWidget.tsx +4 -4
  61. package/src/components/OneTransactionButton.tsx +28 -3
  62. package/src/components/OneWalletBalance.tsx +1 -1
  63. package/src/components/ai/OneChainSelector.tsx +63 -336
  64. package/src/components/ai/OneForexCapitalSplit.tsx +112 -0
  65. package/src/components/ai/OneForexConsoleView.tsx +90 -0
  66. package/src/components/ai/OneForexPairSelector.tsx +101 -0
  67. package/src/components/ai/OneForexPoolCard.tsx +105 -0
  68. package/src/components/ai/OneForexTradeHistory.tsx +107 -0
  69. package/src/components/ai/OnePairSelector.tsx +77 -434
  70. package/src/components/ai/console/OneAIQuantConsole.tsx +423 -0
  71. package/src/components/ai/console/OneAgentCard.tsx +383 -0
  72. package/src/components/ai/console/OneAgentConsole.tsx +469 -0
  73. package/src/components/ai/console/OneDecisionTimeline.tsx +433 -0
  74. package/src/components/ai/console/OneMetricsDashboard.tsx +493 -0
  75. package/src/components/ai/console/OnePositionCard.tsx +406 -0
  76. package/src/components/ai/console/OnePositionDetail.tsx +600 -0
  77. package/src/components/ai/console/OneRiskIndicator.tsx +464 -0
  78. package/src/components/ai/console/OneTradingConsole.tsx +660 -0
  79. package/src/components/ai/console/index.ts +17 -0
  80. package/src/components/ai/index.ts +10 -0
  81. package/src/hooks/index.ts +46 -0
  82. package/src/hooks/useAIDecisions.ts +280 -0
  83. package/src/hooks/useAIPositions.ts +349 -0
  84. package/src/hooks/useAIQuantConsole.ts +283 -0
  85. package/src/hooks/useAIRiskStatus.ts +276 -0
  86. package/src/hooks/useAITrading.ts +190 -0
  87. package/src/hooks/useBotSimulation.ts +201 -0
  88. package/src/hooks/useForexTrading.ts +430 -0
  89. package/src/hooks/useTradingConsole.ts +243 -0
  90. package/src/index.ts +123 -5
  91. package/src/providers/OneProvider.tsx +181 -5
  92. package/src/providers/index.ts +22 -8
  93. package/src/react-native.ts +41 -0
  94. package/src/services/forex/BotSimulationEngine.ts +968 -0
  95. package/src/services/forex/ForexPoolDataGenerator.ts +542 -0
  96. package/src/services/forex/ForexSimulationEngine.ts +482 -0
  97. package/src/services/forex/index.ts +21 -0
  98. package/src/services/index.ts +16 -0
  99. package/src/types/aiTrading.ts +151 -0
  100. package/src/types/console.ts +380 -0
  101. package/src/types/forex.ts +282 -0
  102. package/src/types/index.ts +106 -0
  103. package/dist/price-CgqXPnT3.d.ts +0 -13
  104. package/dist/price-ClbLHHjv.d.mts +0 -13
  105. package/dist/supabase-BT0c7q9e.d.mts +0 -82
  106. package/dist/supabase-BT0c7q9e.d.ts +0 -82
@@ -442,3 +442,193 @@ export function useAITrading(): UseAITradingResult {
442
442
  error,
443
443
  };
444
444
  }
445
+
446
+ // ============================================
447
+ // AI Agents Hooks
448
+ // ============================================
449
+
450
+ export interface AIAgent {
451
+ id: string;
452
+ name: string;
453
+ name_zh: string;
454
+ description: string;
455
+ description_zh: string;
456
+ category: string;
457
+ risk_level: number;
458
+ icon: string;
459
+ color: string;
460
+ tiers: Array<{ tier: number; amount: number; label: string; label_zh: string }>;
461
+ supported_cycles: number[];
462
+ default_cycle: number;
463
+ supported_pairs: string[];
464
+ supported_chains: string[];
465
+ is_active: boolean;
466
+ preview?: {
467
+ tier: { tier: number; amount: number; label: string };
468
+ cycle: number;
469
+ dailyLots: number;
470
+ stabilityScore: number;
471
+ roiRange: { min: number; max: number; userMin: number; userMax: number };
472
+ shareRate: number;
473
+ profitEstimate: { monthlyMin: number; monthlyMax: number; cycleMin: number; cycleMax: number };
474
+ };
475
+ }
476
+
477
+ export interface AIAgentParams {
478
+ dailyLots: number;
479
+ effectiveCapital: number;
480
+ stabilityScore: number;
481
+ roiRange: { min: number; max: number; userMin: number; userMax: number };
482
+ shareRate: number;
483
+ profitEstimate: { monthlyMin: number; monthlyMax: number; cycleMin: number; cycleMax: number };
484
+ }
485
+
486
+ export interface UseAIAgentsResult {
487
+ agents: AIAgent[];
488
+ shareRates: Record<number, number>;
489
+ isLoading: boolean;
490
+ error: string | null;
491
+ refresh: () => Promise<void>;
492
+ }
493
+
494
+ /**
495
+ * Hook to fetch all AI agents with their configurations
496
+ */
497
+ export function useAIAgents(includeInactive = false): UseAIAgentsResult {
498
+ const [agents, setAgents] = useState<AIAgent[]>([]);
499
+ const [shareRates, setShareRates] = useState<Record<number, number>>({});
500
+ const [isLoading, setIsLoading] = useState(true);
501
+ const [error, setError] = useState<string | null>(null);
502
+
503
+ const fetchAgents = useCallback(async () => {
504
+ setIsLoading(true);
505
+ setError(null);
506
+ try {
507
+ const result = await getClient().getAgentConfigs({ includeInactive });
508
+ if (result.success && result.data) {
509
+ setAgents(result.data.agents || []);
510
+ setShareRates(result.data.shareRates || {});
511
+ } else {
512
+ setError(result.error?.message || 'Failed to fetch agents');
513
+ }
514
+ } catch (err) {
515
+ setError(err instanceof Error ? err.message : 'Unknown error');
516
+ } finally {
517
+ setIsLoading(false);
518
+ }
519
+ }, [includeInactive]);
520
+
521
+ useEffect(() => {
522
+ fetchAgents();
523
+ }, [fetchAgents]);
524
+
525
+ return { agents, shareRates, isLoading, error, refresh: fetchAgents };
526
+ }
527
+
528
+ export interface UseAIAgentResult {
529
+ agent: AIAgent | null;
530
+ params: AIAgentParams | null;
531
+ isLoading: boolean;
532
+ error: string | null;
533
+ refresh: () => Promise<void>;
534
+ calculateParams: (amount: number, cycleDays: number) => Promise<AIAgentParams | null>;
535
+ }
536
+
537
+ /**
538
+ * Hook to fetch a single AI agent with detailed parameters
539
+ */
540
+ export function useAIAgent(agentId: string | undefined): UseAIAgentResult {
541
+ const [agent, setAgent] = useState<AIAgent | null>(null);
542
+ const [params, setParams] = useState<AIAgentParams | null>(null);
543
+ const [isLoading, setIsLoading] = useState(true);
544
+ const [error, setError] = useState<string | null>(null);
545
+
546
+ const fetchAgent = useCallback(async () => {
547
+ if (!agentId) {
548
+ setIsLoading(false);
549
+ return;
550
+ }
551
+
552
+ setIsLoading(true);
553
+ setError(null);
554
+ try {
555
+ const result = await getClient().getAgentConfigs({ agentId });
556
+ if (result.success && result.data?.agent) {
557
+ setAgent(result.data.agent);
558
+ } else {
559
+ setError(result.error?.message || 'Agent not found');
560
+ }
561
+ } catch (err) {
562
+ setError(err instanceof Error ? err.message : 'Unknown error');
563
+ } finally {
564
+ setIsLoading(false);
565
+ }
566
+ }, [agentId]);
567
+
568
+ useEffect(() => {
569
+ fetchAgent();
570
+ }, [fetchAgent]);
571
+
572
+ const calculateParams = useCallback(async (amount: number, cycleDays: number): Promise<AIAgentParams | null> => {
573
+ if (!agentId) return null;
574
+
575
+ try {
576
+ const result = await getClient().calculateAgentParams({ agentId, amount, cycleDays });
577
+ if (result.success && result.data) {
578
+ setParams(result.data);
579
+ return result.data;
580
+ }
581
+ return null;
582
+ } catch (err) {
583
+ setError(err instanceof Error ? err.message : 'Failed to calculate params');
584
+ return null;
585
+ }
586
+ }, [agentId]);
587
+
588
+ return { agent, params, isLoading, error, refresh: fetchAgent, calculateParams };
589
+ }
590
+
591
+ export interface UseAIAgentSubscriptionResult {
592
+ subscribe: (agentId: string, amount: number, cycleDays: number, txHash?: string) => Promise<ApiResponse<{ order: AIOrder }>>;
593
+ isLoading: boolean;
594
+ error: string | null;
595
+ }
596
+
597
+ /**
598
+ * Hook to subscribe to an AI agent strategy
599
+ */
600
+ export function useAIAgentSubscription(): UseAIAgentSubscriptionResult {
601
+ const [isLoading, setIsLoading] = useState(false);
602
+ const [error, setError] = useState<string | null>(null);
603
+
604
+ const subscribe = useCallback(async (
605
+ agentId: string,
606
+ amount: number,
607
+ cycleDays: number,
608
+ txHash?: string
609
+ ): Promise<ApiResponse<{ order: AIOrder }>> => {
610
+ setIsLoading(true);
611
+ setError(null);
612
+ try {
613
+ // Create order for the agent strategy
614
+ const result = await getClient().createAIOrder({
615
+ strategyId: agentId,
616
+ amount,
617
+ lockPeriodDays: cycleDays,
618
+ txHashDeposit: txHash,
619
+ });
620
+ if (!result.success) {
621
+ setError(result.error?.message || 'Failed to subscribe');
622
+ }
623
+ return result;
624
+ } catch (err) {
625
+ const errorMsg = err instanceof Error ? err.message : 'Subscription failed';
626
+ setError(errorMsg);
627
+ return { success: false, error: { code: 'SUBSCRIPTION_ERROR', message: errorMsg } };
628
+ } finally {
629
+ setIsLoading(false);
630
+ }
631
+ }, []);
632
+
633
+ return { subscribe, isLoading, error };
634
+ }
@@ -0,0 +1,201 @@
1
+ /**
2
+ * ONE SDK - Bot Simulation Hook
3
+ * Provides React hook for subscribing to BotSimulationEngine events
4
+ */
5
+
6
+ import { useState, useEffect, useCallback, useRef, useMemo } from 'react';
7
+ import type { BotLogEntry, BotState, StrategyPersonality } from '../services/forex/BotSimulationEngine';
8
+
9
+ // ── Types ─────────────────────────────────────────────────────────────────────
10
+
11
+ export interface UseBotSimulationOptions {
12
+ maxLogs?: number;
13
+ strategyIds?: string[];
14
+ userPairs?: string[];
15
+ userChains?: string[];
16
+ autoStart?: boolean;
17
+ }
18
+
19
+ export interface UseBotSimulationResult {
20
+ /** All log entries from all strategies */
21
+ logs: BotLogEntry[];
22
+ /** Logs grouped by strategy ID */
23
+ logsByStrategy: Map<string, BotLogEntry[]>;
24
+ /** Current state for each strategy */
25
+ botStates: Map<string, BotState>;
26
+ /** Whether simulation is currently running */
27
+ isRunning: boolean;
28
+ /** Available strategies */
29
+ strategies: StrategyPersonality[];
30
+ /** Start the simulation */
31
+ start: (strategyIds?: string[], userPairs?: string[], userChains?: string[]) => void;
32
+ /** Stop the simulation */
33
+ stop: (strategyIds?: string[]) => void;
34
+ /** Clear all logs */
35
+ clearLogs: () => void;
36
+ /** Emit boot sequence messages */
37
+ emitBootSequence: () => void;
38
+ /** Get state for a specific strategy */
39
+ getBotState: (strategyId: string) => BotState | undefined;
40
+ }
41
+
42
+ // ── Hook Implementation ───────────────────────────────────────────────────────
43
+
44
+ export function useBotSimulation(options?: UseBotSimulationOptions): UseBotSimulationResult {
45
+ const maxLogs = options?.maxLogs ?? 500;
46
+ const [logs, setLogs] = useState<BotLogEntry[]>([]);
47
+ const [isRunning, setIsRunning] = useState(false);
48
+ const [strategies, setStrategies] = useState<StrategyPersonality[]>([]);
49
+ const [botStatesMap, setBotStatesMap] = useState<Map<string, BotState>>(new Map());
50
+ const engineRef = useRef<any>(null);
51
+ const unsubRef = useRef<(() => void) | null>(null);
52
+
53
+ // Lazy load the engine
54
+ const getEngine = useCallback(() => {
55
+ if (!engineRef.current) {
56
+ try {
57
+ const { botSimulationEngine } = require('../services/forex/BotSimulationEngine');
58
+ engineRef.current = botSimulationEngine;
59
+ setStrategies(botSimulationEngine.getStrategies());
60
+ } catch {
61
+ // Engine not available
62
+ }
63
+ }
64
+ return engineRef.current;
65
+ }, []);
66
+
67
+ // Group logs by strategy
68
+ const logsByStrategy = useMemo(() => {
69
+ const grouped = new Map<string, BotLogEntry[]>();
70
+ for (const log of logs) {
71
+ const existing = grouped.get(log.strategyId) || [];
72
+ grouped.set(log.strategyId, [...existing, log]);
73
+ }
74
+ return grouped;
75
+ }, [logs]);
76
+
77
+ // Start simulation
78
+ const start = useCallback((
79
+ strategyIds?: string[],
80
+ userPairs?: string[],
81
+ userChains?: string[]
82
+ ) => {
83
+ const engine = getEngine();
84
+ if (!engine) return;
85
+
86
+ const ids = strategyIds || options?.strategyIds;
87
+ const pairs = userPairs || options?.userPairs;
88
+ const chains = userChains || options?.userChains;
89
+
90
+ if (!engine.isRunning()) {
91
+ engine.start(ids, pairs, chains);
92
+ }
93
+ setIsRunning(true);
94
+ }, [getEngine, options?.strategyIds, options?.userPairs, options?.userChains]);
95
+
96
+ // Stop simulation
97
+ const stop = useCallback((strategyIds?: string[]) => {
98
+ const engine = getEngine();
99
+ if (engine) {
100
+ engine.stop(strategyIds);
101
+ if (!strategyIds) {
102
+ setIsRunning(false);
103
+ }
104
+ }
105
+ }, [getEngine]);
106
+
107
+ // Clear logs
108
+ const clearLogs = useCallback(() => {
109
+ setLogs([]);
110
+ }, []);
111
+
112
+ // Emit boot sequence
113
+ const emitBootSequence = useCallback(() => {
114
+ const engine = getEngine();
115
+ if (engine) {
116
+ engine.emitBootSequence();
117
+ }
118
+ }, [getEngine]);
119
+
120
+ // Get state for specific strategy
121
+ const getBotState = useCallback((strategyId: string): BotState | undefined => {
122
+ return botStatesMap.get(strategyId);
123
+ }, [botStatesMap]);
124
+
125
+ // Subscribe to engine events
126
+ useEffect(() => {
127
+ const engine = getEngine();
128
+ if (!engine) return;
129
+
130
+ // Check if already running
131
+ setIsRunning(engine.isRunning());
132
+
133
+ // Subscribe to log events
134
+ unsubRef.current = engine.onLog((entry: BotLogEntry) => {
135
+ setLogs(prev => {
136
+ const next = [...prev, entry];
137
+ return next.length > maxLogs ? next.slice(-maxLogs) : next;
138
+ });
139
+
140
+ // Update bot states
141
+ const state = engine.getBotState(entry.strategyId);
142
+ if (state) {
143
+ setBotStatesMap(prev => {
144
+ const next = new Map(prev);
145
+ next.set(entry.strategyId, state);
146
+ return next;
147
+ });
148
+ }
149
+ });
150
+
151
+ return () => {
152
+ if (unsubRef.current) {
153
+ unsubRef.current();
154
+ unsubRef.current = null;
155
+ }
156
+ };
157
+ }, [getEngine, maxLogs]);
158
+
159
+ // Auto-start if configured
160
+ useEffect(() => {
161
+ if (options?.autoStart) {
162
+ const engine = getEngine();
163
+ if (engine && !engine.isRunning()) {
164
+ emitBootSequence();
165
+ setTimeout(() => {
166
+ start();
167
+ }, 5500); // After boot sequence completes
168
+ }
169
+ }
170
+ }, [options?.autoStart, getEngine, emitBootSequence, start]);
171
+
172
+ // Periodically update bot states
173
+ useEffect(() => {
174
+ if (!isRunning) return;
175
+
176
+ const interval = setInterval(() => {
177
+ const engine = getEngine();
178
+ if (engine) {
179
+ const states = engine.getAllBotStates();
180
+ if (states.size > 0) {
181
+ setBotStatesMap(new Map(states));
182
+ }
183
+ }
184
+ }, 1000);
185
+
186
+ return () => clearInterval(interval);
187
+ }, [isRunning, getEngine]);
188
+
189
+ return {
190
+ logs,
191
+ logsByStrategy,
192
+ botStates: botStatesMap,
193
+ isRunning,
194
+ strategies,
195
+ start,
196
+ stop,
197
+ clearLogs,
198
+ emitBootSequence,
199
+ getBotState,
200
+ };
201
+ }