Fix key conditions

This commit is contained in:
2025-11-19 23:25:57 +07:00
parent b7796ede0c
commit fb570b9f7e

View File

@@ -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)
{