From fb570b9f7e97b37c87b57f6ed1430561e7507378 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Wed, 19 Nov 2025 23:25:57 +0700 Subject: [PATCH] Fix key conditions --- .../StartCopyTradingCommandHandler.cs | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/Managing.Application/ManageBot/StartCopyTradingCommandHandler.cs b/src/Managing.Application/ManageBot/StartCopyTradingCommandHandler.cs index 2f8446e3..79ca88cf 100644 --- a/src/Managing.Application/ManageBot/StartCopyTradingCommandHandler.cs +++ b/src/Managing.Application/ManageBot/StartCopyTradingCommandHandler.cs @@ -21,7 +21,8 @@ namespace Managing.Application.ManageBot private readonly IEvmManager _evmManager; public StartCopyTradingCommandHandler( - IAccountService accountService, IGrainFactory grainFactory, IBotService botService, IKaigenService kaigenService, IEvmManager evmManager) + IAccountService accountService, IGrainFactory grainFactory, IBotService botService, + IKaigenService kaigenService, IEvmManager evmManager) { _accountService = accountService; _grainFactory = grainFactory; @@ -50,11 +51,13 @@ namespace Managing.Application.ManageBot if (string.Equals(request.MasterBotIdentifier.ToString(), "Kudai", StringComparison.OrdinalIgnoreCase)) { await ValidateKudaiStakingRequirements(request.User); - }else { + } + else + { // Verify the user owns the keys of the master strategy var ownedKeys = await _kaigenService.GetOwnedKeysAsync(request.User); var hasMasterStrategyKey = ownedKeys.Items.Any(key => - string.Equals(key.AgentName, request.MasterBotIdentifier.ToString(), StringComparison.OrdinalIgnoreCase) && + string.Equals(key.AgentName, masterBot.User.AgentName, StringComparison.OrdinalIgnoreCase) && key.Owned >= 1); if (!hasMasterStrategyKey) @@ -69,11 +72,13 @@ namespace Managing.Application.ManageBot var masterConfig = await _botService.GetBotConfig(request.MasterBotIdentifier); if (masterConfig == null) { - throw new InvalidOperationException($"Could not retrieve configuration for master bot {request.MasterBotIdentifier}"); + throw new InvalidOperationException( + $"Could not retrieve configuration for master bot {request.MasterBotIdentifier}"); } // Check if user already has a bot on this ticker (same as master bot) - var hasExistingBotOnTicker = await _botService.HasUserBotOnTickerAsync(request.User.Id, masterConfig.Ticker); + var hasExistingBotOnTicker = + await _botService.HasUserBotOnTickerAsync(request.User.Id, masterConfig.Ticker); if (hasExistingBotOnTicker) { throw new InvalidOperationException( @@ -88,6 +93,7 @@ namespace Managing.Application.ManageBot { throw new InvalidOperationException($"User '{request.User.Name}' has no accounts configured."); } + Account account = firstAccount; // Check balances for EVM/GMX V2 accounts before starting @@ -164,7 +170,8 @@ namespace Managing.Application.ManageBot // Start the copy trading bot immediately await botGrain.StartAsync(); - return $"Copy trading bot started successfully, following master bot '{masterConfig.Name}' with {request.BotTradingBalance:F2} USDC balance"; + return + $"Copy trading bot started successfully, following master bot '{masterConfig.Name}' with {request.BotTradingBalance:F2} USDC balance"; } catch (Exception ex) { @@ -172,20 +179,20 @@ namespace Managing.Application.ManageBot } } - private async Task ValidateKudaiStakingRequirements(User user) - { - // Use the user's wallet address directly - if (string.IsNullOrEmpty(user.OwnerWalletAddress)) + private async Task ValidateKudaiStakingRequirements(User user) { - throw new InvalidOperationException( - "To copy trade the Kudai strategy, you must have a wallet address configured in your profile."); - } + // Use the user's wallet address directly + if (string.IsNullOrEmpty(user.OwnerWalletAddress)) + { + throw new InvalidOperationException( + "To copy trade the Kudai strategy, you must have a wallet address configured in your profile."); + } - // Check KUDAI staked balance - var kudaiStakedBalance = await _evmManager.GetKudaiStakedBalance(user.OwnerWalletAddress); + // Check KUDAI staked balance + var kudaiStakedBalance = await _evmManager.GetKudaiStakedBalance(user.OwnerWalletAddress); - // Check GBC staked NFT count - var gbcStakedCount = await _evmManager.GetGbcStakedCount(user.OwnerWalletAddress); + // Check GBC staked NFT count + var gbcStakedCount = await _evmManager.GetGbcStakedCount(user.OwnerWalletAddress); // Requirements: 100 million KUDAI OR 10 GBC NFTs const decimal requiredKudaiAmount = 100_000_000m; // 100 million