// Test comment to check persistence namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\User; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Auth; use Carbon\Carbon; class ArbitrageBotController extends Controller { public $theme; public function __construct() { $this->theme = template(); } /** * Show the Bot Store / Subscription Page. */ public function index() { $user = Auth::user(); // Check current subscription $subscription = \Illuminate\Support\Facades\DB::table('bot_subscriptions') ->where('user_id', $user->id) ->where('is_active', true) ->first(); // Bot Price (Later fetching from settings) $botPrice = 5.00; // Re-initialize theme here to be safe $theme = template(); return view($theme.'arbitrage.bot_store', compact('user', 'subscription', 'botPrice', 'theme')); } /** * Process the Bot Purchase. */ public function purchase(Request $request) { $user = Auth::user(); if (!$user) { return response()->json(['status' => 'error', 'message' => 'Login Required'], 401); } $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); $service = new \App\Services\ArbitrageService(); $result = $service->activateBotForPosition($user, $request->position_id); if ($result['status'] === 'success') { return response()->json(['status' => 'success', 'message' => $result['message']]); } else { return response()->json(['status' => 'error', 'message' => $result['message']], 400); } } /** * Show the Manual Trading Page. */ public function manualTrade() { $user = Auth::user(); $theme = template(); // Fetch Real-Time Data (Price/Hash) for the View $service = new \App\Services\ArbitrageService(); $marketData = $service->getMarketData(); $botPrice = $service->getBotPrice(); return view($theme.'arbitrage.manual_trade', compact('user', 'theme', 'marketData', 'botPrice')); } /** * Execute Manual Arbitrage for a specific position. */ public function execute(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); // Validar position_id $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); try { $service = new \App\Services\ArbitrageService(); // Execute para posição específica (isBot = false) $result = $service->executeOperation($user, (int)$request->position_id, false); return response()->json($result); } catch (\Throwable $e) { return response()->json(['error' => 'Critical Error: ' . $e->getMessage() . ' on line ' . $e->getLine()], 500); } } /** * Criar nova posição de arbitragem */ public function createPosition(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); $request->validate([ 'amount' => 'required|numeric|min:10', ]); try { $service = new \App\Services\ArbitrageService(); $result = $service->createPosition($user, (float)$request->amount); return response()->json($result); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 400); } } /** * Buscar dados das posições ativas do usuário */ public function getPositionData() { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); try { $service = new \App\Services\ArbitrageService(); $positions = $service->getUserActivePositions($user); if ($positions->isEmpty()) { return response()->json(['has_position' => false]); } $positionsData = []; foreach ($positions as $position) { // Determine Last Operation Time $lastOp = DB::table('arbitrage_ops')->where('position_id', $position->id)->latest('created_at')->first(); $lastTime = $lastOp ? \Carbon\Carbon::parse($lastOp->created_at) : \Carbon\Carbon::parse($position->created_at)->subMinutes(5); // Ready if new // Cooldown: 5 minutes per position $nextExec = $lastTime->addMinutes(5); $now = \Carbon\Carbon::now(); $secondsRemaining = $now->lt($nextExec) ? $now->diffInSeconds($nextExec) : 0; $positionsData[] = [ 'id' => $position->id, 'amount_locked' => number_format($position->amount_locked, 2), 'started_at' => \Carbon\Carbon::parse($position->started_at)->format('d/m/Y'), 'expires_at' => \Carbon\Carbon::parse($position->expires_at)->format('d/m/Y'), 'days_remaining' => \Carbon\Carbon::now()->diffInDays($position->expires_at), 'total_operations' => $position->total_operations, 'total_profit' => number_format($position->total_profit_earned, 2), 'has_active_bot' => (bool)($position->has_active_bot ?? 0), 'next_execution_timestamp' => $nextExec->timestamp * 1000, // JS millis 'seconds_to_wait' => $secondsRemaining ]; } return response()->json([ 'has_position' => true, 'positions' => $positionsData, 'bot_price' => $service->getBotPrice(), 'total_locked' => number_format($positions->sum('amount_locked'), 2), 'total_locked' => number_format($positions->sum('amount_locked'), 2), 'total_profit' => number_format($positions->sum('total_profit_earned'), 2) ]); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 400); } } /** * Get operations history for a specific position */ public function getPositionHistory(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'Unauthorized'], 401); $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); // Verify position belongs to user $position = DB::table('arbitrage_positions') ->where('id', $request->position_id) ->where('user_id', $user->id) ->first(); if (!$position) { return response()->json(['error' => 'Position not found'], 404); } $service = new \App\Services\ArbitrageService(); $operations = $service->getPositionOperations($request->position_id, 20); $formattedOps = []; foreach ($operations as $op) { $formattedOps[] = [ 'id' => $op->id, 'profit' => number_format($op->net_profit, 2), 'fee' => number_format($op->network_fee, 2), 'hash' => $op->real_blockchain_hash, 'time' => \Carbon\Carbon::parse($op->created_at)->format('d/m/Y H:i'), 'executed_by' => $op->executed_by ]; } return response()->json([ 'success' => true, 'position' => [ 'id' => $position->id, 'amount' => number_format($position->amount_locked, 2), 'total_ops' => $position->total_operations, 'total_profit' => number_format($position->total_profit_earned, 2) ], 'operations' => $formattedOps ]); } } // Test comment to check persistence namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\User; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Auth; use Carbon\Carbon; class ArbitrageBotController extends Controller { public $theme; public function __construct() { $this->theme = template(); } /** * Show the Bot Store / Subscription Page. */ public function index() { $user = Auth::user(); // Check current subscription $subscription = \Illuminate\Support\Facades\DB::table('bot_subscriptions') ->where('user_id', $user->id) ->where('is_active', true) ->first(); // Bot Price (Later fetching from settings) $botPrice = 5.00; // Re-initialize theme here to be safe $theme = template(); return view($theme.'arbitrage.bot_store', compact('user', 'subscription', 'botPrice', 'theme')); } /** * Process the Bot Purchase. */ public function purchase(Request $request) { $user = Auth::user(); if (!$user) { return response()->json(['status' => 'error', 'message' => 'Login Required'], 401); } $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); $service = new \App\Services\ArbitrageService(); $result = $service->activateBotForPosition($user, $request->position_id); if ($result['status'] === 'success') { return response()->json(['status' => 'success', 'message' => $result['message']]); } else { return response()->json(['status' => 'error', 'message' => $result['message']], 400); } } /** * Show the Manual Trading Page. */ public function manualTrade() { $user = Auth::user(); $theme = template(); // Fetch Real-Time Data (Price/Hash) for the View $service = new \App\Services\ArbitrageService(); $marketData = $service->getMarketData(); $botPrice = $service->getBotPrice(); return view($theme.'arbitrage.manual_trade', compact('user', 'theme', 'marketData', 'botPrice')); } /** * Execute Manual Arbitrage for a specific position. */ public function execute(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); // Validar position_id $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); try { $service = new \App\Services\ArbitrageService(); // Execute para posição específica (isBot = false) $result = $service->executeOperation($user, (int)$request->position_id, false); return response()->json($result); } catch (\Throwable $e) { return response()->json(['error' => 'Critical Error: ' . $e->getMessage() . ' on line ' . $e->getLine()], 500); } } /** * Criar nova posição de arbitragem */ public function createPosition(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); $request->validate([ 'amount' => 'required|numeric|min:10', ]); try { $service = new \App\Services\ArbitrageService(); $result = $service->createPosition($user, (float)$request->amount); return response()->json($result); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 400); } } /** * Buscar dados das posições ativas do usuário */ public function getPositionData() { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); try { $service = new \App\Services\ArbitrageService(); $positions = $service->getUserActivePositions($user); if ($positions->isEmpty()) { return response()->json(['has_position' => false]); } $positionsData = []; foreach ($positions as $position) { // Determine Last Operation Time $lastOp = DB::table('arbitrage_ops')->where('position_id', $position->id)->latest('created_at')->first(); $lastTime = $lastOp ? \Carbon\Carbon::parse($lastOp->created_at) : \Carbon\Carbon::parse($position->created_at)->subMinutes(5); // Ready if new // Cooldown: 5 minutes per position $nextExec = $lastTime->addMinutes(5); $now = \Carbon\Carbon::now(); $secondsRemaining = $now->lt($nextExec) ? $now->diffInSeconds($nextExec) : 0; $positionsData[] = [ 'id' => $position->id, 'amount_locked' => number_format($position->amount_locked, 2), 'started_at' => \Carbon\Carbon::parse($position->started_at)->format('d/m/Y'), 'expires_at' => \Carbon\Carbon::parse($position->expires_at)->format('d/m/Y'), 'days_remaining' => \Carbon\Carbon::now()->diffInDays($position->expires_at), 'total_operations' => $position->total_operations, 'total_profit' => number_format($position->total_profit_earned, 2), 'has_active_bot' => (bool)($position->has_active_bot ?? 0), 'next_execution_timestamp' => $nextExec->timestamp * 1000, // JS millis 'seconds_to_wait' => $secondsRemaining ]; } return response()->json([ 'has_position' => true, 'positions' => $positionsData, 'bot_price' => $service->getBotPrice(), 'total_locked' => number_format($positions->sum('amount_locked'), 2), 'total_locked' => number_format($positions->sum('amount_locked'), 2), 'total_profit' => number_format($positions->sum('total_profit_earned'), 2) ]); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 400); } } /** * Get operations history for a specific position */ public function getPositionHistory(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'Unauthorized'], 401); $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); // Verify position belongs to user $position = DB::table('arbitrage_positions') ->where('id', $request->position_id) ->where('user_id', $user->id) ->first(); if (!$position) { return response()->json(['error' => 'Position not found'], 404); } $service = new \App\Services\ArbitrageService(); $operations = $service->getPositionOperations($request->position_id, 20); $formattedOps = []; foreach ($operations as $op) { $formattedOps[] = [ 'id' => $op->id, 'profit' => number_format($op->net_profit, 2), 'fee' => number_format($op->network_fee, 2), 'hash' => $op->real_blockchain_hash, 'time' => \Carbon\Carbon::parse($op->created_at)->format('d/m/Y H:i'), 'executed_by' => $op->executed_by ]; } return response()->json([ 'success' => true, 'position' => [ 'id' => $position->id, 'amount' => number_format($position->amount_locked, 2), 'total_ops' => $position->total_operations, 'total_profit' => number_format($position->total_profit_earned, 2) ], 'operations' => $formattedOps ]); } } // Test comment to check persistence namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\User; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Auth; use Carbon\Carbon; class ArbitrageBotController extends Controller { public $theme; public function __construct() { $this->theme = template(); } /** * Show the Bot Store / Subscription Page. */ public function index() { $user = Auth::user(); // Check current subscription $subscription = \Illuminate\Support\Facades\DB::table('bot_subscriptions') ->where('user_id', $user->id) ->where('is_active', true) ->first(); // Bot Price (Later fetching from settings) $botPrice = 5.00; // Re-initialize theme here to be safe $theme = template(); return view($theme.'arbitrage.bot_store', compact('user', 'subscription', 'botPrice', 'theme')); } /** * Process the Bot Purchase. */ public function purchase(Request $request) { $user = Auth::user(); if (!$user) { return response()->json(['status' => 'error', 'message' => 'Login Required'], 401); } $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); $service = new \App\Services\ArbitrageService(); $result = $service->activateBotForPosition($user, $request->position_id); if ($result['status'] === 'success') { return response()->json(['status' => 'success', 'message' => $result['message']]); } else { return response()->json(['status' => 'error', 'message' => $result['message']], 400); } } /** * Show the Manual Trading Page. */ public function manualTrade() { $user = Auth::user(); $theme = template(); // Fetch Real-Time Data (Price/Hash) for the View $service = new \App\Services\ArbitrageService(); $marketData = $service->getMarketData(); $botPrice = $service->getBotPrice(); return view($theme.'arbitrage.manual_trade', compact('user', 'theme', 'marketData', 'botPrice')); } /** * Execute Manual Arbitrage for a specific position. */ public function execute(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); // Validar position_id $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); try { $service = new \App\Services\ArbitrageService(); // Execute para posição específica (isBot = false) $result = $service->executeOperation($user, (int)$request->position_id, false); return response()->json($result); } catch (\Throwable $e) { return response()->json(['error' => 'Critical Error: ' . $e->getMessage() . ' on line ' . $e->getLine()], 500); } } /** * Criar nova posição de arbitragem */ public function createPosition(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); $request->validate([ 'amount' => 'required|numeric|min:10', ]); try { $service = new \App\Services\ArbitrageService(); $result = $service->createPosition($user, (float)$request->amount); return response()->json($result); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 400); } } /** * Buscar dados das posições ativas do usuário */ public function getPositionData() { $user = Auth::user(); if (!$user) return response()->json(['error' => 'User not found'], 401); try { $service = new \App\Services\ArbitrageService(); $positions = $service->getUserActivePositions($user); if ($positions->isEmpty()) { return response()->json(['has_position' => false]); } $positionsData = []; foreach ($positions as $position) { // Determine Last Operation Time $lastOp = DB::table('arbitrage_ops')->where('position_id', $position->id)->latest('created_at')->first(); $lastTime = $lastOp ? \Carbon\Carbon::parse($lastOp->created_at) : \Carbon\Carbon::parse($position->created_at)->subMinutes(5); // Ready if new // Cooldown: 5 minutes per position $nextExec = $lastTime->addMinutes(5); $now = \Carbon\Carbon::now(); $secondsRemaining = $now->lt($nextExec) ? $now->diffInSeconds($nextExec) : 0; $positionsData[] = [ 'id' => $position->id, 'amount_locked' => number_format($position->amount_locked, 2), 'started_at' => \Carbon\Carbon::parse($position->started_at)->format('d/m/Y'), 'expires_at' => \Carbon\Carbon::parse($position->expires_at)->format('d/m/Y'), 'days_remaining' => \Carbon\Carbon::now()->diffInDays($position->expires_at), 'total_operations' => $position->total_operations, 'total_profit' => number_format($position->total_profit_earned, 2), 'has_active_bot' => (bool)($position->has_active_bot ?? 0), 'next_execution_timestamp' => $nextExec->timestamp * 1000, // JS millis 'seconds_to_wait' => $secondsRemaining ]; } return response()->json([ 'has_position' => true, 'positions' => $positionsData, 'bot_price' => $service->getBotPrice(), 'total_locked' => number_format($positions->sum('amount_locked'), 2), 'total_locked' => number_format($positions->sum('amount_locked'), 2), 'total_profit' => number_format($positions->sum('total_profit_earned'), 2) ]); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 400); } } /** * Get operations history for a specific position */ public function getPositionHistory(Request $request) { $user = Auth::user(); if (!$user) return response()->json(['error' => 'Unauthorized'], 401); $request->validate([ 'position_id' => 'required|integer|exists:arbitrage_positions,id' ]); // Verify position belongs to user $position = DB::table('arbitrage_positions') ->where('id', $request->position_id) ->where('user_id', $user->id) ->first(); if (!$position) { return response()->json(['error' => 'Position not found'], 404); } $service = new \App\Services\ArbitrageService(); $operations = $service->getPositionOperations($request->position_id, 20); $formattedOps = []; foreach ($operations as $op) { $formattedOps[] = [ 'id' => $op->id, 'profit' => number_format($op->net_profit, 2), 'fee' => number_format($op->network_fee, 2), 'hash' => $op->real_blockchain_hash, 'time' => \Carbon\Carbon::parse($op->created_at)->format('d/m/Y H:i'), 'executed_by' => $op->executed_by ]; } return response()->json([ 'success' => true, 'position' => [ 'id' => $position->id, 'amount' => number_format($position->amount_locked, 2), 'total_ops' => $position->total_operations, 'total_profit' => number_format($position->total_profit_earned, 2) ], 'operations' => $formattedOps ]); } } Redirecting to https://solarioncoin.fun/login Redirecting to https://solarioncoin.fun/login.